OpenAIProvider
Namespace: Vercel.AI.OpenAI
public sealed class OpenAIProvider : OpenAICompatibleProvider, IBatchProviderOpenAI provider: Chat Completions, Responses, embeddings, images, speech, transcription, files, and batches.
Inheritance: object → ProviderBase → OpenAICompatibleProvider
Implements: IBatchProvider
Constructors
Section titled “Constructors”OpenAIProvider(HttpClient, OpenAIOptions?)
Section titled “OpenAIProvider(HttpClient, OpenAIOptions?)”public OpenAIProvider(HttpClient httpClient, OpenAIOptions? options = null)Creates an OpenAI provider.
Parameters
| Name | Type | Description |
|---|---|---|
httpClient |
HttpClient | |
options |
OpenAIOptions |
Fields
Section titled “Fields”ProviderId
Section titled “ProviderId”public const string ProviderId = "openai"Provider id.
Value: string
UserAgentSuffix
Section titled “UserAgentSuffix”public const string UserAgentSuffix = "ai-sdk/openai/4.0.73"User-Agent suffix appended to every request. Tracks @ai-sdk/openai 4.0.73.
Value: string
Properties
Section titled “Properties”HttpClient
Section titled “HttpClient”public HttpClient HttpClient { get; }HTTP client used for calls that need response headers.
Value: HttpClient
Methods
Section titled “Methods”BatchModel()
Section titled “BatchModel()”public override IBatchModel BatchModel()Returns a batch model.
Returns: IBatchModel
ChatModel(string)
Section titled “ChatModel(string)”public OpenAIChatLanguageModel ChatModel(string modelId)Chat Completions model. The provider id is openai.chat.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: OpenAIChatLanguageModel
CompletionModel(string)
Section titled “CompletionModel(string)”public OpenAICompletionLanguageModel CompletionModel(string modelId)Legacy completions model. The provider id is openai.completion.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: OpenAICompletionLanguageModel
Create(OpenAIOptions?, HttpMessageHandler?)
Section titled “Create(OpenAIOptions?, HttpMessageHandler?)”public static OpenAIProvider Create(OpenAIOptions? options = null, HttpMessageHandler? handler = null)Creates a provider. Pass a handler from tests.
Parameters
| Name | Type | Description |
|---|---|---|
options |
OpenAIOptions | |
handler |
HttpMessageHandler |
Returns: OpenAIProvider
CreateOpenAIHeaders(IReadOnlyDictionary<string, string?>?)
Section titled “CreateOpenAIHeaders(IReadOnlyDictionary<string, string?>?)”public Dictionary<string, string?> CreateOpenAIHeaders(IReadOnlyDictionary<string, string?>? callHeaders = null)Builds request headers. Custom provider headers override the API key, organization, and project. The user-agent suffix is appended after that, and per-call headers override the result.
Parameters
| Name | Type | Description |
|---|---|---|
callHeaders |
IReadOnlyDictionary<string, string> |
Returns: Dictionary<string, string>
DecisionModel(string)
Section titled “DecisionModel(string)”public OpenAIDecisionModel DecisionModel(string modelId)Decisions API model. The provider id is openai.decision.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: OpenAIDecisionModel
EmbeddingModel(string)
Section titled “EmbeddingModel(string)”public override IEmbeddingModel EmbeddingModel(string modelId)Returns an embedding model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: IEmbeddingModel
EvaluationModel(string)
Section titled “EvaluationModel(string)”[Obsolete("Use DecisionModel instead.")]public OpenAIDecisionModel EvaluationModel(string modelId)Deprecated alias of DecisionModel(string). Maps to evaluationModel.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: OpenAIDecisionModel
ExperimentalBatch()
Section titled “ExperimentalBatch()”public IBatchApi? ExperimentalBatch()Batch API. Downloads batch results.
Returns: IBatchApi
FileStore()
Section titled “FileStore()”public override IFileStore FileStore()Returns a file store.
Returns: IFileStore
ImageModel(string)
Section titled “ImageModel(string)”public override IImageModel ImageModel(string modelId)Returns an image model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: IImageModel
LanguageModel(string)
Section titled “LanguageModel(string)”public override ILanguageModel LanguageModel(string modelId)Returns a language model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: ILanguageModel
RealtimeModel(string)
Section titled “RealtimeModel(string)”public override IRealtimeModel RealtimeModel(string modelId)Returns a realtime model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: IRealtimeModel
ResponsesModel(string)
Section titled “ResponsesModel(string)”public OpenAIResponsesLanguageModel ResponsesModel(string modelId)Responses API model. The provider id is openai.responses.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: OpenAIResponsesLanguageModel
SkillStore()
Section titled “SkillStore()”public override ISkillStore SkillStore()Returns a skill store.
Returns: ISkillStore
SpeechModel(string)
Section titled “SpeechModel(string)”public override ISpeechModel SpeechModel(string modelId)Returns a speech model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: ISpeechModel
SpeechTranslationModel(string)
Section titled “SpeechTranslationModel(string)”public override ISpeechTranslationModel SpeechTranslationModel(string modelId)Returns a speech translation model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: ISpeechTranslationModel
TranscriptionModel(string)
Section titled “TranscriptionModel(string)”public override ITranscriptionModel TranscriptionModel(string modelId)Returns a transcription model.
Parameters
| Name | Type | Description |
|---|---|---|
modelId |
string |
Returns: ITranscriptionModel
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product