How to Stop Your OpenAI API Bill From Spiking
June 18, 2026 · 7 min read
A step-by-step playbook to prevent a surprise OpenAI or Anthropic bill: find the spend, cap the worst offenders, and get alerted before the invoice — not after.
The worst way to learn your AI feature has a cost bug is a five-figure invoice. If you want to prevent a surprise AI bill, you need three things in place before the spike happens: attribution, a hard cap, and an alert. Here's the playbook.
Step 1: Find out where the money actually goes
You cannot cap what you cannot see. Before touching limits, attribute spend to a feature, a model, and a user. Most teams are surprised: it's rarely spread evenly. Usually one feature and a handful of users dominate.
- Tag every call with a project/feature name and a user id.
- Record input and output tokens per call, and convert to cost with the model's current rates.
- Roll it up by feature and by user for the last 7 and 30 days.
Step 2: Cap the worst offenders
Once you know the top spenders, put a hard cap on them — a budget that rejects calls when hit, rather than a dashboard number you hope to notice. Start per-project, then add per-user ceilings for anything user-facing.
const guard = new Guard(openai, {
project: "support-bot",
cap: { monthly: 800, perUser: 3 },
});
const res = await guard.chat.completions.create({
model: "gpt-5",
messages,
});
// Past the budget this throws instead of spending.Step 3: Get alerted before the invoice
Caps stop catastrophe; alerts catch drift. Set an anomaly alert that fires when spend departs from its baseline — a sudden 3x on the summariser at 2am should page you in minutes, not surface on next month's statement. Details in AI budget alerts.
The usual culprits behind a spike
- A looping agent that retries and re-feeds context — see why agent costs compound.
- One abusive user hammering an unmetered endpoint. Fix with per-user rate limiting.
- A prompt change that quietly doubled input size across every request.
- A model swap to a pricier tier without re-checking the math.
Why provider limits aren't enough
OpenAI and Anthropic offer account-wide usage limits, but they're coarse: they can't cap a single feature or user, and hitting them takes your whole app down rather than degrading one flow. Real control lives at the project and user level, in your own code path.