Own Weights

Why your AI API bill spiked and how to stop it

Why is my OpenAI bill so high? Find the retry loops, leaked keys and growing prompts behind a spike, then set spend caps and budget alerts that stop it.

Updated

Your OpenAI bill is high because your app sends more calls or more tokens than you planned for. The usual causes are a retry or loop that repeats calls, an API key someone else is using, prompts that grew over time, and traffic that moved to a more expensive model. The same pattern shows up on Claude bills. Once the cause is fixed, cut OpenAI API costs at the source.

Find the cause in your usage log before you change any code. Then set spending caps, so the next surprise stops on its own instead of showing up on the invoice.

How do I find out what changed?

Open the usage page in your provider’s dashboard and filter by day and by model. Find the day the line jumped, then ask three questions. Did the number of calls rise? Did tokens per call rise? Did the model change? More calls points to a loop, a retry storm or a new feature. More tokens per call points to longer prompts. A model change points to a deploy or a config value that moved traffic to a pricier tier.

Use the usage view, not the invoice, which shows totals only. Rates change, so check your provider’s current pricing page.

Why do retries and loops multiply my bill?

A retry with no limit can multiply one request many times. Hypothetical example: a job calls the API, times out after 60 seconds, and retries up to five times. If 1,000 jobs each fail on every try, that is 6,000 paid calls instead of 1,000.

Check three things. Cap retries at two or three, with a growing delay between them. Retry only errors that can clear on their own, such as rate limits and server errors, not bad requests. Set a timeout on every call. Then search for API calls inside loops, especially loops over rows, pages or files, and agent steps that call a tool that calls the model again.

Could a leaked API key cause a huge AI bill?

Yes. Scrapers search public code for keys, so a key pushed to a public repo, sent in a front-end bundle or written into a log can be used by someone you do not know. The usage log often shows it: calls at hours nobody on your team works, calls to models nobody chose, or traffic on a key that should be idle.

Act in this order. Revoke the key first, then create a new one and store it in an environment variable or a secrets manager. Remove the old value from git history, not just the latest file, because deleting it from the newest commit leaves it in the older ones. Then check the usage log for the period before you revoked. The free AI cost audit flags API keys written into code, so it is a quick way to find the ones that are still in your repositories.

Why did AI API costs spike overnight?

Overnight spikes usually come from work that ran with nobody watching it. That is a batch job, a scheduled script, an agent with no step limit, or a retry loop that kept going after the office closed. A deploy can also cause one. A change that adds a long document or a full chat history to every prompt multiplies input tokens without raising any error.

Compare calls by hour and by key for the night in question. The hour the line starts climbing usually points to the job. Then compare tokens per call before and after the deploy. Prompt growth often shows up as a slow rise over weeks, so look at a longer window too. Output tokens cost more than input tokens. On Claude’s list prices, Opus is $4 per million input tokens and $20 per million output tokens, and Haiku is $0.10 input and $0.50 output for prompts up to 100K tokens. If a job does not need an answer in real time, Anthropic’s Batch API is half price. For long prompts, see long context costs and prompt caching.

How do I set spend limits and LLM API budget alerts?

The first control is a hard limit: a monthly budget that stops calls when it is reached. To set that number, forecast AI spend from its drivers. Most providers offer usage limits in their dashboard. If you run your own gateway, add a budget per key or per feature there too.

The second is an alert. Set one below the hard limit, for example at 50% and 80% of the monthly budget. Add an alert on the change from one day to the next. A day running well above the normal rate shows up within a day, while the monthly total may not cross a threshold until much of the money is gone.

A hard limit has a cost. When it trips, your product stops making calls. Decide the behavior first: queue the work, send that feature to a cheaper model, or show the user a clear error. Tag each call with the feature that made it, so an alert tells you which part of the product to look at. See LLM cost attribution.

When is paying per call the wrong choice?

If your bill keeps rising with volume, the cost is in the per-call price, and caps only slow the rise. For one narrow, high-volume task, a fine-tuned open-weight model can be the cheaper option. In our own test, the extraction exam used 510 commercial contracts, scored with 5-fold cross-validation. Our Accuracy model scored 0.717 and our Standard model scored 0.650. Claude Opus scored 0.635 and Claude Haiku scored 0.584, so both of our models finished ahead of both Claude models on that exam. Claude took that exam with one prompt, no examples and no training for the task. Our models were fine-tuned for it. That shows what training for one task does. It is not legal advice, and it does not mean a fine-tuned model beats Claude at everything.

Measured at list price on 102 held-out contracts from the same exam, the cost was $4.50 per 1,000 documents for our Accuracy tier, $3.54 for our Standard tier, $4.95 for Claude Haiku and $154.49 for Claude Opus for the tokens it used. Full results are on the benchmark page.

Fine-tuning is the wrong choice when your tasks vary a lot, when volume is low, or when you have no labeled examples and no test set to prove a new model is better. In those cases keep the API, cap spend and fix the calls first.

If you want a second look at where your spend goes, run the free AI cost audit or book a call through the home page.

Questions

why is my openai bill so high

It is usually one of four things: more calls, more tokens per call, a more expensive model, or a key that someone else is using. The usage view in your provider's dashboard, filtered by day and model, shows which one moved. Check the current pricing page for your provider's rates.

ai api costs spiked overnight

Overnight spikes usually come from unattended work such as a batch job, a scheduled script or an agent with no step limit. Compare calls by hour and by key for that night to find where the line starts to climb.

api key leaked huge ai bill

Revoke the exposed key before anything else, then issue a new one from a secrets store. Check the usage log for the period before revocation, since the bill often covers calls you did not make.

how to set spend limits on an llm api

Use the usage limit settings in your provider's dashboard, and add a budget per key or per feature if you run your own gateway. Decide what the product does when the limit trips before you switch it on.

llm api budget alerts

Set alerts at two or three levels of the monthly budget, plus one on the change from one day to the next. Tag each call with its feature so an alert points to the part of the product that caused it.