Trace OpenRouter failures through request validation, account controls, routing and upstream generation. Inspect the response body even when the HTTP request appears successful.

Error format at OpenRouter

OpenRouter’s error envelope contains code, message and optional metadata. A generation can fail after response headers have already been sent. Official documentation.

Separate transport success from a completed model result. Preserve the HTTP status and inspect the body for an error before reading completion choices. For a stream, retain its final event and completion state. Partial text should not be accepted as a finished patch, structured record or complete document answer without an explicit application rule.

Log the request stage and safe routing metadata. A problem can originate before routing, from an account control, or during upstream generation. One generic error label hides those distinctions and often leads to repeated attempts that cannot repair the underlying condition.

Error code table

Typed categoryShort literal termWhat it identifiesNext investigation
authenticationAuthenticationCredential failureKey value, revocation and executing environment.
permission_deniedPermission deniedAccess or guardrail boundaryWorkspace/key permissions and request rules.
payment_requiredPayment requiredCredit conditionAccount and key allowance.
context_length_exceededContext length exceededRequest capacityAssembled input and output allowance.
rate_limit_exceededRate limit exceededTemporary rate boundaryResponse timing and traffic producers.

These are normalized categories from the error reference, with editorial investigation guidance. Preserve the actual response’s native code and normalized type where supplied; the wire location differs by request interface.

Avoid matching only an entire literal message. A stable typed category is more useful for programmatic recovery, while the redacted message remains valuable to the person investigating. Keep a default path for an unfamiliar type that stops safely and retains evidence instead of retrying forever.

Authentication errors

Check the secret used by the failing process and the OpenRouter base URL. A key for a direct upstream provider is not automatically the credential expected by the routing service. If BYOK is enabled, keep its upstream credential configuration separate from the OpenRouter key used to authenticate the application.

Inspect whether the credential was revoked, replaced or moved outside the worker’s active configuration. Use a presence check that does not print its value, then verify a small request from the deployed launch path. A passing call from a different terminal does not prove the service loads the same secret.

Follow the key guide for rotation and keep an inventory of consumers before retiring a shared credential.

Rate and quota errors

Use the provider’s credit view for an account or key-allowance failure. Do not remove a spending boundary without understanding why it was configured. A local retry policy should expose that condition to the responsible operator and preserve unfinished work.

For temporary rate pressure, honor available retry timing and coordinate producers. Keep retry ownership in one layer and retain the task’s final deadline. A user-facing request should not continue through a long hidden retry chain after the result is no longer useful.

Use OpenRouter limit scopes to separate a free-route cap, account credit and upstream availability. Each condition deserves an explicit application state.

Request validation errors

Check JSON types, required fields and the request interface before inspecting model output. If the application uses a compatible client, keep its optional fields in a small reproducible payload. Remove unrelated features, establish a passing call and restore requirements one at a time.

The require_parameters routing option excludes endpoints that do not support all supplied parameters. Official documentation.

Use that behavior when a field is essential to the application contract. If no route remains eligible, the correct action is to review the requirement and candidate set, not silently ignore the field. Keep the difference between a mandatory parameter and a preference visible in configuration.

Validate any generated structure again in application code. A request option can guide generation without replacing checks on field meaning, allowed values and required evidence. Treat a malformed response as an output-validation result, not a successful task merely because the API accepted the request.

Model and context errors

Inspect the exact slug and current status. A moving alias may resolve differently after a release, while a concrete model can be retired or temporarily lack an eligible endpoint. Preserve requested and returned identities so an observed change can be traced to the route actually used.

For a capacity failure, inspect the assembled input: instructions, history, retrieved material and tool definitions. Reduce irrelevant material deliberately, preserve necessary evidence and keep an output allowance appropriate to the response contract. Do not solve an input error by dropping information that makes the answer verifiable.

Read catalog identity and version guidance before selecting a replacement. Use the same fixture to compare the new candidate’s accepted result.

Server errors and status

Inspect whether the error belongs to OpenRouter routing or an upstream serving path. Preserve generation identity when available and the bounded attempt history. The reference’s status widget is useful context, but a broad status summary cannot replace the evidence from the specific failed request.

If a fallback returns a result, record which model handled it and validate the output before calling the task recovered. Keep downstream side effects idempotent so retries or route changes do not repeat an action that already succeeded before the model response failed.

After a persistent problem clears, resume traffic gradually and reconcile queued tasks by identity and deadline. An incident is not resolved merely because fresh requests work while old queued tasks remain duplicated, expired or silently lost.

Use the AI API cost calculator to turn the model and workload you are considering into an estimate.

Last verified · Source ↗

Frequently asked questions

Can HTTP success contain a generation error?
Yes. Inspect the body and final streaming state before accepting a completion.
Where is the normalized type on Chat Completions provider errors?
The error reference places it in error.metadata.error_type for the documented upstream failure path.
Should I use an upstream provider key as the OpenRouter credential?
No. Keep OpenRouter authentication separate from any configured BYOK provider credential.
Why require parameter support?
It prevents an essential request field from being silently ignored by an incompatible eligible endpoint.
What makes a fallback a successful recovery?
The resolved candidate must still satisfy the application’s output and operating requirements.
What should an unfamiliar error type do?
Stop within a bounded policy and preserve safe evidence for investigation.

Sources

Last verified · Source ↗