Browse documentation

Errors & Rate Limits

Every nRouter error returns one JSON shape with a machine-readable code: the status codes, the error codes, the rate-limit headers, and the retry rules.

Every failed nRouter API request returns a structured JSON error envelope containing a machine-readable code and descriptive message. Branch deterministically on code rather than parsing message text across status codes, rate-limit headers (x-nr-limit-source, Retry-After), and failover rules.

{ "error": { "message": "Invalid API key provided.", "type": "gateway_error", "code": "invalid_api_key" } }

Status & error codes

Status / CodeMeaning
400 · invalid_requestMalformed payload, unknown nrouter_* key, or nrouter_cost_band sent on a Direct model, with an invalid band, or under quality or balanced ($0 spent).
400 · cost_band_unsatisfiableActive nrouter_cost_band ceiling on a cost-mode nrouter/auto call left zero eligible models ($0 spent; never escalates).
400 · pot_route_feature_unsupportedPromo- or hack-funded request asked for an unsupported feature (nrouter_web_search, n > 1, or tool-billed feature) with no prepaid credits to overflow into ($0 spent).
400 · byok_envelope_invalidBrowser-sealed customer provider key envelope failed validation on save (byok-env-v1 schema, ciphertext, or target host mismatch).
400 · fallback_not_allowed / guardrail_not_foundUnpermitted or out-of-band fallback target, or unknown guardrail ($0 spent).
400 · guardrail_blockedBlocked in-path before any provider call (x-nr-guardrails: blocked, $0 spent).
400 · input_too_large / max_output_tokens_too_large / image_input_unsupportedPrompt, output cap, or image input exceeds model limits.
401 · invalid_api_keyMissing, expired, or revoked key (x-nr-auth-reason states why).
401 · byok_credential_rejectedSaved provider key rejected by the upstream provider (401/403) when credit fallback is disabled (x-nr-funding-source: byok; BYOK).
402 · insufficient_creditsPrepaid credit balance cannot cover the request hold (x-nr-limit-source: budget, Billing).
402 · budget_exceededSpending budget ceiling reached in Block mode across org, team, user, or key scope (x-nr-limit-source: budget, no Retry-After; Budget Controls).
402 · insufficient_promo_credit / insufficient_hack_creditNeither the promotional (promo) / hackathon (hack) pot nor prepaid credits can cover the hold ($0 spent).
402 · plan_allowance_exhausted / plan_requiredMonthly subscription usage allowance exhausted (x-nr-limit-source: plan_allowance_exhausted, x-nr-allowance-reset, no Retry-After) or legacy subscription allowance paused pending payment (x-nr-limit-source: plan_required).
402 · byok_plan_requiredActive Bring your own keys subscription required to use saved provider keys when credit fallback is disabled (x-nr-funding-source: byok; BYOK).
403 · key_blocked / org_web_search_disabledVirtual key is blocked or disabled (x-nr-auth-reason: key_blocked), or nrouter_web_search was sent while organization web search is disabled (x-nr-auth-reason: org_web_search_disabled).
403 · key_model_not_allowed / model_denied_by_*Model, endpoint, IP policy, or safety hold refusal (x-nr-auth-reason names key_model_not_allowed, model_denied_by_{org,team,key}, key_route_not_allowed, key_ip_not_allowed, key_network_policy_invalid, or {account,team,organization}_hold).
404 · model_not_foundRequested catalog model ID is unknown (pass a concrete catalog model ID or nrouter/auto).
409 · byok_credential_unavailable / byok_version_conflictSaved provider key is paused, disabled, revoked, or unavailable without credit fallback (x-nr-funding-source: byok), or a concurrent key rotation/edit conflicted with the expected version (BYOK).
429 · rate_limit_exceededRPM/TPM/RPS/RPD or allowance sub-window crossed (Retry-After + x-nr-limit-source), or a Throttle-mode budget fired (x-nr-limit-source: budget, no Retry-After).
429 · pot_spend_limit_exceededPromotional or hackathon pot rolling UTC spend window reached with no prepaid credits to overflow into (x-nr-limit-source: pot_window).
429 · byok_fair_use_exceededMonthly 50M BYOK token fair-use allowance reached (x-nr-limit-source: byok_fair_use, x-nr-funding-source: byok; wait Retry-After until next UTC month; never falls back to credits).
503 · rate_limit_unavailable / platform_maintenance / service_unavailableRate-limiter store temporarily unavailable (rate_limit_unavailable), emergency platform maintenance gate active (x-nr-auth-reason: platform_maintenance), or upstream/dependency unavailable (retry as-is if x-nr-guardrails: unavailable).

Pre-auth Edge WAF ceilings & error codes

Every request passes through the pre-auth Edge WAF before key lookup, database access, or provider egress ($0 spent; x-nr-request-id and x-nr-latency-ms are still stamped):

  • Body size ceilings: 8 MiB on JSON inference routes, 25 MiB on multipart audio upload routes (/v1/audio/transcriptions, /v1/audio/translations), and 64 KiB on control-plane (/api/*) and unmapped paths.
  • URI & header ceilings: 4,096 B (4 KiB) request URI target; at most 64 headers, 8 KiB per header value, and 32 KiB total header bytes.
  • JSON complexity ceilings: maximum nesting depth 32, 16,384 entries per array or object container, and 200,000 total JSON elements.
Status / WAF CodeCondition
400 · waf_malformed_pathNon-UTF-8 target, control characters, backslash, dot-segment traversal (..), or forbidden percent-encodings.
400 · waf_malformed_headersControl characters, non-visible ASCII in header values, or duplicate credential headers (Authorization / x-api-key).
400 · waf_ambiguous_lengthDuplicate or comma-listed Content-Length, Content-Length combined with Transfer-Encoding, or non-chunked transfer coding.
400 · waf_body_too_complexMalformed JSON, nesting depth above 32, container entries above 16,384, or total elements above 200,000.
405 · waf_method_not_allowedHTTP method outside the allowed set (Allow header lists accepted methods).
408 · waf_body_read_timeoutRequest body did not finish arriving within the gateway upload read timeout budget.
413 · waf_body_too_largeRequest body exceeds the route ceiling (8 MiB JSON, 25 MiB audio upload, or 64 KiB control-plane/unmapped).
414 · waf_uri_too_longRequest URI path and query exceed 4,096 B.
415 · waf_unsupported_media_typeMissing, repeated, or disallowed Content-Type, multipart outside audio upload routes, or invalid multipart boundary.
431 · waf_headers_too_largeRequest exceeds 64 headers, 8 KiB single header value, or 32 KiB total header bytes.

Rate limits & failover

  • Rate limits: Enforced per key (RPM and TPM), team, and organization. Fallback chains consume one credit hold and one rate-limit slot.
  • Failover: Triggers only on configured fallback chains for 429, 503, Anthropic 529, 401/404 from a misconfigured deployment, connect failure, or first-byte timeout (max 3 provider calls per request).

Frequently asked questions

Should I retry a failed request?

Retry 429 after Retry-After and 503 (x-nr-guardrails: unavailable) as-is; never retry 400 errors without fixing the request.

Does nRouter retry automatically?

Yes, when a fallback chain is configured, up to 3 total provider calls on upstream 429, 503, Anthropic 529, or connect/first-byte failures.

What is the difference between a 402 for credits and one for a budget?

insufficient_credits means your credit balance is low; budget_exceeded means a spend cap refused the call (x-nr-limit-source names the ceiling).

A guardrail blocked my request. Was I charged?

No — guardrail_blocked (400) refuses before any provider call and spends $0.

Should my code branch on the error message?

No — always branch on the stable error.code field.

Chat Completions · Authentication · Troubleshooting · Per-Request Options · Support

Was this page helpful?
Errors & Rate Limits | nRouter