Skip to content

GatewayErrors

Namespace: Vercel.AI.Gateway

public static class GatewayErrors

Parses Gateway auth headers and error bodies.

Inheritance: object

View source

public const string AuthMethodHeader = "ai-gateway-auth-method"

Header that carries api-key or oidc.

Value: string

View source

public const string TeamHeader = "x-vercel-ai-gateway-team"

Header that carries the Vercel AI Gateway team.

Value: string

View source

public static GatewayError AsGatewayError(Exception? error, string? authMethod = null)

Maps any failure to a Gateway error. Gateway errors pass through, transport timeouts become GatewayTimeoutError, and API call errors are read as Gateway error bodies. Maps to asGatewayError.

Parameters

Name Type Description
error Exception
authMethod string

Returns: GatewayError

View source

Create(JsonElement, int, string?, string, Exception?, bool?)

Section titled “Create(JsonElement, int, string?, string, Exception?, bool?)”
public static GatewayError Create(JsonElement response, int statusCode, string? authMethod = null, string defaultMessage = "Gateway request failed", Exception? cause = null, bool? isRetryable = null)

Maps a Gateway JSON body to a typed error. Invalid bodies become GatewayResponseError.

Parameters

Name Type Description
response JsonElement
statusCode int
authMethod string
defaultMessage string
cause Exception
isRetryable bool?

Returns: GatewayError

View source

public static JsonElement ExtractApiCallResponse(ApiCallError error)

Returns Data when set, else the response body parsed as JSON, else the raw body as a JSON string. A missing body yields an empty object. Maps to extractApiCallResponse.

Parameters

Name Type Description
error ApiCallError

Returns: JsonElement

View source

FromResponseBody(string?, int, string?, Exception?)

Section titled “FromResponseBody(string?, int, string?, Exception?)”
public static GatewayError FromResponseBody(string? body, int statusCode, string? authMethod, Exception? cause)

Maps an HTTP error body. Non-JSON bodies become GatewayResponseError.

Parameters

Name Type Description
body string
statusCode int
authMethod string
cause Exception

Returns: GatewayError

View source

ParseAuthMethod(IReadOnlyDictionary<string, string?>?)

Section titled “ParseAuthMethod(IReadOnlyDictionary<string, string?>?)”
public static string? ParseAuthMethod(IReadOnlyDictionary<string, string?>? headers)

Reads AuthMethodHeader. Any other value, including a different case, is ignored.

Parameters

Name Type Description
headers IReadOnlyDictionary<string, string>

Returns: string

View source

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