In this guide · 8 sections
- 01Why AI API bills surprise small businesses
- 02Spend limits by provider (OpenAI, Anthropic, Gemini)
- 03Set up spend limits step by step
- 04API key safety: scoping, storage and rotation
- 05Protect a public chatbot from abuse
- 06A weekly monitoring routine
- 07Do it yourself or get help?
- 08Frequently asked questions
Short answer
Set a hard monthly spend limit for each project (OpenAI and Gemini) or organisation (Anthropic), plus alerts at lower amounts. Use one key per app, keep keys on the server never in browser or app code, rotate them, and check usage weekly. Limits aren't instant, so leave headroom.
Why AI API bills surprise small businesses
Most AI API costs are tiny per request, which is why nobody watches them. Problems come from volume you didn't plan for.
- Leaked key: a key pasted into website JavaScript, a public code repository or a shared document gets found and used by others.
- Runaway loop: an automation or agent that retries endlessly, or calls the model on every page view.
- Abuse of a public chatbot: someone uses your website assistant as a free general-purpose AI.
- Expensive model by default: a developer tested with the top model and nobody switched it back.
- Long context: every request sends a whole document or chat history, multiplying input tokens.
To estimate what normal usage should cost, see our guides to LLM token costs per customer reply and API pricing per token. Knowing the normal number is what makes an alert useful.
Spend limits by provider (OpenAI, Anthropic, Gemini)
All three providers now separate notification-only alerts from limits that actually stop traffic. The details differ.
| Provider | Hard cap you can set | Alerts | Things to know |
|---|---|---|---|
| OpenAI | Monthly hard limit per organisation and per project | Spend alerts at thresholds you choose | At the limit, requests fail with a 429 error; enforcement isn't instant |
| Anthropic (Claude) | Your own monthly spend limit below your tier's cap | Usage and cost in the Console; Admin API for reporting | Usage tiers carry their own monthly spend caps; workspaces separate projects |
| Google Gemini API | Monthly spend cap per project in AI Studio | Plus billing-account tier caps | Billing data can lag around 10 minutes; batch and agent jobs may overrun |
Sources: OpenAI's spend limits guide, Anthropic's rate and spend limits page and Google's Gemini API billing page. OpenAI notes that enforcement "is not instantaneous", so recorded spend can slightly exceed the limit; Google says the same about billing data delays.
Set up spend limits step by step
The same pattern works on each platform. Do it before the AI feature goes live.
Create a project or workspace per app
One for the website chatbot, one for internal tools, one for testing. OpenAI uses projects, Anthropic uses workspaces, Gemini uses Google Cloud projects in AI Studio.
Estimate normal monthly spend
Multiply expected requests by average tokens and the model's price. Set the hard limit at roughly two to three times that, so a busy month still works but a leak doesn't drain the account.
Turn on the hard limit
OpenAI: Project settings, Limits, Edit spend limit, Enforce a hard limit. Gemini: AI Studio, Spend, Monthly spend cap. Anthropic: Console, Billing, set your own spend limit.
Add alerts below the limit
For example at 50% and 80% of the limit, sent to a shared mailbox that someone reads, not one developer's inbox.
Plan what happens at the limit
Your app should handle the 429 error gracefully, for example showing "Our assistant is unavailable, please WhatsApp us" rather than breaking the page.
API key safety: scoping, storage and rotation
Spend limits cap the damage; good key handling prevents it. OpenAI's API key safety article lists the basics: a unique key per team member, never deploying keys in browsers or mobile apps, secure storage, monitoring, rotation and IP restrictions. Administrators can also enforce a maximum key lifetime.
API key checklist
AI-generated code is a common source of leaks, because quick prototypes often put the key straight into the front end. Our vibe-coding risks guide covers this and other security gaps in AI-built apps.
Protect a public chatbot from abuse
A chatbot on your website is a public door to a paid API. Even with a spend cap, abuse can exhaust your budget and take the bot offline for real customers.
Controls that help
- Rate limit per visitor or IP on your server
- Cap message length and conversation length
- System prompt that keeps the bot on your business topics
- A cheaper model for routine questions
- Bot protection (such as a challenge) on the chat endpoint
Set-ups that invite abuse
- Browser calling the AI provider directly with your key
- Unlimited conversation history sent with every message
- No per-visitor limits
- Top-tier model for every greeting and FAQ
- Nobody reviewing usage after launch
A weekly monitoring routine
Five minutes a week is enough for most small businesses.
- Open each provider's usage dashboard and compare this week's spend with last week's.
- Check spend per project or key; a sudden jump on one key points to the cause.
- Look at which models are being used; an expensive model appearing unexpectedly is a red flag.
- Confirm alerts still go to a monitored address.
- If something looks wrong, revoke the key first and investigate second.
If a key has leaked, revoke it immediately, create a new one, update the app, check usage logs for when the misuse started, and contact the provider's support about unexpected charges.
Do it yourself or get help?
Setting spend limits and alerts takes minutes and every business using AI APIs should do it now. Help is worth it when an app was built quickly with keys in the front end, when you need a server-side proxy with rate limits, or when you aren't sure where keys have been copied.
Our Security Health Check (S$290) reviews where keys are stored, who has access and what limits are set. For a properly built AI feature with server-side keys, rate limits and usage reporting, our Custom Tool or Dashboard service starts at S$1,990.
Frequently asked questions
Yes. OpenAI supports monthly hard spend limits at organisation and project level. Once tracked spend reaches the limit, requests fail with a 429 error until you raise the limit or the next month starts. Spend alerts are separate and only send notifications. OpenAI notes enforcement isn't instantaneous, so spend can slightly exceed the limit.
Yes. Google's Gemini API documentation describes monthly spend caps you can set per project in AI Studio, plus caps tied to your billing account's usage tier. Google warns that billing data can be delayed by around 10 minutes, and long-running batch or agent jobs may go over the project cap.
No. Anyone can read a key in browser code and use it on your account. OpenAI's key safety guidance says never to deploy keys in client-side environments such as browsers or mobile apps. Route requests through your own server, which holds the key and can apply rate limits.
Revoke the key straight away in the provider's console, create a replacement and update your app. Check usage logs to see when unusual activity started and which models were used, then contact the provider's support about charges. Review how the key leaked, often a public repository or front-end code, and fix that.
Estimate normal monthly spend from expected requests, average tokens and model prices, then set the hard limit at roughly two to three times that. Add alerts at about half and 80% of the limit. That leaves room for a busy month while stopping a leaked key or loop from running unchecked.