On a paid AI API, a request from a forgotten test script or a bug that resends the same thing over and over is billed like one from a real user. (An AI API is the set of rules an app uses to send input to a provider’s model and get its output back.) Keeping the bill near your plan comes down to the settings you choose and the limits you build in.
The short answer: set a spending limit that actually blocks requests, not just an alert; check whether auto-reload will keep buying credit for you; and add a few limits inside your own app, namely a maximum answer length, a cap on input size, a cap on retries and a limit for each user. Then test in a separate project on a small sample and watch your usage. One caveat: OpenAI and Google, in documentation read on November 22, 2026, both say some usage can slip past a limit or an empty balance before it takes effect, so set every limit below what you could afford to lose [1, 2, 3, 4].
If tokens (the small chunks of text providers count and bill by) and output prices are new to you, start with how AI API pricing works. Providers are named as examples, not recommendations, and BuildAIQ hasn’t tested these settings.
TL;DR
- Alerts only warn. Hard spending limits, spend caps or a prepaid balance with nothing left to draw on are what make requests fail [1, 2, 4, 5].
- Limits at OpenAI and Google aren’t instant: OpenAI says recorded spend can slightly exceed a hard limit, and Google describes overages during a billing delay of about 10 minutes [1, 3].
- Auto-reload can keep buying credit. OpenAI switches it on by default when you set up prepaid billing; set a monthly reload limit or turn it off [2, 3].
- Bound each request with a maximum output length and a limit on input size, and use caching only where prompts genuinely repeat [6, 7, 8].
- Cap loops and retries yourself. OpenAI’s and Anthropic’s official SDKs (ready-made code libraries that wrap an API) retry some errors automatically, and OpenAI says retrying a billing error won’t restore access [9, 10, 11].
- Test in a separate project with its own lower limit, on a small sample, and read the token counts that come back [12].
Warnings vs. Hard Stops: What Each Control Does
Plain terms used here:
- Alert: a notification when spending passes an amount you choose. It stops nothing.
- Hard limit or spend cap: a setting that makes the provider refuse requests once tracked spending reaches your amount.
- Auto-reload: an automatic purchase of more credit when the balance falls below a threshold.
- Project or workspace: a container inside your account with its own keys and, often, its own limits.
Three model providers’ documentation, as of November 22, 2026 [1, 3, 13]:
| Provider (example) | Notifies only | Blocks requests | Conditions |
|---|---|---|---|
| OpenAI API | Spend alerts [1] | A monthly hard spend limit for the organization or one project, once “Enforce a hard limit” is switched on; affected requests get a 429 error [1] | Can slightly overrun; resets with the next monthly cycle [1] |
| Google Gemini API | Not checked for this guide (see Google Cloud below) | A Prepay balance at $0 stops every key in every project linked to that billing account, with a 402 error [3]; experimental project spend caps in AI Studio [3] | Overages possible for about 10 minutes; batch jobs and agents can run past the balance or cap; spend caps aren’t available for invoiced (offline) billing accounts [3] |
| Anthropic API | Not checked for this guide | A monthly spend limit you set below your tier’s cap, for the organization or a workspace; requests then get a 400 error [13] | A limit on the default workspace might not count or stop some usage there, such as the Console playground; Claude Code workspace limits can return a 429 instead [13] |
Those numbers are status codes. OpenAI and Anthropic use 429 for rate limits and also for some spending caps, 402 means payment is required, and 400 normally flags a problem with the request itself, so Anthropic’s error message is what tells you a spend limit was hit [9, 3, 13, 11]. What to do when an AI API stops working covers reading them.
For most accounts, each provider also sets a monthly ceiling of its own, tied to your usage tier: OpenAI’s monthly usage limit, Google’s tier spend cap, which pauses the Gemini API for every linked project until the next billing cycle, and Anthropic’s monthly spend cap, which returns a 429 coded enforced_spend_limit_reached [1, 3, 13]. Exceptions include Google’s Free tier and Anthropic’s Custom tier, which have no such cap [3, 13]. Those figures are the provider’s, not yours, so set your own limit as well.
Cloud platforms that host models have their own billing tools, as their pages stood in late November 2026; not every one offers a documented way to block requests [4, 14, 15, 16]:
| Cloud platform (example) | Notifies only | Blocks requests | Conditions |
|---|---|---|---|
| Google Cloud | Alerts-only budgets, which Google says don’t cap usage or spending [5] | Spend cap budgets pause one eligible service in one project for the rest of the monthly budget period; eligible services include the Gemini API and Gemini Enterprise Agent Platform (formerly Vertex AI) [4] | Alert emails at 50%, 80% and 100%; not instant, and overages are billed as normal [4] |
| Microsoft Azure | Cost Management budgets, which notify but don’t affect resources or stop consumption [14] | Microsoft Foundry cost controls, in public preview, can send alerts or block requests [15] | Budgets are evaluated against cost data every 24 hours [14]; preview totals aren’t reconciled with the bill, and Microsoft doesn’t recommend preview features for production workloads [15] |
| AWS | AWS Budgets notifications by email or a messaging topic [16] | Nothing on the AWS Budgets page read here is described as a cap on API requests; budget actions can automatically apply an access policy, for example one that denies provisioning new resources [16] | Budget data updates up to three times a day, typically 8–12 hours apart, and notifications can arrive after charges pass the threshold [16]; Amazon Bedrock-specific caps not verified |
Limits Don’t Take Effect Instantly
Anthropic’s pages read here don’t describe enforcement timing; OpenAI’s and Google’s do. OpenAI says hard-limit enforcement isn’t instantaneous, so recorded spend can slightly exceed the configured amount [1]. Its prepaid balance behaves the same way: access may not stop the moment credits run out, and usage in that gap shows up as a negative balance taken from your next purchase [2]. OpenAI’s own advice is blunt.
“Do not rely on the prepaid balance as an instantaneous spending cutoff.” [2]
Google says Gemini API Prepay can overrun during a billing delay of about 10 minutes, and that long-running batch jobs and agents may keep consuming credit beyond your balance [3]. On Google Cloud, requests already in progress when a spend cap triggers still run to completion [4].
Reports lag too. Google says the cost graphs on AI Studio’s Billing and Spend pages can take up to 24 hours to update [3]. AWS warns of a delay between incurring a charge and getting a budget notification [16].
Auto-Reload Can Keep Paying
Prepaid credit looks like a ceiling; auto-reload removes it. OpenAI says new API accounts use prepaid billing and that auto-reload is on by default during setup, with a balance threshold, a target balance and an optional monthly reload limit [2]. Google’s Gemini API makes auto-reload optional and adds a monthly auto-charge limit that switches it off for the rest of the month once reached; payments you make by hand don’t count [3]. Anthropic’s auto-reload buys credit when your balance falls below your threshold, and if the balance is already at or below it when you switch the feature on, you’re charged right away [17].
A reload limit caps purchases, not usage; OpenAI says so explicitly [2]. When credit runs out and nothing reloads, requests fail: OpenAI returns a 429 coded credit_balance_exhausted, Google returns a 402, and Anthropic says you can’t call the API until you add more [9, 3, 17].
A Checklist Before You Send Real Traffic
This order is BuildAIQ editorial guidance, built on the documentation cited.
- Set a blocking limit, then alerts below it. At OpenAI, that’s a monthly spend limit with “Enforce a hard limit” switched on, for the organization or a project [1]. A blocking limit stops your live app too, and OpenAI warns hard limits can interrupt production traffic, so know how to raise one quickly [1]. At Anthropic, it’s your own spend limit below the tier cap [13]. On Google, it’s a spend cap budget on the project in Google Cloud, or the experimental project cap in AI Studio [4, 3]. Then add alerts at amounts that, in OpenAI’s words, leave time to adjust usage, raise the limit or investigate [1]. OWASP’s 2026 Top 10 for LLM Applications, volunteer-written guidance and not a formal standard, asks for budget ceilings that can’t be overridden and that halt inference, because usage that climbs quickly can get ahead of an alert [8].
- Send alerts to someone who reads them. Google Cloud’s spend cap emails go to billing account administrators and project owners, and Google says those recipients can’t be customized [4]. If that leaves you out, an alerts-only budget can email other people through Cloud Monitoring [5].
- Decide on auto-reload. Turn it off, or set a monthly reload limit you could live with losing in a bad month [2, 3].
- Give tests their own project and key. OpenAI suggests separate staging and production projects so testing is less likely to disrupt your live app, each with its own spend limits [12]. Anthropic lets each workspace have its own spend limit, and Google’s AI Studio caps work per project [13, 3]. The guide to making your first AI API request covers setting up a project and key.
- Cap the length of every answer. The setting is
max_output_tokensin OpenAI’s Responses API and in thegeneration_configof Google’s Interactions API, andmax_tokensin Anthropic’s Messages API, which Anthropic calls an absolute maximum the model may stop short of [6, 18, 19]. Don’t set it too low on reasoning models: OpenAI warns a response can hit the limit before any visible output, leaving you paying for input and hidden reasoning with no answer [6]. - Limit what goes in. Set a maximum size for what users can type or upload. OpenAI recommends limiting user input and output tokens as safeguards against misuse and prompt injection [20]; the same limits also cap each request’s cost, which is BuildAIQ’s point rather than OpenAI’s. OWASP recommends input size validation and estimating tokens before a request is sent, so oversized ones can be rejected [8]. Anthropic, for one, offers a token-counting endpoint (an API address for one specific job) that estimates input tokens in advance; it’s free but rate-limited [21].
- Use caching where prompts repeat, and check that it pays. Caching lets a provider reuse work on the opening part of a prompt it has recently processed. OpenAI’s prompt caching is on by default for supported models and works only when the whole opening part of a prompt matches an earlier request [7]. On its GPT-5.6 and later models, writing to the cache costs more than ordinary input, so caching saves money only when that opening is reused [7]. Google says implicit caching is on by default for Gemini 2.5 and newer models and suggests putting large, common content first [22].
- Test on a small sample first. Send a handful of realistic requests and read the token counts that come back; OpenAI notes its API and playground return them with each response [12]. BuildAIQ’s guide to estimating the running costs of an AI app shows how to turn those counts into a monthly figure.
- Limit each of your users. A monthly cap protects your account, not your other users: one heavy user or one script could use it all. OWASP recommends rate limits and user quotas that restrict how many requests a single source can make in a given period [8]. That might be a daily request count or token allowance per account in your app.
- Protect the key. OWASP lists stolen credentials among the ways attackers run up costs on pay-per-use AI services, so treat the key like money and follow protecting your API key [8].
- Watch usage, knowing it lags. OpenAI’s usage dashboard shows token usage for current and past billing cycles [12]; check yours daily after any change, allowing for the reporting delays above.
Loops and Runaway Retries
A loop here is code or a workflow that keeps sending a request with no stopping point; a retry is an automatic second attempt after a failure. Both multiply a bill when nothing limits them.
Retries can happen without your writing any. OpenAI’s official Python library retries certain errors, including 429 responses, twice by default, and its max_retries option changes or disables that [10]. Anthropic says its official SDK retries transient failures, rate limits among them, twice by default, also configurable with max_retries [11]. The risk is wrapping that in a retry loop of your own with no end.
Retrying a billing error doesn’t help. OpenAI says retrying billing, spend or quota errors won’t restore API access; the credits or limits have to change first [9]. Anthropic says its tier spend-cap 429 keeps failing until access resumes [11]. Since OpenAI’s 429 covers both rate limits and exhausted credit, it tells developers to read the error code [9].
A timeout, the point at which your app stops waiting for a reply, can cost money too. Anthropic says failed requests aren’t charged, but one that was on track to succeed is still charged if your client disconnects or times out partway [17]. A too-short timeout plus an automatic retry can therefore mean paying twice; that’s BuildAIQ’s inference from Anthropic’s rule, and other providers weren’t checked.
No-code tools have retry settings as well. n8n’s node documentation describes Retry On Fail as rerunning a failed node until it succeeds, and that page doesn’t mention a cap [23]. Check what your tool’s retry option does before switching it on; connecting an AI API to a no-code tool covers the rest of that setup.
A 2019 Amazon Builders’ Library essay by AWS engineer Marc Brooker recommends limiting the number of retries, waiting longer between them, and retrying at one point rather than at every layer, because retries at each layer multiply [24]. BuildAIQ adds one guard: a hard count of requests per job, after which the job stops and reports an error. AI agents need step, time and per-run limits of their own, which BuildAIQ’s guide to setting spending, time and usage limits for an AI agent covers.
Example: A Weekend Project That Wouldn’t Stop (Hypothetical)
This scenario is invented to show which controls act; no costs are estimated. Imagine a hobby app that summarizes articles you’ve saved. On Friday evening you deploy a change with a bug: the app never marks an article as summarized, so a scheduled job resends the same one every minute. Nobody looks until Monday.
- Only an alert: an email arrives once spending passes your alert amount, and the requests keep going all weekend [1, 5].
- A hard limit or spend cap: requests start failing once tracked spending reaches the cap, plus whatever slips through during the enforcement delay [1, 3, 4]. The bill stops near an amount you chose.
- Prepaid credit, auto-reload on, no monthly reload limit: the balance runs down, auto-reload buys more, and the loop continues [2]. With a monthly reload limit, purchases stop there, and requests fail once the remaining credit runs out, after the usual delay [2, 3].
- A maximum output length: a plain text request costs no more than its input plus the capped output, but nothing limits how many requests go out [6].
- A separate project for the scheduled job: the runaway job hits that project’s smaller limit while the rest of the app carries on [12].
The fix at the source is the per-job request counter described above, which stops a bug like this after a set number of attempts; provider limits are the backstop.
What We Know, What We Don’t, and Where Experts Disagree
What We Know
On pages read November 22, 2026, the providers and platforms covered here document which of their controls block requests and, for several, which only notify; OpenAI, Google and AWS also describe delays that let spending run past a limit or an alert [1, 2, 3, 4, 13, 14, 16].
What We Don’t Know
Research for this guide found no independent data on how often loops, retries or leaked keys cause surprise bills, so no frequency is given. Some controls are new and may change: Google labels AI Studio’s project spend caps experimental, and Microsoft’s Foundry cost controls are in public preview [3, 15]. This guide didn’t verify Amazon Bedrock-specific spending caps, or whether Anthropic and the Gemini API offer alert-only settings of their own.
What Experts Disagree About
No named experts in this research take opposite sides, but the sources weigh the trade-off differently. OWASP treats a cap that halts inference as the safeguard and an alert as too slow on its own [8]. OpenAI documents both and warns that a hard limit can interrupt production traffic [1]. The amount you pick has to balance both: low enough to contain a runaway bill, high enough not to cut off real users.
Practical Takeaways
- Before real traffic, confirm your limit blocks requests rather than only alerting, set it well below what you can afford, and check auto-reload.
- Test in a separate project with a smaller limit, on a small sample first.
- Cap output length (leaving reasoning models room to answer), input size, retries, requests per job and each user’s allowance.
- Read the error code before retrying, and check usage daily after any change.
You now have provider limits that actually stop spending and guards that keep each request, job and user bounded. Next, rate limits, a separate kind of cap on how many requests or tokens you can send per minute or per day.
Sources
- Spend limits. OpenAI, accessed 2026-11-22.
- Setting up and managing prepaid API billing. OpenAI, 2026-11, accessed 2026-11-22.
- Billing. Google (Gemini API documentation), accessed 2026-11-22.
- Manage spend cap budgets. Google Cloud, 2026-11-10, accessed 2026-11-22.
- Create, edit, or delete budgets and budget alerts. Google Cloud, 2026-11-10, accessed 2026-11-22.
- Reasoning models. OpenAI, accessed 2026-11-22.
- Prompt caching. OpenAI, accessed 2026-11-22.
- OWASP Top 10 for LLM Applications 2026. OWASP Gen AI Security Project, 2026-08-03, accessed 2026-11-22.
- Error codes. OpenAI, accessed 2026-11-22.
- OpenAI Python API library (README). OpenAI, accessed 2026-11-22.
- Errors. Anthropic, accessed 2026-11-22.
- Production best practices. OpenAI, accessed 2026-11-22.
- Rate limits. Anthropic, accessed 2026-11-22.
- Tutorial – Create and manage budgets – Microsoft Cost Management. Microsoft Learn, 2025-06-26, accessed 2026-11-22.
- Cost and FinOps overview – Microsoft Foundry. Microsoft Learn, 2026-11-09, accessed 2026-11-22.
- Managing your costs with AWS Budgets. Amazon Web Services, accessed 2026-11-22.
- How do I pay for my Claude API usage?. Anthropic (Claude Help Center), accessed 2026-11-22.
- Text generation. Google (Gemini API documentation), accessed 2026-11-22.
- Create a Message. Anthropic, accessed 2026-11-22.
- Safety best practices. OpenAI, accessed 2026-11-22.
- Token counting. Anthropic, accessed 2026-11-22.
- Context caching. Google (Gemini API documentation), accessed 2026-11-22.
- Work with nodes. n8n, accessed 2026-11-22.
- Timeouts, retries, and backoff with jitter. Amazon Web Services (Amazon Builders' Library, AWS Builder Center), 2019-12-05, accessed 2026-11-22.
