Skip to content

Errors ​

Errors use the OpenAI shape:

json
{ "error": { "message": "…", "type": "invalid_request_error" } }

Branch on the HTTP status, never on the message text.

Status codes ​

StatusMeaningWhat to do
401Key invalid or missingCheck the Authorization header and key status
402Insufficient balanceTop up, or switch to a cheaper group
403Key disabled / IP not allowedCheck key status and IP allowlist
404Model not in this groupCall GET /v1/models and use a listed name
429Rate or concurrency limitLower concurrency, retry with backoff
5xxUpstream failureThe gateway fails over automatically; retry, and report if persistent

Retry policy ​

  • Retry 429 and 5xx: exponential backoff starting at 500ms, capped at 8s, three attempts.
  • Never retry 401 / 402 / 403 / 404.
  • Retrying a stream after the first token duplicates content — deduplicate on the client.

What to include in a report ​

  1. x-request-id from the response headers
  2. Timestamp (to the minute)
  3. Model name and protocol used
  4. The full error response

With the request id we can find that exact call in the usage log, including which upstream served it.

LeekBox — unified AI gateway