In the FinOps for AI guide
Limits at every level, and alerts measured in hours
How do you prevent AI cost spikes?
You prevent AI cost spikes with guardrails at 5 levels: limits on each request, a budget for each task, a spend limit on each key, anomaly alerts that fire within hours, and budget alerts for each use case. Each level catches what the one before it misses. Together they turn a surprise on the monthly invoice into an alert to the right person the same day. The aim is not to stop AI use. It is to make sure nothing runs unwatched.
AI spikes are common. In a 2026 Harness survey, 72% of respondents had an unexpected AI cost spike in the past year, a third had more than one, and 79% said tracing a spike to its source would take a full day or longer.
Why AI spikes happen
| Cause | What it looks like |
|---|---|
| An agent stuck in a loop | The same step repeated thousands of times, each call costing more as context grows |
| A prompt or code change | Every request suddenly carries more context, or makes more calls |
| A model upgrade | Same volume, higher price per token, or more tokens per task |
| Caching stops working | A small change to the start of a request breaks the cache, and input cost jumps |
| A successful launch | Real demand, higher than planned. A good spike, but still a budget problem |
| A leaked or misused key | Usage from somewhere it should not be |
| A batch job sent to real time | The same work at twice the price |
Most are not malicious and not even mistakes in the usual sense. They are normal changes whose cost nobody checked.
Worked example: a $14,000 weekend
Halden Freight is the fictional logistics company used across these guides. Its analytics agents normally cost about $600 a day.
On a Friday evening, a change to a database table broke a query the agents used. One agent kept retrying it, each time adding the error to its context and trying a variation. Each attempt cost a little more than the last. By Sunday morning it had made about 9,000 attempts over 40 hours and spent about $14,000, more than 3 weeks of normal spend. The finance team found it 2 weeks later, on the invoice.
Here is what each guardrail would have done:
| Guardrail | Setting | When it would have stopped the loop | Cost |
|---|---|---|---|
| Step limit per task | 25 steps per task | After 25 attempts | About $40 |
| Budget per task | $20 per analysis run | After about 13 attempts | About $20 |
| Daily spend limit on the key | $1,200 a day, twice normal | About 4 hours in | About $1,200 |
| Hourly anomaly alert | 3 times the usual hourly spend | Within the first hour, to the owner | Depends on response |
| Monthly use case budget | $18,500 a month | Days later | Most of the $14,000 |
Any one of the first 3 would have kept it to a rounding error. Halden had none of them. It now has all 5.
The 5 layers
1. Limits on each request
Set a maximum output length on every call, and a timeout. These are simple settings in every provider's API and in most gateways. They stop a single request from running away.
2. A budget for each task
For agents and multi-step workflows, set a maximum number of steps and a maximum cost per task. When either is reached, the task stops and hands off to a person or fails cleanly. This is the guardrail that stops loops. It belongs in the application or the agent framework, and it is the most often missing. See the cost of AI agents.
3. A spend limit on each key
Give every use case its own key, and set a daily and monthly limit on each, usually at about twice normal spend. Most gateways and provider consoles support this. Decide in advance what happens at the limit: block, slow down, or alert only. For customer-facing use cases, alerting may be safer than blocking.
4. Anomaly alerts within hours
Compare each use case's hourly cost with its usual pattern for that hour and day, and alert its owner when it moves outside the range. A fixed threshold is a start. A pattern-based one catches more with fewer false alarms. Send alerts to the owner of the use case, not to a shared channel nobody watches.
5. Budgets for each use case
Give every use case a monthly budget and alert at 50%, 80%, and 100%. This layer is too slow to stop a spike, but it catches gradual drift, such as context slowly growing, that the faster layers miss.
When an alert fires
- Contain. Pause or throttle the key if the cost is still climbing. For a customer-facing use case, switch to a fallback rather than turning it off.
- Find the cause. Check what changed: code, prompts, models, data, or volume. Gateway logs by use case and model make this a matter of minutes.
- Fix and record. Fix the cause, and write down what happened and what it cost.
- Add the missing guardrail. Every spike should leave behind the limit that would have caught it sooner.
Guardrails without friction
Guardrails slow nobody down if they are set sensibly. New use cases start with conservative defaults that owners can raise with a reason. Experiments get a fixed budget and an end date. Production use cases get limits based on their real pattern after a few weeks. Nothing needs approval to start, and nothing runs without a limit.
Governing what AI is allowed to do, rather than what it is allowed to spend, is covered in the AI governance guide.
Questions leaders ask
What causes AI cost spikes?
Most often an agent stuck in a loop, a prompt or code change that adds context or calls, a model upgrade, caching that stops working, or simply higher demand than planned. Leaked keys and batch jobs accidentally run in real time are less common causes. Most are normal changes whose cost nobody checked first.
How do you set spend limits for AI?
Give every use case its own key and set a daily and monthly limit on it, usually at about twice normal spend, in your gateway or provider console. For agents, also set a maximum number of steps and a maximum cost per task in the application, so a single stuck task stops quickly.
How do you detect AI cost anomalies?
Track each use case's cost by the hour and compare it with its usual pattern for that time and day. Alert the owner when it moves outside the normal range. A gateway that tags every request with a use case makes both detection and diagnosis fast.
How do you stop an AI agent loop from running up costs?
Set a maximum number of steps and a maximum cost for each task, so the agent stops or hands off to a person when either is reached. Add a daily spend limit on the agent's key as a backstop, and an hourly alert to its owner.
Should AI spend limits block requests?
For internal tools and agents, usually yes, because a blocked task costs less than a runaway one. For customer-facing use cases, blocking can do more harm than the cost, so alert and throttle instead, or switch to a cheaper fallback model when the limit is reached.
Keep going
- Free toolsFree FinOps for AI calculators and templates6 tools and 2 downloads, free to use
- The TBM guideWhat is Technology Business Management (TBM)?A way to run technology like a business
- The Operating model guideWhat is an operating model?How a company is set up to deliver its strategy
Last reviewed