Skip to content
Billfuse

OpenRouter 402: "This request requires more credits, or fewer max_tokens"

Last updated

If OpenRouter answers with error 402 and “This request requires more credits, or fewer max_tokens. You requested up to … tokens, but can only afford …”, the message itself says why: the request could cost more than you can afford. OpenRouter says a 402 without a Retry-After header isn't one to wait and retry, so sending the same request again won't help. Make it smaller, add credits, or raise your API key's limit. error.metadata.limit_source tells you which.

What this page says about OpenRouter was checked against OpenRouter's docs on November 14, 2026. The error bodies are from developers' reports, with dates. Where the advice is ours, the page says so.

The short version

  1. Read error.metadata.limit_source in the response.
  2. If it says openrouter_credits, set a lower max_tokens or send a shorter prompt, or add credits on OpenRouter's Credits page.
  3. If it says openrouter_key_limit, the API key's own limit is the problem: raise it on the Keys page, or, if the limit resets, wait for the reset.

Why it can happen while you still have credits

OpenRouter's docs don't explain this message, and don't say how the two numbers in it are counted. We searched the full docs on November 14, 2026: “requires more credits” and “can only afford” appear 0 times.

What the docs do say, in the Limits page's section on the in-flight spending budget: OpenRouter charges a request when it finishes, so it estimates each paid request's token cost up front and holds it while the request runs. The estimate is your input tokens plus the output tokens max_tokens allows, up to a fixed cap per request, at that endpoint's prices. Per-request fees, plugin charges and image pricing aren't part of it.

Source: OpenRouter, Limits

Which limit did you hit?

We found the message with two values of limit_source. The link at the end of the message differs too.

Your credits: openrouter_credits

Error 402, as reported
{
  "message": "This request requires more credits, or fewer max_tokens. You requested up to 32000 tokens, but can only afford 15989. To increase, visit https://openrouter.ai/settings/credits and upgrade to a paid account",
  "code": 402,
  "metadata": {
    "limit_source": "openrouter_credits",
    "remedy_hint": "Add credits at https://openrouter.ai/settings/credits, or lower max_tokens / prompt size to fit your remaining balance.",
    "provider_name": null,
    "previous_errors": […]
  }
}

From a GitHub issue dated October 18, 2026. We formatted it and shortened previous_errors, which the report had already cut. A report from October 3, 2026 has the same limit_source and ends “and add more credits”.

OpenRouter says openrouter_credits means your balance can't cover the request, or the single request is too expensive for your in-flight budget. The remedy_hint in the body says the same thing as a fix: add credits, or lower max_tokens or the prompt size.

The API key's limit: openrouter_key_limit

Error 402, as reported
{
  "message": "This request requires more credits, or fewer max_tokens. You requested up to 917141 tokens, but can only afford 374710. To increase, visit https://openrouter.ai/workspaces/default/keys/... and adjust the key's daily limit",
  "code": 402,
  "metadata": {
    "limit_source": "openrouter_key_limit",
    "remedy_hint": "Raise or remove this API key's usage limit at https://openrouter.ai/settings/keys, or use a key without a limit.",
    "provider_name": null,
    "previous_errors": […]
  }
}

From a comment on a GitHub issue dated November 4, 2026. We formatted it, shortened previous_errors and cut the key's ID from the link.

OpenRouter says openrouter_key_limit means the API key's credit limit is exhausted. A key can have its own limit, and that limit can reset daily, weekly or monthly. The message offers “fewer max_tokens”; the remedy_hint says to raise or remove the key's limit, or use a key without one.

Sources: OpenRouter, Limits, Errors and Debugging, Capping Shared Agent Keys

Fix it

Ask for fewer tokens

Our advice: set max_tokens on the request to the longest answer you actually need. OpenRouter says it caps how many tokens the model can generate, and the estimate above counts the output tokens it allows. A shorter prompt, such as less chat history, means fewer input tokens in the estimate.

OpenRouter also accepts max_completion_tokens, which it says works the same way. Its description of the estimate only names max_tokens.

Add credits

Add credits on the Credits page, the link in the message. OpenRouter says adding credits also raises the in-flight total on accounts that have one, up to a fixed ceiling.

Raise the key's limit

For openrouter_key_limit, raise the limit on that key on the Keys page, or, if the limit resets, wait for the reset. OpenRouter's hint also offers removing the limit or using a key without one; that also removes the cap the limit gave you. Our OpenRouter spending limit guide has the steps. To see what the key has left, ask OpenRouter:

Shell
curl https://openrouter.ai/api/v1/key \
  -H "Authorization: Bearer $OPENROUTER_API_KEY"

In the response, limit_remaining is what the key can still spend (null if it has no limit), and limit_reset says how often the limit resets (daily, weekly or monthly), or null if it never does. For the whole account, GET /api/v1/credits returns the total credits purchased and used, and needs a management key.

Sources: OpenRouter, Parameters, Python SDK reference, Limits, Get remaining credits

Tell this 402 apart in code

OpenRouter's docs say the OpenAI SDK, which works with OpenRouter, doesn't retry a 402 on its own. So your code sees the error once. Read limit_source to decide what to do:

Python
import openai


def why_402(error: Exception) -> str | None:
    """For an OpenRouter 402: error.metadata.limit_source, or "unknown"."""
    if not (isinstance(error, openai.APIStatusError) and error.status_code == 402):
        return None
    body = error.body if isinstance(error.body, dict) else {}
    metadata = body.get("metadata")
    source = metadata.get("limit_source") if isinstance(metadata, dict) else None
    return source if isinstance(source, str) else "unknown"
TypeScript
import OpenAI from "openai";

// For an OpenRouter 402: error.metadata.limit_source, or "unknown".
function why402(error: unknown): string | undefined {
  if (!(error instanceof OpenAI.APIError) || error.status !== 402) {
    return undefined;
  }
  const body = error.error as { metadata?: { limit_source?: unknown } };
  const source = body?.metadata?.limit_source;
  return typeof source === "string" ? source : "unknown";
}

We ran both checks with the Python SDK (openai 3.50.0) and the TypeScript SDK (openai 7.56.0), against a local test server. It sent the two errors above (with the outer error object added and previous_errors left out), OpenRouter's own in-flight example, a made-up 402 with no metadata, and a 429. The default client sent each 402 once. For a full retry check that covers every OpenRouter limit, see our OpenRouter spending limit guide.

Sources: OpenRouter, Errors and Debugging, Quickstart

Where Billfuse fits

Billfuse is the tool we built to watch AI API spend. It can't prevent this error. It doesn't read your OpenRouter balance or your key limits, it can't pause OpenRouter, and OpenRouter spend reaches it about a day late, because OpenRouter reports each UTC day once it's over.

What Billfuse does: one monthly budget across OpenAI, Anthropic, Gemini and OpenRouter, with emails at 50%, 80% and 100% of it. It also alerts you when one provider's day reaches 3 times a normal day, and at least $10 more. Against this error, use OpenRouter's own tools: a sensible max_tokens, and an eye on the key's limit_remaining.

More guides

It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.