OpenAIChatClientFactory
AgentPrism.OpenAI.dllBuilds an OpenAI.OpenAIClient from options and produces
AI.IChatClient instances from model bindings.
public sealed class OpenAIChatClientFactoryInheritance
Section titled “Inheritance”object ← OpenAIChatClientFactory
Inherited Members
Section titled “Inherited Members”object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()
Remarks
Section titled “Remarks”The factory returns a raw client. The shared pipeline
(UseFunctionInvocation, UseOpenTelemetry, the content guard,
the circuit breaker and attachment resolution) is built inside
ModelProviderRegistry.CreateChatClient — it.
when the loop was built here, no decorator wrapped by the recorder could observe
the tool call turns.
The OpenAI.OpenAIClient is built once and shared; it manages the HTTP
connection pool itself. Building a new client per chat client fragments that pool.
Constructors
Section titled “Constructors”OpenAIChatClientFactory(OpenAIProviderOptions, ILoggerFactory?)
Section titled “ OpenAIChatClientFactory(OpenAIProviderOptions, ILoggerFactory?)”Initializes a new factory from options.
public OpenAIChatClientFactory(OpenAIProviderOptions options, ILoggerFactory? loggerFactory = null)Parameters
Section titled “Parameters”options OpenAIProviderOptions
Provider options.
loggerFactory ILoggerFactory?
Logger factory handed to the produced clients.
Exceptions
Section titled “Exceptions”options is null.
OpenAIProviderOptions.ApiKey is empty.
Methods
Section titled “Methods”CreateChatClient(ModelBinding, OpenAIApiSurface)
Section titled “ CreateChatClient(ModelBinding, OpenAIApiSurface)”Creates a chat client for the given binding.
public IChatClient CreateChatClient(ModelBinding binding, OpenAIApiSurface apiSurface)Parameters
Section titled “Parameters”binding ModelBinding
The model binding.
apiSurface OpenAIApiSurface
The OpenAI API surface to use.
Returns
Section titled “Returns”IChatClient
A chat client that the pipeline wraps.
Exceptions
Section titled “Exceptions”binding is null.
The model name cannot be resolved.
CreateClient(OpenAIProviderOptions, EgressSocketGuard?)
Section titled “ CreateClient(OpenAIProviderOptions, EgressSocketGuard?)”Builds an OpenAI client from options.
public static OpenAIClient CreateClient(OpenAIProviderOptions options, EgressSocketGuard? egressGuard = null)Parameters
Section titled “Parameters”options OpenAIProviderOptions
Provider options.
egressGuard EgressSocketGuard?
When given, every connection this client opens passes through the outbound network guard. Supplied only for a tenant-supplied endpoint override; a setup-time endpoint is the operator’s own decision and is written in code.
Returns
Section titled “Returns”OpenAIClient
The client that was built.
Exceptions
Section titled “Exceptions”options is null.
OpenAIProviderOptions.ApiKey is empty.
FromClient(OpenAIClient, string?, ILoggerFactory?)
Section titled “ FromClient(OpenAIClient, string?, ILoggerFactory?)”Initializes a new factory from an existing client.
public static OpenAIChatClientFactory FromClient(OpenAIClient client, string? defaultModel = null, ILoggerFactory? loggerFactory = null)Parameters
Section titled “Parameters”client OpenAIClient
The OpenAI client to use.
defaultModel string?
The model to use when no model name is given.
loggerFactory ILoggerFactory?
Logger factory handed to the produced clients.
Returns
Section titled “Returns”The new factory.
Remarks
Section titled “Remarks”Setups that manage authentication themselves (for example an identity provider that refreshes tokens) use this factory method.
Exceptions
Section titled “Exceptions”client is null.