Skip to content

AnthropicChatClientFactory

Namespace AgentPrism · Assembly AgentPrism.Anthropic.dll

Builds an Anthropic.AnthropicClient from settings and produces AI.IChatClient instances from model bindings.

public sealed class AnthropicChatClientFactory

objectAnthropicChatClientFactory

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, usage resolution) is built inside ModelProviderRegistry.CreateChatClient. When the loop was built here, none of the layers the registry wrapped around it could see the tool-call turns.

Anthropic.AnthropicClient is built once and shared; it manages its own HTTP connection pool. Building a new client per call would fragment the pool.

The Anthropic Messages API treats max_tokens as required. When ModelBinding.MaxOutputTokens is left empty, AnthropicProviderOptions.DefaultMaxOutputTokens is used instead.

AnthropicChatClientFactory(AnthropicProviderOptions, ILoggerFactory?)

Section titled “ AnthropicChatClientFactory(AnthropicProviderOptions, ILoggerFactory?)”

Builds a new factory from settings.

public AnthropicChatClientFactory(AnthropicProviderOptions options, ILoggerFactory? loggerFactory = null)

options AnthropicProviderOptions

Provider settings.

loggerFactory ILoggerFactory?

Logger factory passed to produced clients.

ArgumentNullException

options is null.

AgentPrismException

AnthropicProviderOptions.ApiKey is empty.

Produces a chat client for the given binding.

public IChatClient CreateChatClient(ModelBinding binding)

binding ModelBinding

The model binding.

IChatClient

A chat client that has passed through the pipeline.

ArgumentNullException

binding is null.

AgentPrismException

The model name cannot be resolved, or ModelBinding.ProviderSettings contains an unrecognized key.

CreateClient(AnthropicProviderOptions, EgressSocketGuard?)

Section titled “ CreateClient(AnthropicProviderOptions, EgressSocketGuard?)”

Builds an Anthropic client from settings.

public static AnthropicClient CreateClient(AnthropicProviderOptions options, EgressSocketGuard? egressGuard = null)

options AnthropicProviderOptions

Provider settings.

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.

AnthropicClient

The constructed client.

ArgumentNullException

options is null.

AgentPrismException

AnthropicProviderOptions.ApiKey is empty.

FromClient(IAnthropicClient, string?, int, ILoggerFactory?)

Section titled “ FromClient(IAnthropicClient, string?, int, ILoggerFactory?)”

Builds a new factory from an already-constructed client.

public static AnthropicChatClientFactory FromClient(IAnthropicClient client, string? defaultModel = null, int defaultMaxOutputTokens = 4096, ILoggerFactory? loggerFactory = null)

client IAnthropicClient

The Anthropic client to use.

defaultModel string?

The model to use when no model name is given.

defaultMaxOutputTokens int

The upper bound used when ModelBinding.MaxOutputTokens is not given.

loggerFactory ILoggerFactory?

Logger factory passed to produced clients.

AnthropicChatClientFactory

The new factory.

Setups that manage their own authentication (for example Bedrock/Vertex identity, or a provider that refreshes tokens) use this factory method.

ArgumentNullException

client is null.

ArgumentOutOfRangeException

defaultMaxOutputTokens is not positive.