API

Errors

The error format, what each code means and how to handle it.

Failed requests return a non-200 HTTP status and a body in this format:

Error format
{
  "error": {
    "message": "Insufficient credits. Please top up and try again.",
    "type": "relay_error",
    "code": "insufficient_quota",
    "request_id": "req_8c1f02…"
  }
}
codeHTTPMeaningWhat to do
invalid_api_key401The key is invalid, expired or disabledCheck the key under API Keys in the console
insufficient_quota402Account credits or this key’s limit are used upAdd credits or raise the key’s spending limit
rate_limited429Too many requestsLower concurrency and retry after a few seconds
invalid_request400A request parameter is wrongRead the message and check the request body
context_length_exceeded400Input exceeds the model’s context windowShorten the input or use a model with a longer context
content_filtered400The request was blocked by a content policyChange the content. Uncensored models rarely trigger this.
model_unavailable404 / 503Unknown model ID, or the model is temporarily unavailableCheck the model ID, retry later or switch models
service_unavailable503 / 504The service is temporarily unavailableRetry later. Contact support if it persists.

Retries

Retry only on 429, 503 and 504, with exponential backoff (for example 1 s, 2 s, 4 s) and at most three attempts. Retrying 400, 401 or 402 will not help until the cause is fixed.

request_id

Every response carries an x-request-id header, and error bodies include it too. Quote it when you contact support so the exact request can be found.