Skip to content

OpenAIProviderOptionsValidator

Namespace AgentPrism · Assembly AgentPrism.OpenAI.dll

Validates OpenAIProviderOptions while the application starts.

public sealed class OpenAIProviderOptionsValidator : IValidateOptions<OpenAIProviderOptions>

objectOpenAIProviderOptionsValidator

IValidateOptions<OpenAIProviderOptions>

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

The validation is written by hand; ValidateDataAnnotations relies on reflection and produces IL2026. AgentPrism.OpenAI must stay AOT compatible.

The failure messages never contain the API key. Validation messages go to the log and to the startup exception; leaking the key there exposes it.

This validator checks both the unnamed (default) options instance of UseOpenAI and the named instances of UseOpenAICompatible. The name parameter of OpenAIProviderOptionsValidator.Validate tells the two apart: on the unnamed instance (name is empty) the API key is required, because the official OpenAI service does not work without a key. On a named instance (a compatible provider) the API key is optional (local servers do not ask for one) but OpenAIProviderOptions.Endpoint is required — if it were left empty, the request would silently go to the official OpenAI address.

public OpenAIProviderOptionsValidator()
public ValidateOptionsResult Validate(string? name, OpenAIProviderOptions options)

name string?

options OpenAIProviderOptions

ValidateOptionsResult