Stop Agents from Burning Your API Budget Overnight
In an illustrative coding-agent scenario, an ambiguous error leads to 240 iterations over three hours. At the stated flat averages and model rates, the loop costs $52.80.
The model pricing was exactly right. The call volume was not.
Why existing controls didn't help
Provider cost controls vary across soft project budgets, prepaid credits, account limits, and throughput quotas. They can isolate traffic when you assign separate provider identities, but a shared project or key does not infer your production run, staging test, or application tenant.
Rate limits control how fast, not how much. The agent stayed within its requests-per-second limit. It was making perfectly well-formed API calls. Just 240 of them.
Observability dashboards showed the spike — the next morning. The cost graph was a vertical line at 2 AM. Useful for the post-mortem. Useless for prevention.
How Cycles fixes it
from runcycles import cycles
@cycles(estimate=2_000_000, action_kind="llm.completion", action_name="gpt-4o")
def call_llm(prompt: str) -> str:
return openai.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": prompt}],
).choices[0].message.contentFor this decorated function, the wrapper reserves budget before invoking the model. If the live reservation fails for insufficient budget, it raises BudgetExceededError and does not call the wrapped model. Other call paths remain unprotected unless they use the same mandatory boundary.
Under the source scenario's flat-average assumptions, a $15 workflow ledger keyed to that run rejects a protected call around iteration 68. The host can surface: "Budget exhausted. This task needs human review."
What happens now
- Budget checked before every decorated call. The wrapped model call does not execute when its live reservation fails; complete path coverage, estimate accuracy, settlement, and overage policy still matter.
- Graceful degradation, not a crash. The agent can catch
BudgetExceededErrorand wind down: summarize progress, switch to a cheaper model, or queue the task for later. - Run-scope isolation. If the application provisions distinct budget subjects for each run and routes every protected call correctly, a runaway in run #47 cannot consume run #48's allocation.
- The configured bound surfaces sooner. A $15 limit rejects a later protected call instead of allowing all 240 modeled iterations.
The math
| Without Cycles | With Cycles ($15/run cap) | |
|---|---|---|
| Agent loops | 240 | About 68 under flat-average assumptions |
| Cost | $52.80 | Near $15, subject to estimates and settlement |
| Time to detect | Next morning | Immediately |
| Impact on other agents | Depends on the shared provider cap | Contained when scopes and routing are configured correctly |
| Recovery action | Post-mortem and budget reset | Fix the prompt |
Now run the numbers for your workload
The calculator below is pre-seeded with a separate, larger-context retry-loop profile — 200K input tokens and 10K output tokens per call, 240 calls. It is not the source scenario's input. Adjust the tokens, call count, and model rates to match your workload. Click Share to send the configured view to a teammate, or PNG for an artifact you can paste into a deck.
USD · Standard API rates · GPT rates assume at most 272K input tokens per call. For longer prompts, enter the provider's long-context rates manually.
| Model | Input $ / M | Output $ / M | Per call | Per day | Per month | Per year | |
|---|---|---|---|---|---|---|---|
| $0.0600 | $600 | $18,000 | $219,000 | ||||
| $0.0120 | $120 | $3,600 | $43,800 | ||||
| $0.0006 | $6.00 | $180 | $2,190 | ||||
| $0.0120 | $120 | $3,600 | $43,800 | ||||
| $0.0600 | $600 | $18,000 | $219,000 | ||||
| $0.0240 | $240 | $7,200 | $87,600 | ||||
| $0.0120 | $120 | $3,600 | $43,800 | ||||
| $0.0060 | $60.00 | $1,800 | $21,900 |
Default rates last verified on 2026-09-30 against OpenAI and Anthropic; edit any cell to match your contracted rate. Shared links keep their saved rates, which may be older. Calculation: (input_tokens × input_$/M + output_tokens × output_$/M) ÷ 1,000,000 × calls/day. Excludes cache reads/writes, batch/flex discounts, fine-tuning, fast/ultrafast modes, tool fees, and data-residency premiums. Rates do not adjust automatically for long context: above 272K input tokens, the listed GPT models charge 2× input and 1.5× output rates. Claude Fable 5.1, Opus 5.5, and Sonnet 5.5 retain standard rates across their 1M context windows. Haiku 4.5 has a 200K context window; check model limits before budgeting a request. Include billed reasoning/thinking tokens in output totals. Token counts vary by tokenizer; the same text can use different token counts across models.
Go deeper
- LLM Cost Runtime Control Reference — the full topic guide: incident taxonomy, runtime authority patterns, multi-tenant isolation, unit economics, and rollout
- End-to-End Tutorial — zero to budget-guarded LLM call in 10 minutes
- Cost Estimation Cheat Sheet — how much to reserve per model
- Degradation Paths — what to do when budget runs out
- 5 Agent Cost Failures Runtime Budgets Can Bound — illustrative scenarios with checked dollar math
- Why Rate Limits Are Not Enough — the deeper argument