← All posts

Blog

Put a spending cap on your agents before you give them keys

A developer's AI agent got stuck in a loop and hit a paid API a few hundred thousand times. No cap, no alert. Fence the wallet before an agent gets a key.

2 min read

Put a spending cap on your agents before you give them keys

A developer called me and said, "Bryan, I think I screwed up."

The week before, I had given him access to a paid Google API. He wrote an AI agent to work with it, kicked it off, and went home.

The agent got stuck in a loop. It hit that API a few hundred thousand times before anybody noticed.

At a penny or two a call, that's a few thousand dollars. All for a test.

The one-minute version.

Whose fault was it?

Mine.

He did what developers do. He built something, ran it, and trusted it to stop. The agent did what agents do. It kept going.

I'm the one who handed out a key with no limit on it. No spending cap. No alerts. No kill switch. Nothing between a runaway loop and the company card.

Agents don't get tired

A human developer who accidentally writes a loop hitting a paid API will usually notice. The logs scroll. They get bored and check on it.

Agents don't get tired, and they don't get bored. They'll do the wrong thing a few hundred thousand times with the same energy as the right thing once.

That's what makes agents useful. It's also what makes an unguarded key dangerous.

We want to be careful that we don't unleash the agents.

The math is the point

Teams get excited about agents because they're cheap per task. A few cents here, a dollar there.

But "cheap per call" times "nobody is watching" is how you get a surprise invoice. One runaway loop can eat the savings you were counting on.

Keep using agents. Fence the wallet first.

Guardrails before autonomy

Here's the checklist I use now before any agent, script or developer gets a key to something that costs money:

  1. A hard spending cap on the key itself. Set it at the provider. Most cloud providers let you set budgets or quotas per project or per API.
  2. An alert way below the cap. Get an email or a text at 25% and 50%, not after the money is gone.
  3. A rate limit. If a task should make 100 calls, cap it at 1,000. Anything past that is a bug.
  4. A separate key per agent or project. When something goes wrong, you can kill one key without taking everything down.
  5. Somebody who knows how to shut it off. Write down who can revoke the key and how, before you need to.
  6. A weekend rule. Don't kick off a long unattended run on Friday afternoon unless every item above is in place.

None of this is new. We've done it for cloud servers for years. Agents just make it urgent, because now the thing spending the money can also write more code that spends money.

What I tell CEOs

If your team is building with agents, ask one question this week: what is the most an agent could spend before a human found out?

If nobody can answer, you have a project for Monday.

I help teams put guardrails around AI before they hand it the keys. If that's where you are, book a call at bry.net.

Have you ever been surprised by an API bill?