JsonValues
Namespace: Vercel.AI.ProviderUtils
public static class JsonValuesSmall JSON helpers shared by providers.
Inheritance: object
Properties
Section titled “Properties”Options
Section titled “Options”public static JsonSerializerOptions Options { get; }Serializer options used for provider bodies.
Value: JsonSerializerOptions
Methods
Section titled “Methods”EmptyObject()
Section titled “EmptyObject()”public static JsonElement EmptyObject()An empty JSON object.
Returns: JsonElement
ExtractErrorMessage(string?, int)
Section titled “ExtractErrorMessage(string?, int)”public static string ExtractErrorMessage(string? body, int statusCode)Best-effort error message from a provider JSON body.
Parameters
| Name | Type | Description |
|---|---|---|
body |
string | |
statusCode |
int |
Returns: string
GenerateId(string)
Section titled “GenerateId(string)”public static string GenerateId(string prefix)Creates a new id. Maps to generateId.
Parameters
| Name | Type | Description |
|---|---|---|
prefix |
string |
Returns: string
GetInt(JsonElement, string)
Section titled “GetInt(JsonElement, string)”public static int? GetInt(JsonElement element, string name)Reads an integer property, or null.
Parameters
| Name | Type | Description |
|---|---|---|
element |
JsonElement | |
name |
string |
Returns: int?
GetString(JsonElement, string)
Section titled “GetString(JsonElement, string)”public static string? GetString(JsonElement element, string name)Reads a string property, or null.
Parameters
| Name | Type | Description |
|---|---|---|
element |
JsonElement | |
name |
string |
Returns: string
ParseOrEmpty(string?)
Section titled “ParseOrEmpty(string?)”public static JsonElement ParseOrEmpty(string? json)Parses a JSON object or returns an empty object.
Parameters
| Name | Type | Description |
|---|---|---|
json |
string |
Returns: JsonElement
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product