8 minutes

When a request fails

Read an error response, tell a key problem from a credit problem from a rate limit, and fix each one.

Your shop assistant has been answering questions for a week. This morning, customers see a blank reply. Your server logs show the request went out and something came back, but not an answer.

When a request fails, the response returns an error object with a numeric code and a message instead of choices. The HTTP status matches error.code. Three codes cover most failures you’ll see:

Response · HTTP 402 · Illustrative example
{
  "error": {
    "code": 402,
    "message": "Insufficient credits. Add more using https://openrouter.ai/settings/credits"
  }
}
  • 401 means the key is the problem: missing, mistyped, disabled, or deleted. Check the Authorization header and the key’s status on the keys page.
  • 402 means the account or key has run out of credits, or the key hit its spending limit. Add credits on the credits page or raise the key’s limit. Exception: if your balance is positive and metadata.reason is in_flight_budget_exhausted, too many paid requests are running concurrently. Wait for the Retry-After duration and retry (see Rate limits).
  • 429 means you’re sending requests faster than allowed. It can come from OpenRouter or from the provider serving the model. Wait and retry, with a longer wait each time.
OpenRouter returns 401 and 402. A 429 can come from OpenRouter or from the provider.

Check your understanding

Question 1 of 2

The response says "code": 402 with the message Insufficient credits. Customers are still asking questions. What do you do first?

Read the message too. It often says exactly which of these happened and what to do. The errors reference lists every code.

Apply it

Everything works on your laptop. You deploy to your server, and the first request returns a 401. What’s the most likely cause?

Takeaway

Read the code before you change anything. 401 is the key, 402 is credits, 429 is speed. Retrying helps a 429, or a 402 that says in_flight_budget_exhausted, and only with a wait between tries.