cocodot
← Back to guides
Local card declined, direct access hard? cocodot does both
Cost ControlUpdated 2026-09

How an AI Agent Burns Hundreds of Dollars Overnight, and Five Guardrails That Stop It

The defining property of an agent is that it chooses its own call count. Three failure modes account for nearly every runaway bill, and the five guardrails that prevent them are each about a dozen lines of code.

TL;DR: Ordinary API calls have a count you set. An agent decides its own, which is the entire difference. Three failure modes cause nearly all runaway bills: **(1) unbounded retries** — failure triggers another attempt with no ceiling; **(2) the context snowball** — every turn carries the full history, so turn fifty costs many times turn one for identical work; **(3) agents talking to each other** with no stop condition. Five guardrails: a hard step limit, a per-task spend ceiling, context trimming, tiered models, and a small-sample load test before launch. **Each is roughly a dozen lines, and together they are the difference between a normal week and a several-hundred-dollar incident.**

The context snowball is the one that hides

Runaway loops are obvious in logs — the same call, over and over. The snowball is not. The agent is doing genuinely different work each turn, so nothing looks wrong, but each turn carries everything before it. Cost per turn rises steadily while progress looks normal. Watch cost per step over time, not just total spend, and this becomes visible early instead of on the invoice.

A spend ceiling beats a step limit

Step limits are the obvious guardrail and they are not sufficient, because steps are not uniform in cost. Fifty cheap steps and fifty expensive ones hit the same limit at wildly different bills. A per-task spend ceiling caps the thing you actually care about, and it keeps working when someone later changes the model or the prompt size. Set both, but if you only implement one, make it the spend ceiling.

Tiered models are a safety feature, not just a saving

Routing routine steps to a cheap model is usually framed as cost optimization. It is also containment: when something does spin, it spins at a fraction of the rate, which converts a serious incident into a noticeable one. Reserve the expensive tier for the specific steps that need it and a runaway becomes survivable.

Load test on a small sample before launch

Run the agent against a representative sample and record the token count per task before it touches real volume. This gives you a real per-task cost to set your ceiling from, and it surfaces loops that only appear on inputs you did not think about. An afternoon here is cheaper than the first bad night.

Make anomalies surface themselves

Alert on daily spend and on cost per task, not on monthly totals. Monthly numbers tell you about an incident well after it finished. A simple threshold on daily spend catches the overnight case, which is precisely the one that hurts, because nobody is watching when it happens.

Failure modes and the guardrail that catches each

Failure modeHow it shows upGuardrail
Unbounded retriesSame call repeating in the logsHard step limit per task
Context snowballCost per turn climbing while the work stays the sameTrim or summarize history
Agents looping on each otherTwo components exchanging messages indefinitelySpend ceiling per task

FAQ

What is a reasonable per-task spend ceiling?

Measure your typical task cost on a small sample, then set the ceiling at several times that. The goal is not to clip normal work — it is to make the pathological case stop on its own.

Do guardrails make the agent less capable?

A ceiling that stops a task which was going to fail anyway costs you nothing. If you find limits clipping successful runs, raise them — the point is bounding the tail, not constraining normal operation.

About cocodot

cocodot is a payment and AI access service for developers and cross-border teams in mainland China. It provides US-BIN virtual cards issued by a licensed institution — used to pay for overseas subscriptions and ad accounts — and an OpenAI-compatible AI API gateway for calling Claude, GPT and Gemini from within mainland China. Both share one wallet, funded by Alipay and accounted in USD. Card: $9.9 to open, 3% to load, 0% on spend, $1 per active card per month.

Service scope, pricing and limits →
How an AI Agent Burns Hundreds of Dollars Overnight, and Five Guardrails That Stop It · cocodot