Errors
Every error uses one envelope: {"error":{"code":"...","message":"...","status":...}}. The code is machine-readable and stable (e.g. INSUFFICIENT_CREDITS), message is for humans and may change, and status mirrors the HTTP status. Branch on code, never on the message text.
Which errors to retry
429. Wait per theRetry-Afterheader, then retry.500/502/503/504. Retry with backoff; if you sent anIdempotency-Key, the retry is safe.400/401/402/409. Retrying won't help; fix the request, key, or credit first.499means your own client disconnected; nothing was charged.
Error catalogue
| Status | code | Description |
|---|---|---|
| 400 | BAD_REQUEST | The request body or query parameters are invalid. Check the
|
| 400 | INVALID_TOOLS | Returned when the
The error message names the offender and includes a migration hint. The hold has NOT been placed (no charge). |
| 400 | UNSUPPORTED_IMAGE_FORMAT | The image bytes could not be decoded (HEIC, AVIF, partial bytes,
non-image content). The classifier requires JPEG, PNG, WebP, or
GIF input. Re-encode the image and resend with a fresh
|
| 401 | UNAUTHORIZED | Authentication failed. Either the |
| 404 | NOT_FOUND | The requested resource was not found. Either the ID is wrong or it belongs to a different account. |
| 409 | CONFLICT | Idempotency key conflict: you sent the same |
| 429 | RATE_LIMITED | Too many requests. Back off and retry after a short delay.
Check the |
| 499 | CLIENT_CLOSED | Your HTTP client cancelled the request before the gateway finished. No charge: the hold has been released. The most common cause is a 30 s default client timeout against a model whose p95 latency is 45-60 s; bump your client timeout to 120 s. Retries with the same |
| 500 | INTERNAL_ERROR | Unexpected server error. Please retry with exponential backoff. If the issue persists, contact your admin. |
| 502 | UPSTREAM_ERROR | The upstream AI provider is temporarily
unavailable. Retry with exponential backoff (1s, 2s, 4s) using the
same |
| 504 | UPSTREAM_TIMEOUT | The gateway's 120 s upstream deadline elapsed before the upstream
provider produced a response. Retry with the same
|
FAQ
- What does 402 INSUFFICIENT_CREDITS mean?
Your balance can't cover this request's hold. The request never reaches the model and nothing is charged; top up and retry.
- Why am I getting 499?
Your HTTP client closed the connection before the response finished (usually a short timeout). Raise the timeout or enable streaming; the hold was released.