How failures are returned on the OpenAI-compatible and Anthropic-compatible APIs, and how your application should react.

OpenAI-compatible (/v1/*)

{
  "error": {
    "message": "Human-readable detail",
    "type": "invalid_request_error",
    "param": "messages[0].tool_call_id",
    "code": "insufficient_balance"
  }
}
FieldMeaning
messagePrimary explanation
typee.g. invalid_request_error, rate_limit_error
paramJSON path when validation failed
codeMachine hint when set (insufficient_balance, quota_exceeded, ip_not_allowed, upstream_rate_limited, …)

Some responses include error.gateway with extra structured hints.

Anthropic-compatible (/anthropic/v1/*)

{
  "type": "error",
  "error": { "type": "authentication_error", "message": "..." },
  "request_id": "req_..."
}

Keep request_id when opening support tickets.

HTTP status codes

StatusMeaningClient action
400Bad body or unsupported contentFix payload; do not retry blindly
401Missing/invalid/expired API keyFix Authorization / x-api-key
403Policy: model, balance, IP, keysFix config; usually no retry
429Rate limitedExponential backoff with jitter
502/503Upstream or transient gatewayLimited retries
504TimeoutIncrease client timeout; check payload size

Retry policy

  1. Retry: 429, 502, 503, 504 and transient network errors.
  2. Do not retry without change: 400, 401, most 403.
  3. Use idempotency for side-effecting tool calls.
  4. Cap retries (e.g. 3–5) with backoff from ~1s up to ~60s.

Correlation

Send x-trace-id on every request; include it in tickets with timestamp, model, and redacted headers (Support information, Request correlation).