How to set a spending limit on the OpenRouter API
Last updated
OpenRouter runs on credits: you buy them, and requests spend them. On top of your credit balance, it has three spending limits you can set: a credit limit on each API key, a budget on a workspace, and a budget in a guardrail. This page shows where to set them, what happens when one is reached, and what they don't cover.
Everything here was checked against OpenRouter's docs on November 13, 2026. The sources are linked under the sections they back up.
The short version
- In OpenRouter, open Settings → API Keys and click the key.
- Under Key limit, enter a Credit limit in dollars.
- Choose when it resets: daily, weekly or monthly. With no reset, the limit covers the key's whole lifetime.
When the key has spent its limit, requests with that key fail until the limit resets or you raise it. The limit applies to that key only.
Your balance, and three limits you set
- Your credit balance. When it can't cover a request, the request fails with error 402. With a negative balance, OpenRouter says you may get 402 errors on free models too.
- A credit limit on an API key caps what that one key can spend. It can reset daily, weekly or monthly, or never.
- A workspace budget is one pooled cap for every member and key in a workspace. You can set a daily, weekly, monthly and lifetime amount, in any combination.
- A guardrail budget caps each member or each key the guardrail is assigned to. It resets daily, weekly or monthly.
The limits stack. OpenRouter checks every one that applies on each paid request, and the first one that is spent blocks the request. Daily limits reset at 00:00 UTC, weekly ones on Monday, monthly ones on the 1st.
Sources: OpenRouter, Limits, Spend Controls
Set a credit limit on an API key
- Open Settings → API Keys and click the key.
- Under Key limit, enter a Credit limit in dollars.
- Choose the reset interval: daily, weekly, monthly, or none.
- It's on every plan. OpenRouter says the key credit limit isn't tied to a plan.
- You can set it through the API too. Creating or updating a key takes
limit,limit_resetandinclude_byok_in_limit. Those calls need a management key, not a regular API key. - Your own provider keys don't count by default. If you use your own provider keys through OpenRouter (BYOK), turn on Include BYOK usage in limit. Without it, OpenRouter says a key that only uses BYOK providers never reaches its limit.
- To see what's left, call
GET /api/v1/keywith the key.limit_remainingis what's left of the key's own limit, andeffective_budgetis the budget that will block the key first.
Sources: OpenRouter, Capping Shared Agent Keys, Management API Keys, Limits, Notifications
Set a workspace budget
Your keys already live in a Default workspace, and it can have budgets too. Use a workspace budget as the cap for everything in the workspace, whichever key is used.
- Open the workspace's Settings page, at
openrouter.ai/workspaces/<slug>/settings. - Scroll to the Budgets section.
- Click Add budget, choose an interval, and enter a dollar amount.
- Click Save.
- Who can set it: on a personal account, you. In an organization, only Organization Administrators. It's available on every plan.
- Shorter intervals need smaller amounts. The weekly budget must be less than the monthly one, and the daily less than the weekly.
- It isn't exact. The check runs before a request is sent to a provider. Requests already sent finish, so OpenRouter says spend may slightly exceed the budget.
- BYOK spend doesn't count by default. Turn on Include BYOK spend above the budget rows to count it. It's a separate switch from the one on each key.
Source: OpenRouter, Workspace Budgets, Workspaces
Guardrail budgets, for teams
A guardrail can carry a budget limit along with its other rules. You create one on the workspace's Guardrails page, then assign it to members or API keys. In an organization, that takes an organization admin.
- It does nothing until it's assigned. Creating a guardrail only defines it. The exception is the workspace default guardrail, which applies to all traffic in the workspace.
- It isn't pooled. Each member or key it's assigned to gets the full amount. For one shared cap, use a workspace budget.
- Spend follows whoever created the key, not whoever calls it. A workspace-owned key has no creator, so member guardrails never apply to it. Give that key its own credit limit.
- OpenRouter also has guardrail policies, which make the budget a policy of its own that you assign separately.
Sources: OpenRouter, Guardrails, Spend Controls, Guardrail Policies
What happens when you reach a limit
When a spending limit blocks a request, the error can carry a field that names the limit: error.metadata.limit_source. Read that, not only the status code.
A budget or a key limit is spent: error 403
The request fails with error 403 before it reaches a provider. limit_source is openrouter_guardrail_budget, openrouter_workspace_budget or openrouter_key_limit. The error's metadata also has limit_usd, spend_usd and resets_at, the time the limit resets (null for a limit that never resets). OpenRouter says retrying before then fails the same way, and there is no Retry-After header.
Key limit exceeded (daily limit). Manage it using https://openrouter.ai/workspaces/default/keys/... $2.03 of $2.00 used; resets 2026-10-28T00:00:00.000Z.This one is a key's own limit: raise the key's credit limit, or wait for the reset time at the end of the message. The text is from a GitHub issue dated October 27, 2026; we cut the key's ID from the link. OpenRouter's docs give only the words Key limit exceeded, and say the message ends with the amount used, the limit and the reset time.
One thing to know about key limits: OpenRouter's docs list a spent key limit under both 403 and 402 errors. Checking limit_source works either way.
Your credits can't cover the request: error 402
limit_source is openrouter_credits. Add credits, or make the request smaller. Retrying won't help.
This request requires more credits, or fewer max_tokens. You requested up to 131072 tokens, but can only afford 35063. To increase, visit https://openrouter.ai/settings/credits and add more creditsThe message says the request could use more tokens than you can afford. OpenRouter's advice for a 402: add credits, or make the request smaller (fewer input tokens or a lower max_tokens) so its estimated cost fits. If you still have credits, see the next section. The checks below don't retry this error.
OpenRouter's docs don't show this message, and the report above (GitHub, November 8, 2026) doesn't show its limit_source. Other reports have a link to an API key instead of the credits page (November 12, 2026), or limit_source set to openrouter_key_limit (November 3, 2026), which OpenRouter says means the key's credit limit is exhausted. So check limit_source to see which limit you hit.
For why this happens while you still have credits, and how to fix each case, see our guide to the “requires more credits” error.
A 402 while you still have credits
OpenRouter charges a request when it finishes, so it holds each paid request's estimated cost while it runs. On some prepaid accounts, those with a balance below a threshold and, for now, newer accounts, the total it will hold is limited. Two things can then happen while your balance is still positive:
- Your running and recently finished requests fill that total. A new request fails with a 402 whose
limit_sourceisopenrouter_in_flight_budget. This is the one 402 to retry: wait for theRetry-Afterheader, then send it again. OpenRouter says a 402 without that header is not one to wait and retry. - One request is larger than the whole total.
limit_sourceisopenrouter_credits, and OpenRouter says retrying will not help. Lowermax_tokensor the prompt size, or add credits.
Sources: OpenRouter, Limits, Errors and Debugging, Capping Shared Agent Keys
Stop your code from retrying a limit
A spent limit keeps failing until it resets or someone raises it, so a loop that retries every error can run for hours without doing anything. These checks use the OpenAI SDK, which OpenRouter says you can point at its API. Check before you retry:
import openai
# limit_source values that mean a spending limit was reached
SPEND_LIMITS = {
"openrouter_key_limit",
"openrouter_workspace_budget",
"openrouter_guardrail_budget",
"openrouter_credits",
}
# OpenRouter may send a Retry-After header with these
RETRY = {429, 503}
MAX_ATTEMPTS = 5
def limit_source(error: Exception) -> str | None:
"""OpenRouter's error.metadata.limit_source, if the error has one."""
if not isinstance(error, openai.APIStatusError):
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 None
def spend_limit_reached(error: Exception) -> bool:
"""A named spending limit, or any other 402 except the in-flight one."""
source = limit_source(error)
if source in SPEND_LIMITS:
return True
return (
isinstance(error, openai.APIStatusError)
and error.status_code == 402
and source != "openrouter_in_flight_budget"
)
def should_retry(error: Exception, attempts: int) -> bool:
"""attempts: how many times this request has been sent so far."""
if not isinstance(error, openai.APIStatusError) or attempts >= MAX_ATTEMPTS:
return False
if spend_limit_reached(error):
return False
# The one 402 to retry, and only when OpenRouter says how long to wait
if error.status_code == 402:
return error.response.headers.get("retry-after") is not None
# Everything else, such as 400, 401 and a 403 from a content filter
return error.status_code in RETRYimport OpenAI from "openai";
// limit_source values that mean a spending limit was reached
const SPEND_LIMITS = new Set([
"openrouter_key_limit",
"openrouter_workspace_budget",
"openrouter_guardrail_budget",
"openrouter_credits",
]);
// OpenRouter may send a Retry-After header with these
const RETRY = new Set([429, 503]);
const MAX_ATTEMPTS = 5;
// OpenRouter's error.metadata.limit_source, if the error has one
function limitSource(error: unknown): string | undefined {
if (!(error instanceof OpenAI.APIError)) return undefined;
const body = error.error as { metadata?: { limit_source?: unknown } };
const source = body?.metadata?.limit_source;
return typeof source === "string" ? source : undefined;
}
// A named spending limit, or any other 402 except the in-flight one
function spendLimitReached(error: unknown): boolean {
const source = limitSource(error);
if (source && SPEND_LIMITS.has(source)) return true;
return (
error instanceof OpenAI.APIError &&
error.status === 402 &&
source !== "openrouter_in_flight_budget"
);
}
// The SDK keeps headers in a Headers object; older versions use a plain object
function hasRetryAfter(error: { headers?: unknown }): boolean {
const headers = error.headers as
| Headers
| Record<string, string | null | undefined>
| undefined;
const value =
headers instanceof Headers
? headers.get("retry-after")
: headers?.["retry-after"];
return Boolean(value);
}
// attempts: how many times this request has been sent so far.
function shouldRetry(error: unknown, attempts: number): boolean {
if (!(error instanceof OpenAI.APIError) || attempts >= MAX_ATTEMPTS) {
return false;
}
if (spendLimitReached(error)) return false;
// The one 402 to retry, and only when OpenRouter says how long to wait
if (error.status === 402) return hasRetryAfter(error);
// Everything else, such as 400, 401 and a 403 from a content filter
return RETRY.has(error.status ?? 0);
}Call the retry check after each failed attempt. When it says yes, wait for the Retry-After header if there is one, then try again. When the spend limit check says yes, stop and tell someone. That check also says yes for a 402 that names no limit, since OpenRouter describes 402 as insufficient credits.
- SDK retries. In our test, the OpenAI SDK's default client sent a 402 or a 403 once, and a 429 or a 503 three times. Count SDK retries toward your own limit.
- Other statuses. Besides that one 402, the checks retry only 429 and 503, which OpenRouter says may carry
Retry-After. Add any others your app treats as temporary. OpenRouter also uses 503 when no provider meets your routing requirements; the attempt limit stops the loop either way. - Errors with status 200. Once a provider accepts a request, the status is already 200, so later errors arrive inside the response, streaming or not. These checks don't cover those. Budget checks and the in-flight check run before a request reaches a provider.
We ran the checks with the OpenAI Python SDK (openai 3.50.0 and 1.40.0) and the OpenAI TypeScript SDK (openai 7.56.0 and 4.52.0), against a local test server that sends the errors described above.
Sources: OpenRouter, Errors and Debugging, Quickstart
Alerts before a limit
- Low balance alert: on every plan, by email. It fires when your balance drops below an amount you choose, $100 by default. Set it under Settings → Notifications.
- Workspace budget and API key spend limit alerts: on Business and Enterprise plans only. Once turned on, they fire at 80% and 100% of the limit by default. The key alert is set on the key's own page and goes out by email only.
- Auto top-up refills your balance when it drops below a threshold you set. OpenRouter warns that a key with no limit lets a leaked key or a runaway agent spend your entire balance, including any auto top-ups.
Sources: OpenRouter, Notifications, FAQ, Authentication
What the limits don't cover
- Your own provider keys, unless you switch it on. Key limits, workspace budgets and guardrail budgets each have their own BYOK switch, and all three are off by default. When on, workspace and guardrail budgets count what OpenRouter would have charged, which may not match your provider's invoice.
- Guardrail budgets aren't shared. Ten members on a $50 guardrail can spend $500.
- They aren't exact. OpenRouter says of workspace budgets that requests already sent finish, so spend may slightly exceed the budget.
- They only see OpenRouter. What you spend directly with OpenAI, Anthropic or Google has its own cap at each provider. This guide covers all four.
Where Billfuse fits
Billfuse is the tool we built for these gaps. It doesn't replace OpenRouter's limits. Keep them on.
- One budget across OpenRouter and your other providers. Billfuse emails you at 50%, 80% and 100% of the budget, and can post to Slack too. It reads OpenRouter spend with a management key, and counts the credits you spent, not what your own provider keys were billed.
- Spike alerts, with no budget needed. When one provider's day reaches 3 times a normal day, and at least $10 more, you get an email, and a Slack message if you added one.
- What it can't do. It can't pause OpenRouter. And OpenRouter reports each day once it's over (UTC), so OpenRouter spend, and any alert it triggers, reaches Billfuse about a day late. OpenRouter checks its own limits on every paid request. Billfuse also doesn't read your credit balance, so it doesn't warn you when credits are about to run out.
More guides
- How to put a hard spending cap on OpenAI, Anthropic, Gemini and OpenRouter
- How to set a hard spending limit on the OpenAI API
- How to set a spending limit on the Anthropic API
- How to set a spending limit on the Gemini API
- Billing error or rate limit? AI API errors from OpenAI, Anthropic, Gemini and OpenRouter
- Leaked AI API key: what to do first
- Fix "Your credit balance is too low to access the Anthropic API"
- Gemini API error 402: "Your prepayment credits are depleted"
- OpenAI error 429 insufficient_quota: "You exceeded your current quota"
- OpenRouter 402: "This request requires more credits, or fewer max_tokens"
It's free while Billfuse is in early access. You can try it with sample data first, no sign-up needed.