Agents · July 11, 2026 · 3 min read
Set spend caps before your AI agents run overnight
An always-on agent with a paid API key is a surprise bill waiting to happen. Two layers of spend caps bound the damage before your first overnight run.
The problem
An always-on agent with a paid API key is a surprise bill waiting to happen. A misfiring cron or a runaway reasoning loop can fire thousands of API calls while you sleep, and there are real stories of agents that quietly burned hundreds of dollars in a day. The fix is two layers of spend caps: a hard limit at the provider that nothing in the agent can touch, and a daily cap in your own code checked before every model call.
How do you stop an agent from overspending overnight?
Layer 1 lives at the provider. Set a hard monthly limit and a billing alert in your Anthropic, OpenAI, or OpenRouter dashboard. That ceiling holds even when the agent misbehaves, because it sits outside anything the agent can read, write, or reason about. It is the one limit an agent cannot talk its way around.
Layer 2 lives in your code. In the member app I run, my community RAG coach, every request passes a spend check before the model is ever called: reserve the estimated cost against a per-user daily cap and a global daily cap, then reconcile with the actual cost after the call. The reserve is atomic, it locks the member’s daily usage row, so two concurrent requests cannot both squeeze under the limit. The per-user caps are sized so a maxed-out member still costs less per month than their subscription. Copy the pattern in any stack:
Before every model call:
1. Estimate the cost of this call.
2. Atomically add the estimate to today's running total.
3. If the total would cross the daily cap, refuse and log. Do not call.
4. After the call, replace the estimate with the actual cost.
A spend cap is a safety rail you chose in advance, not a budget you expect to hit.
The spend cap checklist for your first overnight run
- A hard limit and a billing alert at every provider the agent can call.
- The daily cap check above in front of every model call your code makes.
- No free payment method. If a workflow genuinely needs to buy something, route it through a card with a low limit or a manual approval step.
- Cheap models for the grunt work. Let the top model plan and a cheaper model build: routing lowers your average cost, and the caps bound your worst case.
Do this now
- Open your provider’s billing page and set a hard monthly limit plus an alert below it.
- Put the four-line cap check in front of every model call your agent makes.
- If the agent can buy anything, remove the saved card and add an approval step.