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

StatusTypeRetry?Description
400invalid_request_errorNoMalformed request.
401authentication_errorNoMissing or invalid API key.
403permission_errorNoKey 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.
404not_found_errorNoModel or resource does not exist.
409conflict_errorNoConflicting state (e.g. duplicate key name).
413request_too_largeNoInput exceeds the model's context window.
422invalid_request_errorNoValid shape, wrong semantics.
429rate_limit_errorYes, with backoffHonor Retry-After.
499client_closed_requestNoClient disconnected before response.
500internal_server_errorYesAnyRouter internal issue.
502upstream_errorYesUpstream provider returned a 5xx.
502upstream_error (code: empty_stream)YesProvider returned an empty stream. See Empty stream.
503service_unavailableYesNo healthy upstream available.
504upstream_timeoutYesUpstream 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

CodeMeaning and fix
authentication_requiredRoute needs a signed-in session or bearer key. Add Authorization: Bearer.
missing_api_keyAuthorization header missing. Send Authorization: Bearer sk-ar-your-key.
invalid_api_keyKey invalid, revoked or inactive. Create a new one in the dashboard.
insufficient_balanceOut 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_foundSlug not in the catalog. Use a full provider/model id from the catalog.
model_not_yet_availableModel is listed as Coming soon and cannot serve yet (404). Use a live model.
context_length_exceededInput too long. Shorten the prompt or pick a larger-context model.
rate_limit_exceeded, ip_rate_limit_exceededPer-key or per-IP limit. Back off and honor Retry-After.
upstream_unavailableAll upstreams for the model are down. Retry or route to another model.
content_policyAn 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