Fix an OpenRouter 402 Error and Negative Balance
Read limit_source to tell an empty balance from the new in-flight budget 402, when Retry-After is safe, and how to fix a negative balance.
Published Checked By RouterPlex9 min read
On this page
Key facts
Checked October 20, 2026
- Read
error.metadata.limit_source:openrouter_credits,openrouter_key_limitoropenrouter_in_flight_budgetnames the check that failed. - Only retry
openrouter_in_flight_budget, after theRetry-Afterseconds. That 402 can fire while your balance is positive. - A negative balance blocks free models too. Free variants cap at 20 requests per minute and 50 or 1,000 per day.
- Concurrency can cross zero: $0.08 left and four requests costing $0.04 each ends at -$0.08.
- RouterPlex balances stop at $0 and never go negative, and each key can carry a hard lifetime spend budget.
An OpenRouter 402 means a credit or budget check refused the request. Most 402s mean the balance or a key limit is used up, and retrying will not help. One newer 402 is different. OpenRouter can return it while your balance is still positive, because running and recent requests have filled your in-flight budget. That one clears on its own, and the response tells you how long to wait.
Read error.metadata.limit_source first. It names the check that failed. If the dashboard also shows a negative balance, stop the client before you top up. Automatic retries will keep spending against a balance that is already below zero.
Recovery from an empty balance is three steps: stop the workload, add enough credit to get above zero, then send one small manual request before restarting the agent. The rest of this page explains why a prepaid-looking balance can cross zero, and how to keep the next incident inside a $5 or $10 key budget.
OpenRouter 402: check limit_source first
Every OpenRouter 402 that comes from a budget check carries error.metadata.limit_source. Some also carry a reason and a remedy_hint (a one-line suggested fix). OpenRouter's docs say to branch on limit_source, not on the message text.
Checked 20 October 2026: OpenRouter API limits and OpenRouter errors and debugging. Field names and limits can change. Read the current docs before you hard-code them.
| limit_source | reason | What it means | Retry? | Fix |
|---|---|---|---|---|
openrouter_in_flight_budget | in_flight_budget_exhausted | Running and recently finished requests fill your in-flight budget. Your balance can still be positive. | Yes, after Retry-After | Wait the number of seconds in the Retry-After header, then send it again. Lower concurrency if it repeats. |
openrouter_credits | weight_exceeds_budget | This one request's estimated cost is larger than your whole in-flight budget. | No | Lower max_tokens or the prompt size, or add credit. |
openrouter_credits | none | The balance cannot cover the request. | No | Add credit. Stop the client first if the balance is negative. |
openrouter_key_limit | none | The credit limit set on this API key is used up. | No | Raise the key limit or use another key. |
The docs also list openrouter_guardrail_budget and openrouter_workspace_budget for budgets set by an org admin. Treat those like a key limit. A 402 without a Retry-After header is not a wait-and-retry case.
This snippet calls OpenRouter with the OpenAI Python SDK. It retries only the in-flight case.
import os, timefrom openai import OpenAI, APIStatusErrorclient = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])def ask(model, messages):for attempt in range(3):try:return client.chat.completions.create(model=model, messages=messages, max_tokens=500)except APIStatusError as error:body = error.body if isinstance(error.body, dict) else {}body = body.get("error", body)source = (body.get("metadata") or {}).get("limit_source")wait = error.response.headers.get("retry-after")if error.status_code == 402 and source == "openrouter_in_flight_budget" and wait:time.sleep(float(wait))continueraiseraise RuntimeError("in-flight budget still full after 3 tries")
Which 402 message did you get?
OpenRouter returns a few different 402 messages. Each one points at a different fix.
"This request requires more credits, or fewer max_tokens"
The full message reads like: *"This request requires more credits, or fewer max_tokens. You requested up to 64000 tokens, but can only afford 1600."* OpenRouter checks the most the request could cost, using its max_tokens, against your remaining credit. Coding agents often ask for 32K or 64K output tokens by default, so a small balance fails even for a short answer.
- Lower
max_tokensfor the request. In Claude Code, setCLAUDE_CODE_MAX_OUTPUT_TOKENSto a smaller value, such as8000. - Switch to a cheaper model for the same task.
- Or add credit so the balance covers the reserved output.
"Insufficient credits. This account never purchased credits"
The key belongs to an account or organization with no credit purchase on record. This is common when a key was created under a personal account but credits were bought for an organization, or the other way round. Check which account or org owns the key. If it is the right one, buy credits there. Free-model allowances do not cover paid models.
402 with a positive balance (in-flight budget)
OpenRouter places a hold on each paid request while it runs. The hold is the estimated cost of the request. When the request ends, the actual cost replaces the hold for a short settling window. The total that can be held at once is your in-flight budget. The docs describe it as a fraction of your current balance, up to a fixed ceiling. They do not publish the fraction or the ceiling.
When a new request does not fit beside the running and recent ones, OpenRouter rejects it with 402 before it reaches a provider. This can happen with a positive balance. The docs say it can even happen with no request still running, while recent costs are settling. Look for limit_source set to openrouter_in_flight_budget and a Retry-After header. Wait, then retry. If one request is too big for the whole budget, reason is weight_exceeds_budget and waiting will not help.
"Insufficient credits. Add more using https://openrouter.ai/settings/credits"
The available balance is at or below zero. If the dashboard shows a negative balance, usage posted after the balance check (see below). Stop the client before topping up, or queued retries will spend the new credit straight away.
402 on a free model
A negative balance blocks free models too. OpenRouter's limits page says you "may see 402 errors, including for free models" until the balance is above zero again. Free variants (model ids ending in :free) also have their own caps. With fewer than 10 credits purchased, the limit is 20 requests per minute and 50 per day. With at least 10 credits purchased, it is 20 per minute and 1,000 per day. The page adds that the higher daily ceiling starts one credit below that threshold. To see your daily counter and credits left on a key, send GET https:/. It does not report the per-minute limit. (Checked 20 October 2026 on the OpenRouter limits page.)
OpenRouter documents its credit system and credit monitoring in the billing section of its FAQ. Error behavior and provider responses can change, so use the current activity page as the source of truth for your account.
If you are deciding whether the failure mode justifies switching services, separate the incident from the purchase model. The OpenRouter credits and fee guide covers funding cost and expiry terms, while the OpenRouter alternatives comparison compares hosted wallets including LLM Gateway and Vercel AI Gateway.
Why a balance can cross zero
LLM billing is finalized after tokens are generated. At request start, a gateway knows the current balance and an estimate of what the request might cost. It does not yet know the final output length.
Several normal API behaviors can create a small accounting gap:
- Streaming: the response starts before the final output-token count is known.
- Concurrency: multiple requests pass the same pre-request balance check at nearly the same time.
- Retries: an SDK, proxy, or agent may retry a request without making the retry obvious in the UI.
- Long outputs: a missing or high
max_tokensvalue lets a response cost much more than expected. - Agent loops: tools can call the model repeatedly until a task ends, multiplying a small per-call cost.
- Delayed usage posting: provider usage can arrive after the response completes.
Imagine an account with $0.08 left and four concurrent requests. Each request sees a positive balance at the start. If each eventually costs $0.04, the final combined cost is $0.16 and the resulting balance is -$0.08.
How to recover from a 402
- Stop the process that is sending requests. Do not let an automatic retry loop keep firing.
- Open the activity or usage log and filter to the affected API key and time window.
- Check whether requests were concurrent, retried, or unexpectedly long.
- Rotate the key if the traffic is not yours.
- Add enough credit to restore a positive available balance.
- Send one small request manually before restarting the full workload.
For an automated service, treat a 402 as a billing-state error unless limit_source is openrouter_in_flight_budget. Blind exponential retries cannot create credit, and they can hide the actual failure from an operator.
import osfrom openai import OpenAI, APIStatusErrorclient = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=os.environ["OPENROUTER_API_KEY"])try:client.chat.completions.create(model="your-model-id",messages=[{"role": "user", "content": "Summarize this file"}],max_tokens=500,)except APIStatusError as error:if error.status_code == 402:# Pause the queue and alert an operator. Retry only the in-flight case shown above.raise RuntimeError("LLM credit or budget exhausted") from errorraise
Four controls that matter more than a low-balance alert
An alert is useful, but it fires after spend has already happened. Stronger controls stop or constrain the request path.
1. One key per workload
Do not share the same key across production, local development, CI, and coding agents. Separate keys make attribution and revocation straightforward.
2. A hard key budget
A server-side key budget is better than a dashboard target. Set the maximum amount that a key is allowed to consume. If a local experiment should cost at most $10, its credential should not be able to reach the other $490 in the account.
3. Output and concurrency limits
Set max_tokens, bound the number of parallel requests, and cap agent steps. These limits reduce both expected cost and the uncertainty between request start and final accounting.
4. Fail closed when balance data is unavailable
If your own service cannot retrieve the current gateway balance, do not display a made-up zero or assume the full lifetime top-up remains available. Mark the balance unavailable and pause high-risk jobs until billing state is trustworthy.
The prepaid design alternative
RouterPlex uses a prepaid account balance and lets every API key carry a hard lifetime spend budget. Requests stop when the balance reaches $0 instead of turning into a negative amount that must be repaid. When credit runs out, the API returns a 402 that says the balance is used up. The message links straight to the top-up page, so a coding agent does not sit in a retry loop.
New accounts can connect Claude Code, Cursor, Codex or another OpenAI-compatible tool in guided setup and test it with $1 of credit before paying. Top-ups start at $5 and the credit does not expire.
The safest setup still uses defense in depth: a $10 key budget, explicit output limits, bounded concurrency, and a low-balance alert. No single billing check can replace application-level controls for an autonomous agent.
For the exact setup, read API keys and budgets. You can also compare RouterPlex and OpenRouter directly or read how Vercel AI Gateway compares with OpenRouter. To see the failure behavior yourself, create a $5 prepaid account and test it with a small key budget.
Frequently asked questions
What does HTTP 402 mean on OpenRouter?
What does "This request requires more credits, or fewer max_tokens" mean?
What does "This account never purchased credits" mean on OpenRouter?
What does OpenRouter negative credits or a minus balance mean?
Should I retry an OpenRouter 402 error?
How do I prevent a coding agent from draining my balance?
Run the smallest paid test.
Add $5, cap the key, and verify the result with your own workload. No subscription, and credit never expires. A first top-up of $25+ is matched with $25 extra.
Weighing the switch? RouterPlex vs OpenRouter, line by line




