Guide · For developers

How to give an AI agent a budget.

An agent that can call paid tools can also call them in a loop all night. The fix is not watching it; it is limits the agent cannot talk its way past. Here are the five controls, and a setup that takes five minutes.

5 min read

The risk

Agents fail in a particular way: they retry. A tool that returns something unexpected can send an agent round the same three calls for hours, and each call costs money. A spending alert that arrives tomorrow morning is too late. What you want are limits enforced on every call, before it is charged.

One key per agent

Give each agent, or each environment, its own key. You can hold ten at once, each with a name that appears in your spend breakdown. Separate keys mean one runaway agent cannot spend another's budget, and you can revoke one without touching the rest. A key can also be given an expiry, between an hour and a year, after which it simply stops working.

A rolling 24-hour cap

Each key can carry a spend cap: a ceiling on what it may spend in any rolling 24 hours. When a call would pass it, the call is refused with 402 Budget_Exhausted and nothing is charged. As older spend ages past 24 hours, room returns on its own.

cap = $5.00 per rolling 24 hours

09:00  spend $4.80   allowed, $0.20 left
09:01  spend $0.50   refused with 402, nothing charged
next day 09:01       the 09:00 spend ages out, room returns

No heuristic and no operator lowers a cap you set. You choose capped or uncapped when you create the key; an uncapped key is bounded only by your wallet balance, which is a fair choice for a workload you trust.

Only the tools it needs

A key can be limited to a list of up to 50 tools. A call to anything else is refused before anything is charged, and the agent's tool list shows only what it may call, so it never wastes a turn on a tool it cannot use. For an agent that discovers tools on its own, set a maximum price per call as well, so it can never pick a tool more expensive than you meant.

A wallet you fund

The last line of defence is the wallet itself. You add funds in advance, by card with 3D Secure, and there is no automatic top-up and no stored card to draw on. Whatever happens, an agent can spend at most what you have already put in. When the wallet is empty, calls return 402; there is never a debt.

Hear before it runs out

Add an alert for balance.low, sent to a signed webhook of yours or into a Slack or Discord channel, so you top up before calls start returning 402 rather than after.

A safe setup in five minutes

  1. Fund the wallet with what you are willing to spend this week.
  2. Mint one key per agent, named after it, with a 24-hour cap a little above a normal day.
  3. Limit each key to the tools that agent needs, and give it an expiry if it is temporary.
  4. Add a balance.low alert to the channel you actually read.
  5. Keep the key in an environment variable, never in code, and rotate it if it ever leaks.

Give your agent every tool. Keep the budget.

One key per agent, a hard cap on each, and a wallet you fund yourself.