Errors
HTTP status codes, the error envelope, error codes and retry rules for AnyRouter API errors.
Every error uses one envelope. Use the status to decide whether to retry and code to branch on the failure.
{
"error": {
"message": "Human-readable message",
"code": "machine_code",
"metadata": { "type": "error_category" }
}
}Status codes
| Status | Type | Retry? | Description |
|---|---|---|---|
400 | invalid_request_error | No | Malformed request. |
401 | authentication_error | No | Missing or invalid API key. |
403 | permission_error | No | Key lacks the scope; or (code: free_tier_requires_subscription) a Free-plan account called a free model; or (code: ip_not_allowed) the client IP is not on the workspace IP allowlist. |
404 | not_found_error | No | Model or resource does not exist. |
409 | conflict_error | No | Conflicting state (e.g. duplicate key name). |
413 | request_too_large | No | Input exceeds the model's context window. |
422 | invalid_request_error | No | Valid shape, wrong semantics. |
429 | rate_limit_error | Yes, with backoff | Honor Retry-After. |
499 | client_closed_request | No | Client disconnected before response. |
500 | internal_server_error | Yes | AnyRouter internal issue. |
502 | upstream_error | Yes | Upstream provider returned a 5xx. |
502 | upstream_error (code: empty_stream) | Yes | Provider returned an empty stream. See Empty stream. |
503 | service_unavailable | Yes | No healthy upstream available. |
504 | upstream_timeout | Yes | Upstream provider timed out. |
Do not retry 4xx other than 429; it fails the same way and burns rate-limit budget. For retryable errors use exponential backoff with jitter and honor Retry-After.
Empty stream
A 502 with code: empty_stream means the provider ended the response with no content (/chat/completions, /responses, /messages). AnyRouter has already tried other providers for the model where available, so your request is not the cause. Re-send with backoff; if one model keeps failing, try another.
Error codes
| Code | Meaning and fix |
|---|---|
authentication_required | Route needs a signed-in session or bearer key. Add Authorization: Bearer. |
missing_api_key | Authorization header missing. Send Authorization: Bearer sk-ar-your-key. |
invalid_api_key | Key invalid, revoked or inactive. Create a new one in the dashboard. |
insufficient_balance | Out of credits for a paid model and any free requests are used. Add credits, add your own provider key, subscribe, or donate a key to the shared Pool; error.actions lists these. Free-tier models never use this code. |
model_not_allowed (403) | The key's allow-list excludes the model, or it is disabled for your account. Edit the allow-list in Keys or pick another provider/model from the catalog. |
permission_error (403) | Key lacks the scope (e.g. a management key on /chat/completions, or an inference key on /keys). Mint a key with the right group. |
zdr_required (403) | Zero data retention (account, key, preset or request) excludes every upstream for this model. Turn ZDR off in Privacy settings or pick a model with a ZDR route. If the message says your privacy settings could not be read, retry shortly. |
free_tier_requires_subscription (403) | Free plan called anyrouter/free or a :free model after the 5-request trial. error.actions offers the three ways to unlock them in order: top_up ($5), subscribe (Go or higher), donate_key (one working key to the shared Pool gives Go free), then add_byok. Decision models and paid models with credits still work on Free. |
model_not_found | Slug not in the catalog. Use a full provider/model id from the catalog. |
model_not_yet_available | Model is listed as Coming soon and cannot serve yet (404). Use a live model. |
context_length_exceeded | Input too long. Shorten the prompt or pick a larger-context model. |
rate_limit_exceeded, ip_rate_limit_exceeded | Per-key or per-IP limit. Back off and honor Retry-After. |
upstream_unavailable | All upstreams for the model are down. Retry or route to another model. |
content_policy | An upstream refused under a content-policy filter. Adjust the prompt. |
Debugging
Every inference response carries X-Request-ID (same value as X-AnyRouter-Trace-Id). Include it in bug reports.
curl -i https://anyrouter.dev/api/v1/chat/completions \
-H "Authorization: Bearer sk-ar-your-key" \
-H "Content-Type: application/json" \
-d '{"model": "openai/gpt-5.4-mini", "messages": [{"role": "user", "content": "hi"}]}'
# x-request-id: req_01HQ...Send a trace object in the body of Chat Completions or Responses requests and its trace_id is carried through AnyRouter's step logs and AI Gateway metadata, so you can line up your traces with routing.
AnyRouter routes requests to third-party models. Models and outputs are provided as is, with no warranty; you use them at your own risk. Disclaimer