Skip to content
Main Site News Console

Error Codes and Retries

When an error occurs, the API returns a non-2xx status code, and the response body is JSON:

{
"error": {
"message": "error description",
"type": "invalid_request_error",
"code": "..."
}
}

Common Error Codes

HTTP StatusCommon CauseRecommended Action
400Parameter error, invalid request body formatVerify parameters and JSON format
401Missing / invalid keyCheck Authorization: Bearer sk-...
403Token disabled, model group not authorizedCheck token status and group in the console
404Model name does not exist or is not availableSee Model Overview
413Request body too large (context limit exceeded)Reduce messages or switch to a long-context model
429Rate limit exceeded or insufficient quotaRetry with backoff; see Rate Limits and 429
500 / 502 / 503Upstream model instabilityRetry after a short backoff; the gateway will automatically switch to an available upstream

Retry Recommendations

  • For 429 / 5xx, use exponential backoff + jitter: e.g. 1s, 2s, 4s, up to 3–5 retries;
  • 400 / 401 / 403 are deterministic errors; retries are meaningless and the request should be fixed first;
  • For idempotent scenarios (such as image generation), confirm the final status of the previous request before resubmitting to avoid duplicate charges;
  • In production, it is recommended to log the response headers and error.message to help identify which part returned the error.