OpenAIModelProvider
AgentPrism.OpenAI.dllThe IModelProvider implementation for OpenAI.
public sealed class OpenAIModelProvider : IModelProvider, IModelProviderHealthCheck, IModelProviderConfigurationDiagnosticsInheritance
Section titled “Inheritance”Implements
Section titled “Implements”IModelProvider, IModelProviderHealthCheck, IModelProviderConfigurationDiagnostics
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”UseOpenAI registers two instances of this type:
OpenAIProviderNames.ChatCompletions and
OpenAIProviderNames.Responses. Both share the same
OpenAIChatClientFactory instance, and therefore the same HTTP
connection pool; only their OpenAIModelProvider.ApiSurface values differ.
The provider does not reject a model name that is absent from the catalog. When OpenAI publishes a new model, no new AgentPrism release is needed; if the catalog is not empty, only an informational log entry is written. Because AgentPrism carries no built-in model list, an empty catalog is normal; in that case nothing is logged.
Constructors
Section titled “Constructors”OpenAIModelProvider(string, OpenAIApiSurface, OpenAIChatClientFactory, IReadOnlyList<ModelDescriptor>, ILogger<OpenAIModelProvider>?, OpenAIProviderOptions?, string?, EgressSocketGuard?)
Section titled “ OpenAIModelProvider(string, OpenAIApiSurface, OpenAIChatClientFactory, IReadOnlyList<ModelDescriptor>, ILogger<OpenAIModelProvider>?, OpenAIProviderOptions?, string?, EgressSocketGuard?)”Initializes a new provider.
public OpenAIModelProvider(string name, OpenAIApiSurface apiSurface, OpenAIChatClientFactory chatClientFactory, IReadOnlyList<ModelDescriptor> models, ILogger<OpenAIModelProvider>? logger = null, OpenAIProviderOptions? healthCheckOptions = null, string? configurationSectionKey = "AgentPrism:Providers:OpenAI", EgressSocketGuard? egressGuard = null)Parameters
Section titled “Parameters”name string
The provider name. The ModelBinding.Provider of agent definitions matches this value.
apiSurface OpenAIApiSurface
The OpenAI API surface to use.
chatClientFactory OpenAIChatClientFactory
The chat client factory.
models IReadOnlyList<ModelDescriptor>
The models this provider offers.
logger ILogger<OpenAIModelProvider>?
The logger.
healthCheckOptions OpenAIProviderOptions?
When given, OpenAIModelProvider.CheckHealthAsync calls the GET {endpoint}/models
endpoint with the address and key from these options. When null,
the health status is always ModelProviderHealthStatus.Unknown.
configurationSectionKey string?
The fixed configuration section that OpenAIModelProvider.GetConfigurationDiagnostic
reports. The default is OpenAIProviderOptions.SectionName — it is
meant for UseOpenAI. UseOpenAICompatible passes
null because it takes the key freely in code (there is no fixed
section path); in that case no ConfigurationDiagnostic is reported.
egressGuard EgressSocketGuard?
The outbound network guard. Attached only to a client built from a tenant-supplied endpoint override; when null, such an override is not guarded.
Exceptions
Section titled “Exceptions”A required dependency is null.
name is empty.
Properties
Section titled “Properties”ApiSurface
Section titled “ ApiSurface”Gets the OpenAI API surface this provider uses.
public OpenAIApiSurface ApiSurface { get; }Property Value
Section titled “Property Value”Models
Section titled “ Models”The models this provider offers.
public IReadOnlyList<ModelDescriptor> Models { get; }Property Value
Section titled “Property Value”IReadOnlyList<ModelDescriptor>
The provider name. ModelBinding.Provider matches this value. Comparison is case-insensitive.
public string Name { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”CheckHealthAsync(CancellationToken)
Section titled “ CheckHealthAsync(CancellationToken)”Checks the provider’s reachability.
public ValueTask<ModelProviderHealth> CheckHealthAsync(CancellationToken cancellationToken = default)Parameters
Section titled “Parameters”cancellationToken CancellationToken
The cancellation token.
Returns
Section titled “Returns”ValueTask<ModelProviderHealth>
The check result.
Remarks
Section titled “Remarks”The health check does not use OpenAIModelProvider._chatClientFactory — it makes a separate, lightweight HTTP GET. See AgentPrism.OpenAIProviderHealthCheck.
CreateChatClient(ModelBinding, ModelProviderCredential?)
Section titled “ CreateChatClient(ModelBinding, ModelProviderCredential?)”Produces a raw chat client for the given binding.
public IChatClient CreateChatClient(ModelBinding binding, ModelProviderCredential? credential = null)Parameters
Section titled “Parameters”binding ModelBinding
The model binding.
credential ModelProviderCredential?
A resolved per-tenant credential (BYOK). When null, the provider’s own setup-time credential is used and behavior is identical to a setup without per-tenant credentials. When given, the provider builds (or reuses a cached) client using ModelProviderCredential.ApiKey and, if present, ModelProviderCredential.Endpoint, instead of its setup-time credential.
Returns
Section titled “Returns”IChatClient
The provider-specific client. Decorators specific to the provider (example: Anthropic’s settings decorator) may be added here.
Remarks
Section titled “Remarks”Do not build the common pipeline here.
UseFunctionInvocation, UseOpenTelemetry, the content
guard, the circuit breaker, and extra resolution are added by
ModelProviderRegistry.CreateChatClient. Before that shared pipeline, every
provider package built the tool-call loop inside itself; the result
was that no ring the registry wraps around could see the loop’s turns
— a tool result entered the model uninspected.
If the loop is also built here, two nested FunctionInvokingChatClient
instances form: the inner one resolves tools, the outer one never sees
any call. The damage is not functional but measurable (double
wrapping, a misleading span tree).
GetConfigurationDiagnostic()
Section titled “ GetConfigurationDiagnostic()”Returns the resolution status of the configuration key required by this provider.
public ConfigurationDiagnostic? GetConfigurationDiagnostic()Returns
Section titled “Returns”null when the provider was not configured with an options object.