The error format depends on the address you sent the request to. Every error carries a request ID.
On /v1/chat/completions, /v1/responses and all other addresses the error arrives in the OpenAI format:
{
"error": {
"message": "Invalid or missing API key. Request ID: req_0be8…",
"type": "authentication_error",
"code": "authentication_error",
"request_id": "req_0be8…"
}
}On /v1/messages the error arrives in the Anthropic format, which the Anthropic SDK and Claude Code understand:
{
"type": "error",
"error": {
"type": "authentication_error",
"message": "Invalid or missing API key. Request ID: req_0be8…"
},
"request_id": "req_0be8…"
}The request ID is in the request_id field, at the end of the message text and in the X-Request-Id header. Send it to support: it lets us find the request.
The values in the code column come in the OpenAI format. In the Anthropic format the same cause shows up as the HTTP status and the error type.
| HTTP | code | What to do |
|---|---|---|
400 | model_requiredbad_requestinvalid_request | Check the request body: JSON and required fields. |
400 | model_not_found | Check the model name in GET /v1/models. |
400 | context_length_exceeded | Shorten the request or use a model with a larger context. |
400 | image_input_not_supported | The model does not accept images, use a model with vision. |
400 | content_policy_violation | The request violates the usage policy. |
401 | authentication_error | The key is wrong, revoked or missing. On image and video addresses the code field can arrive as unauthorized, the type stays authentication_error. |
402 | insufficient_quota | Top up your balance. |
402 | account_frozen | The account is suspended, write to support. |
403 | model_not_in_channel | The model is not in this key's channel: change the key's channel or the model. |
404 | not_found | Unknown API address. |
413 | request_too_large | The request body is larger than 32 MB. |
429 | rate_limitedfamily_rate_limited | Too many requests, retry in a few seconds. |
429 | org_queue_full | Too many concurrent requests on this key, wait for the current ones to finish. |
429 | queue_fullqueue_timeout | The service is busy, retry in a few seconds. |
429 | low_balance | The balance is almost empty, so requests run one at a time. Top up your balance. |
500, 502 | server_errorempty_response | Processing failed, retry the request. |
503 | model_overloaded | The model is overloaded, retry later. |
503 | maintenanceauth_unavailableservice_unavailable | Temporarily unavailable, retry in a few seconds. |
Channel selection errors (channel_not_allowed, fallback_not_allowed, channel_unavailable, invalid_state) are covered on the Premium and Cheap channels page.
If the response includes Retry-After, use it to decide when to retry.
If an error happens after the stream has started, the response code is already 200, so the error arrives as an event:
data: {"error": {…}}, then data: [DONE];event: error with the error body;response.failed event.If the model cut the answer off midway, you get an error with the code upstream_stream_interrupted or stream_incomplete. The answer is unfinished, so retry the request.
If the error happens before the answer starts, nothing is charged. If the answer is cut off midway, you are charged only for the tokens the model already produced.
Read the HTTP status and the error code (error.code or error.type) before deciding how to handle the response.
low_balance, top up the balance before retrying; repeating the request will not help. For other 429 codes, wait as long as Retry-After says when it is present, otherwise back off with a random jitter and cap the number of attempts.def read_api_error(response):
content_type = response.headers.get("Content-Type", "")
body = response.json() if "application/json" in content_type else None
error = body.get("error") if isinstance(body, dict) else None
code = None
if isinstance(error, dict):
code = error.get("code") or error.get("type")
return response.status_code, code, response.headers.get("Retry-After")