Skip to main content

AI Gateway Error Codes

This page lists every answer a client of an AI listener can get that is not a normal model response, and which component sent it. For the causes and fixes, see Troubleshooting.

Who answers​

A request passes through these components on the edge, in order. Each can answer the request itself:

EmitterWhen it runsBody shape
Envoy (generated routes)Every request: host selection, the model lists, the catch-all routes, body limitsOpenAI error shape, or empty
Authorization, key phaseGateways with Require key onOpenAI error shape
ExtprocEvery LLM request: parses the body, picks the model, translates to the providerThe extproc's own
Authorization, model phaseKeyed gateways, and every gateway whose sensitive-data policy reads the request bodyOpenAI error shape
Authorization, MCP phasePOST /mcp on a gateway that serves MCP (always keyed)JSON-RPC error
MCP result scan/mcp answers on a gateway whose policy scans tool resultsJSON-RPC error inside a 200
ProviderThe request reached the providerThe provider's own, passed through

The error body​

The authorization answers in OpenAI's error shape, so OpenAI and Anthropic SDKs surface error.code and error.message:

{
"error": {
"message": "consumer team-a used its quota of 1000 requests per day; it resets at 2026-12-06T00:00:00Z",
"type": "rate_limit_error",
"code": "quota_exceeded"
}
}

type follows the HTTP status:

Statustype
401authentication_error
404invalid_request_error
429rate_limit_error
503server_error
any other (400, 403, 413)permission_error

Every refusal from the authorization carries content-type: application/json. Codes that tell the client when to try again add a retry-after header, in seconds.

Authorization: key phase​

This phase runs before the extproc, only on gateways with Require key on. Clients send the consumer key as Authorization: Bearer <key> (OpenAI SDKs), x-api-key (Anthropic SDKs) or api-key (Azure OpenAI SDKs).

StatuscodeMessage (verbatim, with values filled in)Causeretry-after
401invalid_api_keya valid elchi virtual key is required for gateway <gw>No key, an unknown key, a revoked key, or a disabled consumer—
403gateway_not_allowedconsumer <c> may not use gateway <gw>The consumer has a gateway allowlist that does not name this gateway—
403files_not_allowedthe Files API is not available on gateway <gw>: files belong to the provider's account and would be shared by every consumerA path containing /v1/files on a keyed gateway—
429quota_exceededconsumer <c> used its quota of <limit>; it resets at <RFC3339 UTC>A request or token quota is used up (see the quota table below)seconds until the reset
503gateway_not_readythis edge's AI gateway configuration does not have gateway "<gw>" as one that requires a key yet; retry shortlyEnvoy already routes to a keyed gateway that this edge's configuration does not have as keyed. The edge's set lags behind Envoy: a new gateway, a push not yet applied, or a push the edge refused.5
503service_unavailablethe AI gateway has no configuration yetThe gateway on this edge has applied no configuration—
404not_foundthis route is not served by an AI gatewayThe request matched a route that names no gateway (an operator's own route on an AI HCM)—

<limit> in the quota message reads, for example: 60 requests per minute, 1000 requests per day, 2000000 tokens per day, 50000000 tokens per month, 25.00 per day, 500.00 per month. The request and token quotas are checked here. A request is counted in the model phase, so a request the extproc or the model phase refuses does not use the quota.

Authorization: model phase​

This phase runs after the extproc has named the model (x-ai-eg-model). It runs on keyed gateways, and on gateways whose sensitive-data policy reads the request body.

StatuscodeMessageCauseretry-after
401invalid_api_keya valid elchi virtual key is required for gateway <gw>The key phase did not admit a consumer—
403model_not_allowedconsumer <c> may not use model <m> (provider <p>)The consumer's model or provider allowlist excludes it. For a model several providers serve, every provider that may serve it must be allowed.—
403model_not_pricedconsumer <c> has a cost quota and model <m> has no price at provider <p> (asked for <name>)The consumer has a cost quota (costPerDay / costPerMonth) and the price table has no price for this model at this provider—
403sensitive_datathe request carries sensitive data the gateway <gw> does not allow: <types>; remove it and retryThe policy blocks a type found in the body. The message names only the blocking types.—
403sensitive_scan_overflowthe request carries more values that look like sensitive data than gateway <gw> checks; it cannot be checked for the types the gateway blocksThe scan hit its candidate bound, and the policy blocks a type—
413sensitive_scan_too_largethe request is larger than gateway <gw> checks for sensitive data; send a smaller request (its administrator may raise the policy's maxScanBytes)The body is larger than the scan reads, and the policy blocks a type—
503sensitive_scan_busythe AI gateway is busy checking other requests for sensitive data; retry shortlyNo scan slot was free before Envoy's 2 s check timeout1
503sensitive_scan_incompletethe request could not be checked for sensitive data in time; retry shortlyThe scan started but did not finish in time. What was not read is never let through.1
429quota_exceededas in the key phaseThe request would cross a quotaseconds until the reset
503gateway_not_readythis edge's AI gateway configuration does not serve model "<m>" on gateway <gw> yet; retry shortlyEnvoy routes the model, but this edge's set does not have it yet5
403unknown_phasethe authorization phase "<p>" is unknownAn Envoy filter was configured with a phase the gateway does not know. This does not happen with generated configuration.—

Order inside the phase: the allowlist and price checks run first, then the sensitive-data scan, then the quota. A request refused by the scan uses no quota. A policy that only flags a type lets the request through and records it.

Envoy: generated routes​

StatusBody codeMessageCause
404gateway_not_foundno AI gateway serves this host on listener <listener>The Host matches no gateway bound to this listener, and the listener has no default gateway
404model_not_foundthe model is not served by gateway <gw>; GET /v1/models lists the ones it servesThe model in the body is not in the gateway's model list
404(empty body)—The request reached the router without the extproc naming its model (the gateway's unrouted route)
413(Envoy's)—The request body is larger than 50 MiB, the most a gateway buffers
308——A plain-HTTP port in redirect mode. Every request is redirected to the listener's HTTPS port, with method and body kept.

GET /v1/models and GET /anthropic/v1/models are answered by Envoy from the gateway's model list (200). On a keyed gateway they still need a valid key: without one they get the key phase's 401.

Extproc​

The Agent Router extproc answers these itself. Its bodies are the engine's own, not elchi's shape.

StatusCause
400The request body is not valid JSON
422unsupported API schema: the endpoint cannot be translated to the model's provider type. Example: /v1/chat/completions to a native anthropic provider. See the endpoint × provider matrix in Calling the Gateway.
500An MCP call: call to <server> failed …. The server was unreachable, or it answered an error (its body is relayed as text/plain).
503An MCP answer or SSE stream took longer than the gateway's MCP write timeout (default 15 minutes)

Requests that arrive while the gateway or its extproc restarts fail (measured as 500). The AI filters are fail-closed, so no request goes out without its checks.

Provider answers​

What a provider answers is passed to the client. The gateway records each answer per minute in elchi_ai_gateway_upstream with a class: ok, auth_error (401/403), rate_limited (429), client_error, server_error (5xx), unreachable, timeout, reset. A 401 or 429 that the provider sent is not one of the codes above. It has no elchi code, and the provider status on the Providers tab shows it.

For a model several providers serve, Envoy retries the gateway's failover failures on the other providers before the client sees anything. See Gateways and Models.

JSON-RPC errors on /mcp​

On a gateway's /mcp endpoint, the authorization answers in JSON-RPC so MCP clients can read it. Elchi's code is inside error.data:

{
"jsonrpc": "2.0",
"id": 7,
"error": {
"code": -32000,
"message": "consumer team-a may not call tool github__delete_repo on gateway dev",
"data": { "code": "tool_not_allowed", "type": "permission_error", "status": 403 }
}
}
  • id is the id of the refused message, or null when no id was read.
  • error.code is always -32000.
  • For the MCP phase, the HTTP status is data.status. For the result scan, the HTTP status is 200 and the error replaces the blocked message.

MCP phase (requests the client sends)​

HTTP / data.statusdata.codeMessageCause
401invalid_api_keya valid elchi virtual key is required for gateway <gw>No valid consumer key
400invalid_requestthe request is not a JSON-RPC messageNot JSON-RPC, or a body that two parsers could read differently (a key differing only in case, a duplicate key, data after the message)
403tool_not_allowedconsumer <c> may not call tool <server>__<tool> on gateway <gw>A tools/call for a tool the consumer was not granted
413mcp_request_too_largethe MCP request is larger than gateway <gw> readsEnvoy passed only part of the body (MCP requests are read up to 4 MiB)
429quota_exceededconsumer <c> used its quota of <n> MCP calls per minute (or per day) ; it resets at …An MCP call quota is used up. A batch counts each tools/call it holds.
403 / 413 / 503sensitive_data, sensitive_scan_overflow, sensitive_scan_too_large, sensitive_scan_busy, sensitive_scan_incompleteas in the model phaseThe policy scans MCP arguments (sensitive.mcp.arguments)
503gateway_not_readythis edge's AI gateway configuration does not serve MCP on gateway <gw> yet; retry shortlyThe edge's set has no MCP for this gateway yet
503gateway_not_readythe gateway <gw> did not pass the MCP request's body to its check; retry shortlyA POST reached the check without its body

initialize, tools/list and other methods are not counted against quotas. The extproc lists only the tools the consumer was granted.

MCP result scan (answers from the server)​

These run only where the gateway's policy scans tool results (sensitive.mcp.results):

data.statusdata.codeWhen
403sensitive_dataThe answer carries a type the policy blocks. The answer is replaced by this error. A blocked request or notification from the server is dropped. A blocked server request answers the client's call with this error.
403sensitive_scan_unreadableThe policy blocks, and the answer cannot be read: content-encoded, or a content type that is not JSON, SSE or text
413sensitive_scan_too_largeThe policy blocks, and the answer (or one SSE event) is larger than the scan reads
403sensitive_scan_overflowThe policy blocks, and the scan hit its candidate bound

The message of the unreadable and too-large refusals is: the tool's result could not be checked for sensitive data by gateway <gw> (it blocks some types); ask for a smaller result. Where the policy only flags, such answers pass unscanned.

Where refusals are recorded​

RecordWhat
Decision log, ClickHouse elchi_ai_gateway_decisionsEvery denial and every flagged request: gateway, consumer, phase (key, model, mcp, mcp_result), status, code, and the sensitive types with counts (never values). A denial that names no consumer is recorded at 5 per second per gateway and code (burst 20). The rest are counted in the metric elchi_ai_gateway_decision_rows_suppressed_total on 127.0.0.1:9002/metrics.
Journal of elchi-ai-gatewayA known consumer's denial is logged at info as request denied with consumer, gateway, phase, status, code and message, at most once a minute per consumer and code. The line carries suppressed = how many were not logged.
UIAI Gateway → Sensitive data shows the sensitive-data decisions. AI Gateway → Usage shows denials per window.