OpenAICompatibleChat
Namespace: Vercel.AI.OpenAICompatible
public static class OpenAICompatibleChatShared OpenAI-compatible chat request and response helpers.
Inheritance: object
Methods
Section titled “Methods”BaseProviderName(string?)
Section titled “BaseProviderName(string?)”public static string BaseProviderName(string? providerId)First segment of a provider id. anthropic.beta is anthropic.
Parameters
| Name | Type | Description |
|---|---|---|
providerId |
string |
Returns: string
ConvertCompletionUsage(JsonElement?)
Section titled “ConvertCompletionUsage(JsonElement?)”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
ConvertContent(JsonElement)
Section titled “ConvertContent(JsonElement)”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>
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
ConvertUsage(JsonElement?)
Section titled “ConvertUsage(JsonElement?)”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
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
IsCustomReasoning(string?)
Section titled “IsCustomReasoning(string?)”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
ProviderMetadata(string, int?, int?)
Section titled “ProviderMetadata(string, int?, int?)”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
Qualify(string?, string)
Section titled “Qualify(string?, string)”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
ReadErrorMessage(string?)
Section titled “ReadErrorMessage(string?)”public static string? ReadErrorMessage(string? body)Reads error.message or a string error without appending param.
Parameters
| Name | Type | Description |
|---|---|---|
body |
string |
Returns: string
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
ThoughtSignatureMetadata(string, string)
Section titled “ThoughtSignatureMetadata(string, string)”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
ToCamelCase(string)
Section titled “ToCamelCase(string)”public static string ToCamelCase(string value)Converts provider-name and provider_name to providerName.
Parameters
| Name | Type | Description |
|---|---|---|
value |
string |
Returns: string
Unsupported(string)
Section titled “Unsupported(string)”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
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> |
WithMessage(ApiException, string)
Section titled “WithMessage(ApiException, string)”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
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product