Gateway
Errors and retries
Every refusal says what went wrong, in its format’s own error shape, and most cost nothing.
Conifer Gateway answers an error in the shape the SDK you use expects, with a code that says what happened. This page shows the two shapes, lists every status and code, says which errors to send again, and what to do about each.
The two shapes
The OpenAI routes answer in OpenAI’s shape:
{
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is missing or isn't valid.",
"request_id": "req_01M8QKG70MK3272G0TP16BF898"
}
}/v1/messages and /v1/messages/count_tokens answer in Anthropic’s shape, and so do the routes that read, such as GET /v1/models, when the request sends anthropic-version. There the request’s id sits outside error, and an error may carry details:
{
"type": "error",
"error": {
"type": "authentication_error",
"code": "invalid_api_key",
"message": "The API key is missing or isn't valid."
},
"request_id": "req_01M8QKG70MK3272G0TP16BF898"
}Every error also carries the request’s id in x-conifer-request-id, and in x-request-id or request-id. Quote it when you write to support.
Every status and code
The status follows the code, and the code is the same in both shapes.
| Status | Code | What it says |
|---|---|---|
| 400 | invalid_request | What the request got wrong, or the provider’s own words where it refused what the request asked for. |
| 400 | context_length_exceeded | The provider’s words, or the gateway’s where the request is longer than any model it may go to can hold; on Messages, “prompt is too long: ” comes first. |
| 401 | invalid_api_key | “The API key is missing or isn’t valid.” |
| 402 | insufficient_balance | What the request costs and what the balance holds. |
| 403 | forbidden | Why the key may not, such as “This key only reads: it can’t send requests to models.” |
| 404 | model_not_found | “No model is called …”, with the name sent. |
| 404 | router_not_found | No deployed router has this name, or a router on the automatic pool has fewer than two scored models to rank. |
| 404 | route_not_found | “No route for POST /v1/audio/speech.” |
| 404 | request_not_found | No such request in the log. |
| 405 | method_not_allowed | “/v1/chat/completions doesn’t take GET.” |
| 409 | idempotency_conflict | The Idempotency-Key’s first request is running, or ran. |
| 413 | request_too_large | “The body is larger than 32 MiB.” |
| 422 | idempotency_key_reused | The Idempotency-Key was sent before with another request. |
| 422 | no_eligible_model | No model or host the request’s settings allow, naming each and why. |
| 429 | rate_limited | Which limit was met, or that what it needs is set aside for requests already running. |
| 429 | spend_limit_reached | What the request usually costs, and what the month has left of the key’s spend limit, or of the workspace’s where one is set. |
| 500 | model_failed | “The model’s answer failed: ”, then the provider’s words. |
| 500 | internal_error | The gateway failed. |
| 503 | no_provider | Every provider and fallback failed before the first token, or none had room. |
| 503 | router_paused | The saved router is paused. |
| 503 | maintenance | The API is paused for maintenance. |
| 503 | unavailable | The server can’t take the request now; nothing was sent or charged. Send it again. |
The type differs between the two shapes, by status. The gateway never answers Anthropic’s overloaded_error.
| Status | OpenAI type | Anthropic type |
|---|---|---|
| 400, 405, 409, 422 | invalid_request_error | invalid_request_error |
| 401 | authentication_error | authentication_error |
| 402 | invalid_request_error | billing_error |
| 403 | permission_error | permission_error |
| 404 | invalid_request_error | not_found_error |
| 413 | invalid_request_error | request_too_large |
| 429 | rate_limit_error | rate_limit_error |
| 500, 503 | server_error | api_error |
Retries
The gateway retries providers by itself, as Models explains, so an error that reaches you has been tried already. Two headers say what to do next:
retry-after, on a 409, 429 or 503 where waiting helps: the seconds to wait before sending again.x-should-retry: false, where sending again can’t help: a month’s spend limit reached (429spend_limit_reached), anIdempotency-Keywhose request ran and was not kept (409), and a model that failed twice (500model_failed).
OpenAI’s and Anthropic’s SDKs send a 409, a 429 or a 5xx again by themselves, and they obey x-should-retry: false.
What an error costs
A refused request costs nothing, whether the gateway refused it before calling a provider or the provider refused it. A request that fails costs nothing either, except an empty answer a router moved past to another model, as Billing lists.
What to do
400
Read the message: it names the field or feature at fault, such as a tool or option the gateway doesn’t serve, and says what to send instead. A file or an image named by its id at a provider is served only on the workspace’s own key for that provider: on Conifer’s keys, send its contents (Models). On context_length_exceeded, shorten the conversation: Claude Code compacts it by itself on the Messages wire.
401
The key is missing, mistyped, expired or revoked. Check that the variable reached the process, and that the client sends it in a header the gateway reads (API keys).
402
The balance doesn’t cover the request. Add funds in the console, or lower the request’s output cap so its worst case is smaller (Billing).
403
The key may not do this: the request came from outside the key’s allowed addresses, or a saved router’s; the key only reads; or a restricted key doesn’t list the router or model. Use another key, or change this one’s access. A 403 that names a provider is about the workspace’s own key for it: the provider refused the key, or doesn’t serve the model to its account. Change the key on the Provider keys tab of API keys.
404
For model_not_found, check the id against GET /v1/models, the catalog or the console’s Models section. For router_not_found, check the router’s name, and that it is deployed. A router on the automatic pool also answers it where fewer than two of that pool’s models have a Conifer Intelligence score for the reasoning effort asked (Routing). For route_not_found, the route isn’t served.
409
The request with this Idempotency-Key is still running: wait the retry-after and send it again. With x-should-retry: false it already ran and its answer wasn’t kept; send a new request with a new key if you need one.
413
The body is over 32 MiB. Send less in one request.
422
For no_eligible_model, the message names each model and why it can’t serve: a cost cap below the worst case, a data policy no host meets, or no host at the model’s price. Loosen what it names. For idempotency_key_reused, give the new request a new key.
429
A rate_limited answer always carries retry-after: wait that long and send the request again. It has these causes:
- The key, or the saved router, has sent as many requests as its rate limit lets in for now.
retry-aftersays when the next one fits. - The key has as many requests in flight as its limit allows.
retry-afteris 1. - The workspace’s balance covers the request, but all of it is set aside for requests in flight.
retry-afteris 1. - The workspace’s requests hold as much request-body memory on the server as one workspace may.
retry-afteris 1. - The workspace has as many requests waiting for their hold on the balance as may wait.
retry-afteris 1. - The key has read as often as it may for now, on a route that reads.
retry-aftersays when. - The provider rate-limited the workspace’s own key for it.
retry-afteris the provider’s, or 30.
A spend_limit_reached answer with x-should-retry: false means the month can’t take the request: raise the key’s spend limit, or wait for the month to end in UTC. Where the workspace has a monthly limit of its own, the message says so. One with retry-after instead means the month’s room is set aside for requests in flight: send it again when one has ended.
5xx
A 503 with retry-after passes: send the request again after it. unavailable means the server couldn’t take the request, so nothing was sent to a provider and nothing was charged. A 500 model_failed with x-should-retry: false would fail again; change the request or the model. For anything else, send the request again, and write to support with its id if it keeps failing.