Skip to main content

Errors & status codes

The API uses standard HTTP status codes and a consistent error body for failures.

HTTP status codes

CodeMeaningTypical cause
200OKRequest succeeded.
400Bad RequestInvalid body, missing required field, or malformed parameters.
401UnauthorizedMissing or invalid API key.
402Payment RequiredInsufficient account balance.
403ForbiddenNot allowed (e.g. wrong host or endpoint).
404Not FoundModel, job, or resource ID not found.
429Too Many RequestsRate limit exceeded.
500Internal Server ErrorServer or upstream error; retry with backoff.
502Bad GatewayUpstream service error.
503Service UnavailableService temporarily unavailable.

Error response format

Error responses are JSON with at least:
FieldTypeDescription
errorstringShort code or description (e.g. invalid_api_key, Insufficient balance).
messagestringOptional; human-readable details.
For 429, the response may include:
FieldTypeDescription
retryAfternumberSuggested seconds to wait before retrying.
Example:
{
  "error": "Insufficient balance. Please add funds to your account."
}
{
  "error": "rate_limit_exceeded",
  "message": "Too many requests. Please slow down.",
  "retryAfter": 60
}

Common error cases

ScenarioStatusSuggested action
Wrong or missing API key401Check Authorization: Bearer sk_... and key in dashboard.
Out of balance402Add funds and retry; show “Add funds” in UI.
Invalid model ID404Use a model from the models list.
Rate limited429Back off; use retryAfter if present.
Server error500, 502, 503Retry with exponential backoff; contact support if persistent.

Best practices for handling errors

  1. Parse the body — Read the JSON error (and message) and display or log it.
  2. Map status to UX — 401 → “Sign in or check API key”; 402 → “Add funds”; 429 → “Too many requests; retry in X seconds.”
  3. Retries — Retry only on 429, 500, 502, 503; use backoff and optional retryAfter. Do not retry 400, 401, 402, 404 without fixing the request or account.
  4. Idempotency — For non-idempotent operations, use idempotency keys if the API supports them to avoid duplicate charges on retry.