How to Cap AI API Spend: Anthropic, OpenAI and Google Compared
When attackers reached API keys stored in OpenCode Console this weekend, some developers woke up to charges of hundreds of dollars, and a few reported more than $1,000, according to TechCrunch. The lesson is not specific to one tool. Any AI API key is a spending credential, and the best defence is a limit set at the provider. This guide shows what Anthropic, OpenAI and Google each offer, as of October 2026, and how to combine them.
Why do AI API keys need spending limits?
An API key lets whoever holds it consume AI services on your account, and charges follow usage, not intent. If a key leaks through a breached tool, a public repository or a careless paste, the bill grows while you sleep. Hiding keys better is necessary but not sufficient. A spend limit at the provider is the control that still works after a leak, because it caps what the key can cost. Our checklist for securing AI agents covers the broader credential hygiene; this guide focuses on money.
What spend controls does each provider offer?
| Provider | Hard cap you can set | Alerts | Key and project controls | Notable detail |
|---|---|---|---|---|
| Anthropic | Your own monthly spend limit, below your tier cap, in the Console Billing page; workspaces can have their own limits | Not covered in the page we read | Workspaces with custom spend and rate limits (not on the default workspace) | Tier caps: Start $500, Build $1,000, Scale $200,000 per month |
| OpenAI | Hard spend limits stop affected API traffic at the limit | Spend alerts at a dollar amount you set | Project keys with expiration dates; separate projects for staging and production | Hard limits can stop production traffic, so test before enabling |
| Google (Gemini API) | Project-level spend caps (experimental) in AI Studio, plus billing-tier caps | Not mentioned in the page we read | Keys belong to a project and inherit its limits | Caps can allow some overage because billing data lags up to about 10 minutes |
How do you set a limit on the Anthropic API?
In the Claude Console, open the Billing page, find Spend limits and choose Set limit or Adjust limit. Your limit cannot exceed your tier’s cap. Anthropic’s documentation says that when usage reaches a limit you set, requests return an HTTP 400 error that states when access resumes, and you can raise or remove the limit to restore access sooner. You can also set lower spend and rate limits per workspace, which is useful if you give different teams or tools their own workspace. The default workspace cannot be limited, so create dedicated workspaces for experiments and third-party tools.
How do you set a limit on the OpenAI API?
OpenAI’s guidance has several layers. Keep keys out of code and public repositories, loading them from environment variables or a secret manager. Rotate keys: create a replacement, update your apps, verify it works, then revoke the old one. OpenAI strongly recommends setting an expiration date when you create a project key, and administrators can cap key lifetimes at organisation or project level. Use separate projects for staging and production. For money, spend alerts notify you when usage passes an amount you set, while hard spend limits stop affected traffic when tracked spend reaches the limit. Because hard limits can stop live traffic, review the spend-limit guide before using one on a production project.
How do you set a limit on the Google Gemini API?
Google’s documentation describes project-level spend caps, labelled experimental, that users with editor, owner or admin roles can set on the Spend page of AI Studio. There are also monthly caps tied to your billing tier, listed as $250 for Tier 1, $2,000 for Tier 2 and $20,000 to $100,000 for Tier 3, and when a cap is reached service pauses for all linked projects until the next billing cycle. Keys inherit their project’s tier and limits, so usage from every key in a project counts toward that project’s cap. Google notes that both cap types can allow some overage because billing data can lag by up to about ten minutes.
Does prepaying credits work as a spending control?
Sometimes. Google’s documentation says that on a prepay plan usage is deducted from your credit balance, and when it reaches $0, API keys in all projects linked to that billing account stop working with an HTTP 402 error. That naturally limits exposure to the credit you loaded, but it also halts every project on the account, so it suits a small setup better than a company with live products. Auto-reload can top up the balance, and you can set a monthly auto-charge limit on it, so check that setting too.
What practices help regardless of provider?
Limits are one layer. These habits make a leak cheaper and easier to contain:
- One key per tool and per environment. If a coding agent or automation platform is compromised, you revoke one key.
- Dedicated projects or workspaces. Put third-party tools in their own project with a low limit.
- Store as few keys as possible in other people’s systems. If a hosted console does not need your provider key, do not give it one.
- Short lifetimes. Expiring keys limit how long a stolen key is useful.
- Watch the usage page. Check it after any change in tooling and after any security news about a tool you use.
- Know the revoke path. Write down where to revoke each key and who is allowed to.
For teams buying coding assistants, our guide to AI coding assistant pricing for teams explains how per-seat plans differ from usage-based API billing, which is where unlimited bills come from.
What should you do when a key leaks?
Act in this order. First, revoke the key at the provider. Second, create a replacement and update only the systems that need it. Third, open the usage dashboard and look for charges you did not make, then contact the provider’s support about them: in the OpenCode incident, TechCrunch reports that OpenAI said it would refund API customers for credits used in the attack, and Anthropic and Google blocked keys they believed were exposed. Refund policies vary, so ask rather than assume. Finally, find how the key escaped, whether through a tool, a repository or a shared document, and close that route.
How we chose what to cover
We reviewed the public documentation pages of Anthropic, OpenAI and Google that describe spend limits, key handling and billing, plus press coverage of the OpenCode incident, and we report only what those pages state. Limits, tier caps and menus change often, so check the linked pages before relying on any figure here. We did not test the consoles ourselves, and where a page did not mention a feature we say so in the table.
What is a sensible starting setup for a small team?
Create a separate project or workspace for each tool or environment, give each its own key with an expiry date where the provider allows it, and set a low monthly limit on each, raising it only when real usage requires it. Turn on alerts where they exist. Keep production keys in a secret manager rather than in chat, tickets or shared drives. Review usage weekly for the first month, then monthly. The goal is that the worst-case loss from any single leaked key is a number you chose in advance, not a number an attacker chose for you.
Frequently asked questions
How do I stop an AI API bill from running away?
Set a spend limit at the provider, use separate keys and projects per tool, add alerts, and keep keys out of code. A provider limit stops charges even if a key leaks, which a key you merely hide cannot do.
Does a spend cap stop charges instantly?
Not always. Google's documentation says caps can allow some overage because billing data can lag by up to about ten minutes, so combine caps with alerts and low limits.
What should I do if an API key leaks?
Revoke it at the provider straight away, create a replacement, update the apps that need it and review your usage page for unexpected charges. Ask the provider about refunds for fraudulent use.
Should developers share one API key across tools?
No. One key per tool or project means a leak can be revoked without breaking everything else, and usage can be traced to the tool that caused it.