A $37 bill taught me to put spending limits on my AI agents

Originally published on dyordo.com.

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 agent asks. It doesn't just spend.

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 watch for anomalies

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.

On top of that, an unusual call rate, failure rate or spend speed freezes the account. The cheapest version is one condition: the agent 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.

Three things to do this week

  1. List every paid service your agents call and what each costs per month. The total is usually higher than you think.
  2. Give each main agent one budget number, then enforce it in code, not in a note.
  3. One agent, one API key. Separate bills, separate limits, and you can shut one down without touching the others.

This takes under an hour.

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.

添加评论
点赞收藏
点踩分享查看原文
评论
?
参与讨论