Errors

Check HTTP status first, then decode the protocol-specific error. Not every response has a string error.code.

Gateway errors outside Anthropic

{"error":{"code":404,"type":"invalid_request_error","message":"Model not found","gateway_code":"MODEL_NOT_FOUND"}}

error.code is the numeric HTTP status; error.gateway_code is the detailed machine identifier. X-Gateway-Trace-ID is a response header.

Anthropic Messages / count_tokens errors

{"type":"error","error":{"type":"invalid_request_error","message":"Model not found"},"request_id":"gw-..."}

This shape has error.type, error.message and request_id, without a guaranteed gateway_code or string code. Sanitized upstream errors may instead use error.code = UPSTREAM_REQUEST_FAILED or UPSTREAM_MEDIA_FETCH_FAILED. Handle all three shapes without expecting private upstream details.

Common gateway identifiers

HTTPgateway_codeMeaning
400MODEL_REQUIREDMissing model
400INVALID_REQUEST_BODYInvalid speech request; other validation depends on mapping
400PROTOCOL_TRANSFORM_FAILED / AUDIO_FORMAT_UNSUPPORTED / PROTOCOL_STREAM_UNSUPPORTEDMapping, format or streaming mismatch
401UNAUTHORIZED / INVALID_API_KEYMissing or invalid key
402INSUFFICIENT_BALANCE / KEY_BUDGET_EXCEEDED / PROJECT_BUDGET_EXCEEDEDInsufficient balance or exhausted budget
402 / 403PROJECT_DISABLEDModel/list requests use 402; file requests use 403
403MODEL_NOT_ALLOWEDModel not allowed by this key
404MODEL_NOT_FOUND / MODEL_API_NOT_SUPPORTEDUnavailable model or no mapping for this protocol
404UNSUPPORTED_ENDPOINT / VIDEO_TASK_NOT_FOUNDUnknown path or invalid video handle
405METHOD_NOT_ALLOWEDUnsupported HTTP method
413REQUEST_TOO_LARGEBody too large or cannot be read by the endpoint
429RATE_LIMIT_EXCEEDED / ROUTE_CAPACITY_EXCEEDEDKey rate limit or exhausted route capacity
500API_KEY_LOOKUP_FAILED / MODEL_QUERY_FAILED / MODEL_LIST_QUERY_FAILED / MODEL_RULE_CHECK_FAILED / MAPPING_QUERY_FAILEDDatabase/internal lookup failure
502UPSTREAM_CONNECT_ERROR / UPSTREAM_TRANSPORT_ERROR / PROTOCOL_RESPONSE_TRANSFORM_FAILEDConnection, transport or response conversion failure
503UPSTREAM_UNAVAILABLE / RATE_LIMIT_STATE_UNAVAILABLENo available upstream or unavailable rate state
504UPSTREAM_TIMEOUTUpstream timed out; work may already have started

For unknown identifiers retain status and Trace for support. Do not infer unsupported codes. File-specific errors are documented in the files API.

Retry handling

402 requires fixing balance, budget or project state; 401/403 require credentials or permissions. Respect Retry-After for 429 and use bounded backoff for safely retryable 5xx requests. SSE can report errors after HTTP 200; stop and retain the Trace.

Files · Streaming · Trace

Error codes · Documentation · InOneAPI