GatewayErrors
Namespace: Vercel.AI.Gateway
public static class GatewayErrorsParses Gateway auth headers and error bodies.
Inheritance: object
Fields
Section titled “Fields”AuthMethodHeader
Section titled “AuthMethodHeader”public const string AuthMethodHeader = "ai-gateway-auth-method"Header that carries api-key or oidc.
Value: string
TeamHeader
Section titled “TeamHeader”public const string TeamHeader = "x-vercel-ai-gateway-team"Header that carries the Vercel AI Gateway team.
Value: string
Methods
Section titled “Methods”AsGatewayError(Exception?, string?)
Section titled “AsGatewayError(Exception?, string?)”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
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
ExtractApiCallResponse(ApiCallError)
Section titled “ExtractApiCallResponse(ApiCallError)”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
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
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
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product