Skip to content

JsonValues

Namespace: Vercel.AI.ProviderUtils

public static class JsonValues

Small JSON helpers shared by providers.

Inheritance: object

View source

public static JsonSerializerOptions Options { get; }

Serializer options used for provider bodies.

Value: JsonSerializerOptions

View source

public static JsonElement EmptyObject()

An empty JSON object.

Returns: JsonElement

View source

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

View source

public static string GenerateId(string prefix)

Creates a new id. Maps to generateId.

Parameters

Name Type Description
prefix string

Returns: string

View source

public static int? GetInt(JsonElement element, string name)

Reads an integer property, or null.

Parameters

Name Type Description
element JsonElement
name string

Returns: int?

View source

public static string? GetString(JsonElement element, string name)

Reads a string property, or null.

Parameters

Name Type Description
element JsonElement
name string

Returns: string

View source

public static JsonElement ParseOrEmpty(string? json)

Parses a JSON object or returns an empty object.

Parameters

Name Type Description
json string

Returns: JsonElement

View source

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