errorformat

package
v0.7.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package errorformat decodes the error body formats that more than one provider package receives, such as OpenAI's, which OpenAI-compatible APIs copy. A format that only one package receives stays in that package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DashScopeKind

func DashScopeKind(code string) sdk.ErrorKind

DashScopeKind classifies a DashScope error code. Arrearage and the free-tier stop arrive as 400 and 403, so the status alone would misfile them.

func DecodeDashScope

func DecodeDashScope(e *sdk.APIError)

DecodeDashScope is the error decoder for Alibaba Cloud Model Studio's DashScope API (https://help.aliyun.com/zh/model-studio/error-code). The request ID comes from the body.

func DecodeDeepgram

func DecodeDeepgram(e *sdk.APIError)

DecodeDeepgram fills e from a Deepgram error body, documented at https://developers.deepgram.com/docs/errors. Most endpoints send {"err_code":"...","err_msg":"...","request_id":"..."}; the 503 example spells the code error_code, and JSON validation failures send {"category":"...","message":"...","details":"...","request_id":"..."}. category becomes Type. The dg-request-id response header carries the same ID, see https://developers.deepgram.com/docs/text-to-speech.

func DecodeElevenLabs

func DecodeElevenLabs(e *sdk.APIError)

DecodeElevenLabs fills e from an ElevenLabs error body, documented at https://elevenlabs.io/docs/eleven-api/resources/errors: {"detail":{"type":"...","code":"...","message":"...","status":"...","request_id":"...","param":"..."}}. Some endpoints still send only the legacy fields, {"detail":{"status":"model_not_found","message":"..."}}, so Code falls back to status. The x-trace-id response header carries the same ID as request_id and is the only ID on a legacy body. A body in any other shape keeps the Kind derived from the status.

func DecodeGoogle

func DecodeGoogle(e *sdk.APIError)

DecodeGoogle is the error decoder for Google APIs, which report errors as a google.rpc.Status. Type is the canonical status (error.status) and Code is the reason of the google.rpc.ErrorInfo detail, when there is one. The APIs document no request ID header, so RequestID stays empty.

RESOURCE_EXHAUSTED covers per-minute and per-day quotas alike. When a google.rpc.QuotaFailure detail names a daily quota among its violations, the Kind is KindQuotaExhausted: the quota resets once a day, whatever delay the RetryInfo detail suggests.

func DecodeOpenAI

func DecodeOpenAI(e *sdk.APIError)

DecodeOpenAI is the error decoder for OpenAI's API and the OpenAI-compatible endpoints the OpenAI-format packages are pointed at. The request ID comes from x-request-id, or from x-amzn-requestid on Amazon Bedrock.

func DecodeOpenAIErrorEvent

func DecodeOpenAIErrorEvent(e *sdk.APIError)

DecodeOpenAIErrorEvent is DecodeOpenAI for a Responses "error" stream event.

func DecodeOpenAIFailedEvent

func DecodeOpenAIFailedEvent(e *sdk.APIError)

DecodeOpenAIFailedEvent is DecodeOpenAI for a Responses "response.failed" stream event.

func DecodeOpenRouter

func DecodeOpenRouter(e *sdk.APIError)

DecodeOpenRouter is the error decoder for OpenRouter (https://openrouter.ai/docs/api-reference/errors). Code is the numeric code as text and Type is metadata.error_type, which OpenRouter documents as the field to classify by. RequestID is the x-generation-id response header, which OpenRouter sends on chat completion errors and lists in Access-Control-Expose-Headers; its API reference does not describe it.

func DeepgramKind

func DeepgramKind(code string) sdk.ErrorKind

DeepgramKind classifies a Deepgram err_code. INSUFFICIENT_PERMISSIONS arrives as 401 as well as 403, so the status alone would misfile it.

func ElevenLabsKind

func ElevenLabsKind(typ, code string) sdk.ErrorKind

ElevenLabsKind classifies an ElevenLabs error type and code.

func GoogleKind

func GoogleKind(status, reason string) sdk.ErrorKind

GoogleKind classifies a google.rpc.Status by its ErrorInfo reason and, when the reason has no mapping, by its canonical status. The reasons are values of google.api.ErrorReason (https://github.com/googleapis/googleapis/blob/master/google/api/error_reason.proto).

func OpenAIKind

func OpenAIKind(typ, code string) sdk.ErrorKind

OpenAIKind classifies OpenAI's error type and code. It returns KindUnknown for values it has no mapping for, including every value an OpenAI-compatible API invents.

func OpenRouterKind

func OpenRouterKind(errorType string) sdk.ErrorKind

OpenRouterKind classifies an OpenRouter metadata.error_type.

func ParseOpenAI

func ParseOpenAI(e *sdk.APIError)

ParseOpenAI copies type, code and message from an OpenAI-format body into e. A numeric code is copied as its decimal text.

func ParseOpenAIErrorEvent

func ParseOpenAIErrorEvent(e *sdk.APIError)

ParseOpenAIErrorEvent copies code and message from a Responses "error" stream event into e: from the top level when it carries either, otherwise type, code and message from the nested error object.

func ParseOpenAIFailedEvent

func ParseOpenAIFailedEvent(e *sdk.APIError)

ParseOpenAIFailedEvent copies type, code and message from the error object of a Responses "response.failed" stream event into e.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL