Error Handling

Errors are returned as JSON with an error object containing message, type, and code.

Error response
{
  "error": {
    "message": "Rate limit exceeded. Please retry after a brief wait.",
    "type": "rate_limit_error",
    "code": 429
  }
}

HTTP Status Codes

StatusTypeDescription
200SuccessRequest succeeded.
400invalid_request_errorInvalid request body, missing messages, or content filtered by safety system.
401authentication_errorInvalid or missing API key.
429rate_limit_errorToo many requests or concurrent connections. Check the Retry-After header.
502upstream_errorFailed to connect to upstream model provider.
503service_unavailableService temporarily unavailable. Daily quota or plan limit reached.

Retry Strategy

For 429 errors, respect the Retry-After header value (in seconds). For 503 errors, use exponential backoff starting from 5 seconds with a maximum of 60 seconds.