FaqHow do I troubleshoot AI Gateway errors?

How do I troubleshoot AI Gateway errors?

SymptomMeaningFix
401 Invalid gateway credentialThe key is missing, unknown, expired, or disabled.Check that LANGFUSE_GATEWAY_KEY is exported in the shell that runs the agent, and that the key is still active.
401 on an OpenAI route with only x-api-key setThe OpenAI routes read the key only from Authorization: Bearer.Send Authorization: Bearer <gateway key>. x-api-key works only on the Anthropic route.
401 Conflicting gateway credentials in the Authorization and x-api-key headersBoth headers were sent with different values. Typical case: Claude Code with a leftover ANTHROPIC_API_KEY next to ANTHROPIC_AUTH_TOKEN.Run unset ANTHROPIC_API_KEY, or give both the same value. For Pi, don't add a manual Authorization header next to apiKey.
401 with a provider-looking keyThe agent sends a stored provider credential instead of the gateway key (for example opencode auth or OPENAI_API_KEY).Remove the stored credential or environment variable.
403 Gateway access forbiddenThe key belongs to a user who can no longer call the gateway (for example, their role changed to Viewer), or the organization has no usable ingestion project.Check the key owner's organization role, and check that an ingestion project is set in Organization settings → AI Gateway → Setup. Role changes can take up to 60 seconds to reach existing keys.
403 model_not_allowedThe model is turned off on the provider credential that serves the request.Pick an enabled model from /models, or ask an admin to enable it.
404 No eligible provider connectionNo enabled provider credential serves this API format, for example a Claude Code call without an ANTHROPIC credential, or the model ID's prefix doesn't name a credential.Add or fix the credential in Organization settings → AI Gateway → Setup, or use a model ID from /models. See model IDs.
404 with an empty body on every callWrong path.Claude Code and Pi use …/anthropic. OpenCode uses …/anthropic/v1. Everything on OpenAI uses …/openai/v1. Chat Completions is served at …/openai/v1/chat/completions. See your coding agent guide.
404 not_found_error / model_not_foundThe provider doesn't know the model, or your provider account has no access to it. On the Anthropic route, the gateway's own 404 errors also use the type not_found_error.Read the error message: No eligible provider connection comes from the gateway (see the row above). Otherwise, check the ID with /models (see list models). A provider 404 is still recorded as ERROR.
400 Invalid gateway modelThe model ID has no credential prefix and doesn't start with gpt-, codex-, claude-, or ft:.Use the <credential>:<model> ID from /models. See model IDs.
400 Unsupported parameter: 'reasoning.effort' (Codex)A global model_reasoning_effort was sent to a non-reasoning model.Remove it, or use a reasoning model.
400 Tool 'tool_search' is not supported with <model> (Codex)The small model rejects Codex's tools.Use a larger model.
413 Request body exceeds gateway limitThe request is larger than 16 MiB (large contexts or screenshots).Compact the conversation or start a new session.
415 Unsupported request Content-EncodingThe request body is compressed (a Content-Encoding header other than identity). The gateway only accepts uncompressed bodies.Turn off request compression in the client.
429 Langfuse AI Gateway rate limit exceededYour organization hit its per-minute request or request-size limit on Langfuse Cloud.Wait for the Retry-After time. Most clients retry on their own. If you hit it regularly, upgrade your plan or contact support.
502 Upstream request failedThe gateway couldn't reach the provider, or the provider connection failed mid-request.Retry. The call is recorded as ERROR. Report it with the request ID if it persists.
504 Upstream deadline exceeded, or a stream that stopsThe call hit the 600-second overall limit, or the provider sent nothing for 120 seconds.Known beta limits. Split very long generations. The call is recorded as ERROR.
503 Gateway temporarily unavailableThe gateway is at capacity or briefly can't reach Langfuse.Retry with backoff. Report it with the request ID if it persists.
Client crashes on the last chunk of a streamed Chat Completions responseThe gateway requests streaming usage upstream, so the stream ends with a usage chunk whose choices array is empty.Skip chunks without choices. See streaming usage.
No session on Pi Anthropic tracesPi doesn't send its session ID to Anthropic by default.Add "compat": { "sendSessionAffinityHeaders": true }. See Pi.
Traces in default despite langfuse-environmentThe value doesn't match the environment format, so it fell back to default.Use lowercase letters, numbers, - and _, at most 40 characters, not starting with langfuse.
Six ERROR generations over about 70 seconds (OpenCode)OpenCode retries OpenAI 404 errors with backoff. Anthropic 404 errors are not retried.Fix the model ID. The duplicates are client retries.
Two ERROR generations per failed prompt (Claude Code)Claude Code retries once without streaming.Expected.
All your sessions merged into oneA static langfuse-session-id in the config.Remove it, or set it from a per-run environment variable.
Every Claude Code call is still its own trace with turn grouping enabledClaude Code only sends traceparent when tracing is active.Set all of CLAUDE_CODE_ENABLE_TELEMETRY, CLAUDE_CODE_ENHANCED_TELEMETRY_BETA, CLAUDE_CODE_PROPAGATE_TRACEPARENT, and a real OTEL_TRACES_EXPORTER (not none). See turn grouping.

Was this page helpful?

Last updated on