Errors
Every HTTP status and error code the gateway returns, what to do about each, and how to retry safely.
Errors are JSON. On chat completions and Responses the body has an error object with message, type, param and code. On POST /v1/messages it is the Anthropic shape, {"type": "error", "error": {"type", "message"}}, with no code and no param. Read the body as well as the status: several different problems share one status. The message is written for people. In your own code, match on code, and on error.type when there is no code. Do not match on the text.
Every inference response carries Inference-Id, and so does every 5xx. Quote it to support.
Status and code#
| Status | code or type |
What to do |
|---|---|---|
| 400 | invalid_request_error |
The request is malformed or outside the model's limits. Fix it. Do not retry unchanged. |
| 400 | context_length_exceeded |
Prompt plus max_tokens is over the model's context. Shorten the input or lower max_tokens. |
| 400 | invalid_type |
A field has the wrong JSON type. param names it. model must be a string. messages and tools must be arrays. |
| 400 | image_too_large, invalid_image, invalid_image_url |
An image is over the pixel limit, cannot be decoded, or its URL returned not found. Fix the image. |
| 401 | 401 |
The API key is missing or not valid. Check the key and the header. Try Authorization: Bearer or x-api-key. |
| 403 | 403 |
The key cannot call this route or model. A customer key cannot call account, key, team, billing or gateway routes. |
| 403 | model_not_allowed |
Your team admin has not enabled this model for you. Ask them, or pick another. See Model access. |
| 403 | model_access_required |
This model needs approved access, and this key has not been granted it. Apply for access, then use a key that has it. |
| 403 | closed_model_pay_per_use |
Claude and GPT models are pay-per-use and not in your plan, and your Team has no credits. Ask an admin to add credits. |
| 403 | model_unavailable_in_region |
Claude and GPT models are not available in your region. Open models keep working. |
| 404 | model_at_capacity |
The model is paused. Try again later, or use another model. |
| 402 | member_credits_exhausted |
Your seat or plan allowance is used up. A Team admin can upgrade your seat or add credits. Do not retry. |
| 402 | credits_exhausted |
Your Team's credits are exhausted (budget_exceeded type). Do not retry. Top up. |
| 402 | key_budget_exhausted |
The key's own budget is used up (budget_exceeded type). Do not retry. Raise the key budget or top up. |
| 402 | development_credits_exhausted |
A Development key's credit pool is empty (budget_exceeded type). Do not retry. A Team admin can move credits in. |
| 429 | rate_limit_error or throttling_error (type) |
Over a rate limit. Not charged. Wait for Retry-After, then retry with backoff. |
| 429 | service_quota_exceeded |
The daily service quota cannot cover this request. Try again after the daily reset. |
| 500, 502, 503, 504 | the status as code, api_error or internal_server_error (type) |
The gateway or the model is not responding. Retry with backoff after checking the request. A stream that fails after it started sends an error event with code upstream_unavailable. |
| 503 | model_policy_guard_unavailable |
The model access check could not run. Retry with backoff. |
Credits that run out return 402 with the budget_exceeded type and a code that names which balance ran out. There is no Retry-After: paying fixes it and waiting does not. Read it as "stop", not "retry", and do not confuse it with 429, which OpenAI SDKs retry by default. On /v1/messages the error keeps the Anthropic envelope, with type billing_error and no code. Any other 422 is a request problem and reaches you unchanged.
Which 429 is it#
Two different problems share 429. Tell them apart before you retry:
| Signal | Meaning | What to do |
|---|---|---|
RateLimit header shows r=0 for requests, throughput or concurrency |
You are at one of your team's caps. | Wait for Retry-After. Lower concurrency. |
RateLimit header absent, Retry-After present |
The gateway is briefly at capacity. | Wait for Retry-After, then retry. |
Rate Limits has the header format.
Retrying safely#
A 400, 401, 402, 403, 404 or 422 will fail the same way again. Fix the cause. Retry only a rate-limit 429, a 500, 502, 503 or 504, a timeout, or a stream that dropped.
A 502, a timeout or a dropped stream leaves one question open: did the gateway finish the request and charge for it? Check before you resend, so you do not pay twice.
- Take the
Inference-Idfrom the failed response. It is alsoX-Request-Id, and every5xxcarries it. - Ask for that request with the same key:
- Read the result.
- A request in the log was recorded, with its exact
costand token counts.failed,invalid,rejectedandthrottledshow the charge, usually0. A completed request was charged: resend only if you need a new answer. 404means this key made no request with that id in the last 90 days. The gateway did not record it. Resend.
- A request in the log was recorded, with its exact
- A request appears within a few seconds of finishing. If you get
404right after a failure, wait a few seconds and ask again once before you resend.
If your client timed out before any response headers arrived, you have no id. List the key's recent requests instead, with GET /v1/requests?model=<model>&limit=5, newest first, and look for yours by time.
When you resend, back off: wait 1 second, then 2, then 4, with some random jitter, and give up after a few tries. A request that costs money should not loop forever. See Billing for the request log fields.