Skip to content

ProviderCredentialClientCache<TFactory\>

Namespace AgentPrism · Assembly AgentPrism.Core.dll

Builds and caches a provider-specific client factory keyed by a resolved ModelProviderCredential (BYOK).

public sealed class ProviderCredentialClientCache<TFactory> where TFactory : class

TFactory

The provider-specific chat client factory type.

objectProviderCredentialClientCache<TFactory>

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

Every provider package’s SDK client is built once and shared (measured: OpenAIClient, AnthropicClient, the Google GenAI Client, and AzureOpenAIClient are all constructed once in their factory and manage their own HTTP connection pool). A tenant credential cannot reuse that shared instance — it carries a different key — so a second client is built for it. This cache exists so that is done once per distinct credential, not once per call: the same pattern OpenAINamedChatClientFactoryCache already uses for named OpenAI-compatible providers, generalized so all four provider packages can share it (every provider package already references AgentPrism.Core).

The cache key is the credential’s own value (API key + endpoint), not a tenant id: two tenants that happen to share the same credential get the same cached client, which is correct — the credential, not the tenant, is the identity boundary here.

Entries are never evicted. The number of distinct credentials is bounded by the number of tenant provider bindings an operator manages (a small, admin-controlled set), not by request volume, so unbounded growth is not a practical concern — the same trade-off OpenAINamedChatClientFactoryCache already makes.

public ProviderCredentialClientCache()

GetOrAdd(ModelProviderCredential, Func<ModelProviderCredential, TFactory>)

Section titled “ GetOrAdd(ModelProviderCredential, Func<ModelProviderCredential, TFactory>)”

Returns the factory for the given credential, building and caching it when absent.

public TFactory GetOrAdd(ModelProviderCredential credential, Func<ModelProviderCredential, TFactory> build)

credential ModelProviderCredential

The resolved credential.

build Func<ModelProviderCredential, TFactory>

Builds a factory from the credential when not already cached.

TFactory

The cached factory.

ArgumentNullException

A parameter is null.