How to put a hard spending cap on OpenAI, Anthropic, Gemini and OpenRouter
Last updated
An AI agent stuck in a loop can spend a month's budget in one night. OpenAI, Anthropic, Google Gemini and OpenRouter all let you set a hard cap: a dollar amount where your requests start to fail. This guide shows where each cap is, what happens when you hit it, and what the caps don't cover.
Everything here was checked against each provider's own docs on November 6, 2026. The Anthropic and Gemini sections were checked again on November 12, 2026, and the OpenRouter section on November 13, 2026. The links are at the end of each section.
The short version
- OpenAI: Project settings → Limits, then turn on “Enforce a hard limit”. Monthly.
- Anthropic: Claude Console → Spend limits. Monthly.
- Gemini: Google AI Studio → Spend → Monthly spend cap, or a spend cap budget in Google Cloud Billing. Both monthly, and neither is instant: AI Studio's runs up to about 10 minutes late.
- OpenRouter: a credit limit on each API key. Daily, weekly or monthly.
Set one on every provider you use, even if you also use a tool like Billfuse. It's free, and it's the fastest way to stop spending.
OpenAI
You can cap each project, and the whole organization. Both caps are monthly.
Set a cap on one project
- Open the project, then go to Project settings → Limits.
- Under Spend, click Edit spend limit.
- Enter a monthly spend limit.
- Turn on Enforce a hard limit. This switch is what blocks requests. Without it, nothing is blocked.
- Click Save.
Organization limits works the same way, but its cap is one total for all your projects together, not a cap for each project.
What happens when you hit it
Requests fail with error 429 and the code project_spend_limit_exceeded (or organization_spend_limit_exceeded for the organization cap). They work again when you raise the limit, or when the next month starts.
Watch out
- It isn't instant. OpenAI says your spend “can slightly exceed” the limit.
- Spend alerts only tell you. They don't block anything.
- The 429 looks like a rate limit. If your code retries every 429, check the error code, or your app will keep retrying a cap that won't lift until next month.
More on OpenAI, including the other 429 errors and code that stops retrying a limit: How to set a hard spending limit on the OpenAI API.
Source: OpenAI, Spend limits
Anthropic
Accounts on the Start, Build and Scale tiers already have a monthly cap. You can set a lower one yourself.
Set your own cap
- In the Claude Console, open Spend limits.
- Next to Monthly spend limit, click Set limit or Adjust limit.
- Enter an amount. It can't be higher than your tier's cap.
What happens when you hit it
Requests fail with error 400. The message starts with “You have reached your specified API usage limits” (or “…specified workspace API usage limits” for a workspace limit) and says when access comes back. Raise or remove the limit to get it back sooner.
Watch out
- You can cap each workspace, except the Default one. So create a workspace for agents and experiments, create their API keys in it, and give it a small limit. Existing keys can't be moved to another workspace.
- The tier cap can stop production. It's $500 a month on the Start tier, $1,000 on Build and $200,000 on Scale. Hit it and the API stops until 00:00 UTC on the 1st of next month, unless Anthropic raises your limit. Requests fail with 429, and on the Messages API the error code is
enforced_spend_limit_reached. Retrying doesn't help, including the SDK's automatic retries.
More on Anthropic, including workspace limits and code that stops retrying a limit: How to set a spending limit on the Anthropic API.
Sources: Anthropic, Rate limits → Spend limits, Claude Help Center, Create and manage workspaces
Google Gemini
Since March 2026, Google AI Studio lets you put a monthly cap on each project. Google Cloud Billing can do the same with a spend cap budget.
Set a cap on one project
- Open Google AI Studio and go to Spend.
- Under Monthly spend cap, click Edit spend cap.
- Enter an amount.
You need the project editor, owner or admin role.
Watch out
- Google calls this feature experimental.
- It can run up to about 10 minutes behind. You pay for whatever is spent in that time. Batch jobs and agent sessions can also go over the cap.
- Your billing account has its own cap. It's $250 a month on Tier 1, $2,000 on Tier 2 and $20,000 to $100,000 on Tier 3. Hit it and every project on that billing account stops until the 1st of next month. One runaway project can take your other projects down with it.
- If you prepay and your balance reaches $0, every API key in every project on that billing account stops at once, with error 402.
- A Google Cloud budget pauses new requests only if you choose Spend cap enforcement when you create it, with one project and the Gemini API as its service. Requests already running finish and are billed. An alerts-only budget doesn't: Google says it “doesn't automatically cap” usage.
More on Gemini, including the 10-minute spend limit and code that stops retrying a cap: How to set a spending limit on the Gemini API.
Sources: Google AI Studio, Billing, Google blog, March 16, 2026, Google Cloud, Budgets, Google Cloud, Manage spend cap budgets
OpenRouter
Each API key can have its own credit limit. It's the only one of the four that can reset every day.
Set a cap on one key
- Give the key a credit limit in dollars.
- Choose when it resets: daily, weekly or monthly. Resets happen at 00:00 UTC, and weekly ones on Monday.
OpenRouter's docs describe both settings for creating and updating keys through its API.
What happens when you hit it
Requests with that key fail with error 403, and the error's limit_source is openrouter_key_limit. OpenRouter's docs also list a spent key limit under error 402, so check limit_source, not only the status. The limit applies to that key only.
Watch out
- If you use your own provider keys through OpenRouter (BYOK), that usage only counts toward the limit if the key is set to include it.
- Your account credits are a cap too: when they can't cover a request, it fails with error 402.
More on OpenRouter, including workspace budgets and code that stops retrying a limit: How to set a spending limit on the OpenRouter API.
Sources: OpenRouter, Create a new API key, OpenRouter, Errors and Debugging, Limits
What the caps don't cover
- A monthly cap can go in one night. Only OpenRouter can cap a single day. With a $500 monthly cap, a loop can spend all $500 on the 2nd, and your app is blocked until you raise the cap or the month ends.
- A cap only acts at the end. Unless you also set alerts, you find out when your app stops working.
- A cap stops everything behind it, including your production traffic. So people set caps high, and a high cap stops a problem late.
- Each cap only sees one provider. Use three providers and you have three caps, three dashboards, and nothing that adds them up.
- Some aren't instant. OpenAI and Google both say your spend can go a little over the cap.
A setup that works
- Put a hard cap on every provider. Make it the most you could stand to lose in one bad month.
- Give agents and experiments their own project, workspace or key, with a much smaller cap. On OpenRouter, use a daily limit.
- Add alerts well below the cap, so you hear about a problem before things stop.
If a key has already leaked, see what to do first when an AI API key leaks.
Where Billfuse fits
Billfuse is the tool we built for the gaps above. It doesn't replace the caps. Keep them on.
- One budget across all four providers. Billfuse checks your spend every hour and emails you at 50%, 80% and 100% of the budget. It can post to Slack too.
- 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.
- Pausing, if you turn it on. When the budget runs out, Billfuse pauses OpenAI and Anthropic with their own controls: it sets each active OpenAI project's spend limit to $0.01 and switches your active Anthropic API keys off. Resume puts them back, except a project limit you changed, or a key you turned back on or deleted, while it was paused.
- What it can't do. It checks hourly, so it's slower than a provider's own cap. It can't pause Gemini or OpenRouter, and their spend reaches Billfuse about a day late.
More guides
- 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
- How to set a spending limit on the OpenRouter 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.