Skip to content

OpenAICompatibleChat

Namespace: Vercel.AI.OpenAICompatible

public static class OpenAICompatibleChat

Shared OpenAI-compatible chat request and response helpers.

Inheritance: object

View source

public static string BaseProviderName(string? providerId)

First segment of a provider id. anthropic.beta is anthropic.

Parameters

Name Type Description
providerId string

Returns: string

View source

public static LanguageModelUsage ConvertCompletionUsage(JsonElement? usage)

Maps a Completions usage object. A missing object leaves token counts unset.

Parameters

Name Type Description
usage JsonElement?

Returns: LanguageModelUsage

View source

public static List<OpenAICompatibleContentPart> ConvertContent(JsonElement content)

Converts text and thinking content. Unknown parts are ignored.

Parameters

Name Type Description
content JsonElement

Returns: List<OpenAICompatibleContentPart>

View source

ConvertMessages(IReadOnlyList<ModelMessage>, string, string?, bool)

Section titled “ConvertMessages(IReadOnlyList<ModelMessage>, string, string?, bool)”
public static JsonArray ConvertMessages(IReadOnlyList<ModelMessage> prompt, string metadataKey, string? providerName = null, bool supportsMultiPartToolContent = false)

Converts prompt messages to Chat Completions messages.

Parameters

Name Type Description
prompt IReadOnlyList<ModelMessage>
metadataKey string
providerName string
supportsMultiPartToolContent bool

Returns: JsonArray

View source

public static OpenAICompatibleUsage ConvertUsage(JsonElement? usage)

Maps a Chat Completions usage object. A missing object leaves token counts unset.

Parameters

Name Type Description
usage JsonElement?

Returns: OpenAICompatibleUsage

View source

HasOptions(IReadOnlyDictionary<string, JsonElement>?, string)

Section titled “HasOptions(IReadOnlyDictionary<string, JsonElement>?, string)”
public static bool HasOptions(IReadOnlyDictionary<string, JsonElement>? providerOptions, string key)

True when <code class=“paramref”>key</code> is present and not JSON null.

Parameters

Name Type Description
providerOptions IReadOnlyDictionary<string, JsonElement>
key string

Returns: bool

View source

public static bool IsCustomReasoning(string? reasoning)

Top-level reasoning values other than provider-default are sent as reasoning_effort.

Parameters

Name Type Description
reasoning string

Returns: bool

View source

public static JsonElement ProviderMetadata(string metadataKey, int? acceptedPredictionTokens, int? rejectedPredictionTokens)

Builds provider metadata for accepted and rejected prediction tokens.

Parameters

Name Type Description
metadataKey string
acceptedPredictionTokens int?
rejectedPredictionTokens int?

Returns: JsonElement

View source

public static string Qualify(string? providerName, string kind)

Provider id for a model kind, such as groq.chat.

Parameters

Name Type Description
providerName string
kind string

Returns: string

View source

public static string? ReadErrorMessage(string? body)

Reads error.message or a string error without appending param.

Parameters

Name Type Description
body string

Returns: string

View source

ResolveProviderOptionsKey(string, IReadOnlyDictionary<string, JsonElement>?)

Section titled “ResolveProviderOptionsKey(string, IReadOnlyDictionary<string, JsonElement>?)”
public static string ResolveProviderOptionsKey(string rawName, IReadOnlyDictionary<string, JsonElement>? providerOptions)

Prefers the camelCase provider-options key when the caller supplied it.

Parameters

Name Type Description
rawName string
providerOptions IReadOnlyDictionary<string, JsonElement>

Returns: string

View source

public static JsonElement ThoughtSignatureMetadata(string metadataKey, string thoughtSignature)

Builds tool-call metadata that carries a Google thought signature.

Parameters

Name Type Description
metadataKey string
thoughtSignature string

Returns: JsonElement

View source

public static string ToCamelCase(string value)

Converts provider-name and provider_name to providerName.

Parameters

Name Type Description
value string

Returns: string

View source

public static AiSdkException Unsupported(string functionality)

Throws when a file part cannot be represented on this API.

Parameters

Name Type Description
functionality string

Returns: AiSdkException

View source

WarnIfDeprecated(string, IReadOnlyDictionary<string, JsonElement>?, IList<CallWarning>)

Section titled “WarnIfDeprecated(string, IReadOnlyDictionary<string, JsonElement>?, IList<CallWarning>)”
public static void WarnIfDeprecated(string rawName, IReadOnlyDictionary<string, JsonElement>? providerOptions, IList<CallWarning> warnings)

Adds a deprecation warning when <code class=“paramref”>providerOptions</code> uses a non-camelCase key.

Parameters

Name Type Description
rawName string
providerOptions IReadOnlyDictionary<string, JsonElement>
warnings IList<CallWarning>

View source

public static ApiException WithMessage(ApiException exception, string message)

Copies an API exception onto the same status type with a new message.

Parameters

Name Type Description
exception ApiException
message string

Returns: ApiException

View source

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