Skip to content

OpenAIResponsesLanguageModel

Namespace: Vercel.AI.OpenAI

public sealed class OpenAIResponsesLanguageModel : ILanguageModel

OpenAI Responses API language model.

Inheritance: object

Implements: ILanguageModel

View source

OpenAIResponsesLanguageModel(AzureOpenAIProvider, string)

Section titled “OpenAIResponsesLanguageModel(AzureOpenAIProvider, string)”
public OpenAIResponsesLanguageModel(AzureOpenAIProvider provider, string modelId)

Creates an Azure OpenAI Responses model. Message and request options are read from the azure provider options first and fall back to openai when azure is absent.

Parameters

Name Type Description
provider AzureOpenAIProvider
modelId string

View source

OpenAIResponsesLanguageModel(AzureOpenAIProvider, string, AzureOpenAILanguageModelSettings?)

Section titled “OpenAIResponsesLanguageModel(AzureOpenAIProvider, string, AzureOpenAILanguageModelSettings?)”
public OpenAIResponsesLanguageModel(AzureOpenAIProvider provider, string deploymentId, AzureOpenAILanguageModelSettings? settings)

Creates an Azure OpenAI Responses model for a deployment. ModelId reports <code class=“paramref”>settings</code>.ModelId when set and drives capability detection. Requests always use <code class=“paramref”>deploymentId</code>.

Parameters

Name Type Description
provider AzureOpenAIProvider
deploymentId string
settings AzureOpenAILanguageModelSettings

View source

OpenAIResponsesLanguageModel(OpenAIProvider, string)

Section titled “OpenAIResponsesLanguageModel(OpenAIProvider, string)”
public OpenAIResponsesLanguageModel(OpenAIProvider provider, string modelId)

Creates a Responses model.

Parameters

Name Type Description
provider OpenAIProvider
modelId string

View source

public string ModelId { get; }

Model id.

Value: string

View source

public string Provider { get; }

Provider id, such as openai.

Value: string

View source

public string SpecificationVersion { get; }

Always V4.

Value: string

View source

public bool SupportsWebSearchSourcesInclude { get; init; }

Whether a request with a web_search or web_search_preview tool adds web_search_call.action.sources to include. The default is true. The includeWebSearchSources provider option set to false also turns it off.

Value: bool

View source

DoGenerateAsync(LanguageModelCallOptions, CancellationToken)

Section titled “DoGenerateAsync(LanguageModelCallOptions, CancellationToken)”
public Task<LanguageModelGenerateResult> DoGenerateAsync(LanguageModelCallOptions options, CancellationToken cancellationToken)

Generates a complete result.

Parameters

Name Type Description
options LanguageModelCallOptions
cancellationToken CancellationToken

Returns: Task<LanguageModelGenerateResult>

View source

DoStreamAsync(LanguageModelCallOptions, CancellationToken)

Section titled “DoStreamAsync(LanguageModelCallOptions, CancellationToken)”
public Task<LanguageModelStreamResult> DoStreamAsync(LanguageModelCallOptions options, CancellationToken cancellationToken)

Streams partial results. The result carries the stream with the request and response info.

Parameters

Name Type Description
options LanguageModelCallOptions
cancellationToken CancellationToken

Returns: Task<LanguageModelStreamResult>

View source

Prepare(string, LanguageModelCallOptions, bool)

Section titled “Prepare(string, LanguageModelCallOptions, bool)”
public static OpenAIResponsesPreparedRequest Prepare(string modelId, LanguageModelCallOptions options, bool stream)

Builds the Responses body for <code class=“paramref”>modelId</code>. Generate calls omit stream.

Parameters

Name Type Description
modelId string
options LanguageModelCallOptions
stream bool

Returns: OpenAIResponsesPreparedRequest

View source

Prepare(string, LanguageModelCallOptions, bool, string, bool)

Section titled “Prepare(string, LanguageModelCallOptions, bool, string, bool)”
public static OpenAIResponsesPreparedRequest Prepare(string modelId, LanguageModelCallOptions options, bool stream, string providerOptionsName, bool supportsWebSearchSourcesInclude = true)

Builds the Responses body. Options come from <code class=“paramref”>providerOptionsName</code> and fall back to openai when that key is absent.

Parameters

Name Type Description
modelId string
options LanguageModelCallOptions
stream bool
providerOptionsName string
supportsWebSearchSourcesInclude bool

Returns: OpenAIResponsesPreparedRequest

View source

Prepare(string, LanguageModelCallOptions, bool, string, bool, string?)

Section titled “Prepare(string, LanguageModelCallOptions, bool, string, bool, string?)”
public static OpenAIResponsesPreparedRequest Prepare(string modelId, LanguageModelCallOptions options, bool stream, string providerOptionsName, bool supportsWebSearchSourcesInclude, string? requestModelId)

Builds the Responses body. <code class=“paramref”>modelId</code> drives capability detection and <code class=“paramref”>requestModelId</code>, when set, is sent as the request model.

Parameters

Name Type Description
modelId string
options LanguageModelCallOptions
stream bool
providerOptionsName string
supportsWebSearchSourcesInclude bool
requestModelId string

Returns: OpenAIResponsesPreparedRequest

View source

PrepareResponsesTools(IReadOnlyList<LanguageModelTool>?, ToolChoice?, PrepareResponsesToolsOptions?)

Section titled “PrepareResponsesTools(IReadOnlyList<LanguageModelTool>?, ToolChoice?, PrepareResponsesToolsOptions?)”
public static PreparedResponsesTools PrepareResponsesTools(IReadOnlyList<LanguageModelTool>? tools, ToolChoice? toolChoice, PrepareResponsesToolsOptions? options = null)

Prepares Responses tools and the tool choice. Strict is false unless the tool sets Strict. Maps to prepareResponsesTools.

Parameters

Name Type Description
tools IReadOnlyList<LanguageModelTool>
toolChoice ToolChoice
options PrepareResponsesToolsOptions

Returns: PreparedResponsesTools

Exceptions

Type Condition
TypeValidationException The arguments of a provider-defined tool are invalid.
UnsupportedFunctionalityException The tools or the tool choice cannot be expressed for OpenAI.

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product