Skip to content

OpenAIChatClientFactory

Namespace AgentPrism · Assembly AgentPrism.OpenAI.dll

Builds an OpenAI.OpenAIClient from options and produces AI.IChatClient instances from model bindings.

public sealed class OpenAIChatClientFactory

objectOpenAIChatClientFactory

object.GetType(), object.ToString(), object.Equals(object?), object.Equals(object?, object?), object.ReferenceEquals(object?, object?), object.GetHashCode()

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.

OpenAIChatClientFactory(OpenAIProviderOptions, ILoggerFactory?)

Section titled “ OpenAIChatClientFactory(OpenAIProviderOptions, ILoggerFactory?)”

Initializes a new factory from options.

public OpenAIChatClientFactory(OpenAIProviderOptions options, ILoggerFactory? loggerFactory = null)

options OpenAIProviderOptions

Provider options.

loggerFactory ILoggerFactory?

Logger factory handed to the produced clients.

ArgumentNullException

options is null.

AgentPrismException

OpenAIProviderOptions.ApiKey is empty.

CreateChatClient(ModelBinding, OpenAIApiSurface)

Section titled “ CreateChatClient(ModelBinding, OpenAIApiSurface)”

Creates a chat client for the given binding.

public IChatClient CreateChatClient(ModelBinding binding, OpenAIApiSurface apiSurface)

binding ModelBinding

The model binding.

apiSurface OpenAIApiSurface

The OpenAI API surface to use.

IChatClient

A chat client that the pipeline wraps.

ArgumentNullException

binding is null.

AgentPrismException

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)

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.

OpenAIClient

The client that was built.

ArgumentNullException

options is null.

AgentPrismException

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)

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.

OpenAIChatClientFactory

The new factory.

Setups that manage authentication themselves (for example an identity provider that refreshes tokens) use this factory method.

ArgumentNullException

client is null.