Updated Oct 2026: a reader, skillselion, pointed out four gaps in the first version in the comments on the dev.to version of this post. The anomaly rule had no threshold, failed calls can still bill, the escalation rule left approval inside the agent, and one key per agent means little if subprocesses inherit the environment. The sections on escalation, anomalies and key isolation are rewritten below. Thanks for the careful read.
Last month I gave a research agent an API key with a shared limit and pointed it at a competitor-monitoring job. The job was small: at most 50 calls a day, each costing a fraction of a cent.
On the third night the bill said $37 for one day.
A subtask had fallen into an error loop. Call fails, agent tweaks a parameter, retries, fails again. My 50-call cap didn’t stop it, because each endpoint had its own quota and my limit didn’t cover all of them.
$37 is not a disaster. But it showed me I had never designed how my agents spend money. I had given each one a card that works, not an account with a budget.
Here is what I do now. None of it needs new infrastructure.
Split the budget by purpose
One monthly number per agent is too blunt. I use three buckets:
- Exploration: $5 to $20 a week for trying APIs. When it’s gone, the agent waits until next week.
- Project: a fixed amount loaded for one task, like $10 to scrape pricing for a list of competitors. Unspent money comes back when the task ends.
- Escalation: anything above the threshold needs my approval. The threshold lives at the key or proxy layer, not in the agent’s prompt. In the first version I wrote “the agent asks.” That puts the approval inside the thing that broke. The loop that blew past my 50-call cap ran on the agent side, and it would have been just as happy to stop asking. When the proxy refuses the charge, the agent has nothing to decide.
Set the limit before the agent starts. Trimming after it overspends teaches it nothing.
Allow-list, don’t block-list
I used to allow everything and block bad services as they showed up. Every new service was a new risk, and I was always behind.
Now nothing is allowed by default:
- Start with services you already trust, like OpenAI, Anthropic and your existing data sources.
- Add new ones one at a time, after checking them.
- If an agent wants a new service, it requests it.
The allow-list also carries numbers. I cap spend per call and per day. A rule like “max $5 a day, 200 calls a day” would have killed my retry loop in round three.
Cap single transactions and trip on failures
A healthy total says nothing about one transaction. Every agent account I run has a hard rule: any single charge over $2 goes to a human. That rule is enforced by the proxy that holds the key, not by the agent.
A daily cap, in dollars or calls, only stops a loop after it has spent whatever you set. The anomaly rule is the one that would have caught my $37 night, and the first version of this post gave it no number. Here is the rule with a number on it.
Trip on consecutive failures per endpoint. My example threshold is 3 consecutive failures on the same endpoint, then the account freezes until I look at it. Pick your own number; 3 is a starting point, not a measured value. Count per endpoint, not per call signature. My agent tweaked a parameter between retries, so a counter keyed on the parameters sees a new key every time and never reaches 3.
Watch spend, not just successes. If the calls go to a model API, a failure from the agent’s point of view can still be billed. A successful model response that the agent cannot use may still incur token charges. A client timeout also does not prove that the server stopped processing the request. Whether either case is billed depends on the provider and how far the request got; check the provider’s usage and billing records rather than treating every agent-side failure as free or every API error as billable. So a retry loop can burn real money while the success counter sits at zero. That’s how 50 expected calls a day turns into a $37 bill. The breaker should also trip on spend speed: for example, more than $1 in 10 minutes from an agent whose normal day is cents. Again, that’s an example figure. Set it from your own bills.
The cheapest version is still one condition, checked outside the agent: it can spend only if budget > 0 and no anomaly flag is set.
Give the agent a visible owner
When an agent calls third-party services, it should say who it works for, for example a handle like yourname.cloudflare.pay, instead of showing up as an anonymous account.
Merchants are more likely to hand out trial credits to an agent with a known owner, and more likely to email you than ban you when something looks off. Same reason people trust yourname.com and not a bare IP and port. I wrote about domains as trust assets in my Dynadot review.
Three things to do this week
- List every paid service your agents call and what each costs per month. The total is usually higher than you think.
- Give each main agent one budget number, then enforce it in code, not in a note.
- One agent, one API key, and make sure the boundary is real. If the agent shells out to tools or skills that inherit the parent environment, every key in that shell is reachable from the subprocess. Then “one key per agent” is a naming convention, not a limit. Three ways to make it a limit: give each agent a scoped key with its own spend cap at the provider; run tools in a sandbox with a clean environment that only gets the variables they need; or keep the real keys in a proxy and give the agent a token that only works through it, so the cap and the $2 rule are enforced there.
The first two take under an hour. The third takes longer if your tools share one shell, and it’s the one that matters most.
Hard limits buy you freedom
With a $10 cap, I can let an agent try 50 services without watching any of them. With a $1,000 account and no cap, I check the bill at 2 a.m.
That’s why I like Cloudflare’s two-tier wallet design: it turns “do I trust this agent?” into “what’s the cap?”
On a normal day, a well-limited agent system shows the occasional “budget exhausted, paused” notice. You top it up or adjust it and move on. You don’t wake up and open the bill first.
Prices and policies change. Check official docs before you buy anything.
More: AI Agents Can Finally Pay for Things, Can AI Agents Buy Their Own eSIM.