No. 45 · NOV 2026 · 5 Min Read

Every AI Agent Needs a Hard Budget

Abstract

LLM budget caps per run, per user, and per account, enforced in code the model cannot touch, plus what the agent should do when it hits one.

OpenAI’s spend limits guide has one sentence every agent builder should read twice: “Spend alerts do not enforce a cap.” An alert is an email to someone who may be asleep. Meanwhile an agent stuck retrying a failing tool call, rereading a context that grows every turn, keeps spending at machine speed.

Every agent needs a hard budget: a cap on its own model spend that it cannot see past, argue with, or raise. Simon Willison made the general case in October: “Soft caps, ‘after $X/month, send me a warning email’, will not cut it.” For agents, the case is stronger, because the thing spending the money is also the thing deciding whether to keep going.

A Cap the Model Can’t Touch

The first rule is the same one I made about permissions in An Agent’s Tools Are Its Permissions. If the limit lives in the prompt, it is a suggestion. “Stop if this is getting expensive” asks the model to estimate a number it can’t observe and then act against its own instructions to finish the task. It will do neither reliably.

The cap lives in code outside the loop. Before every model call, the orchestrator checks what has been spent against what is allowed. If the next call would cross the line, the call does not happen.

LangChain reached the same rule from the payments side. In their Restock example an agent buys groceries through Stripe’s Link, and the closing advice is to “keep the spending limit and the approvals in code the model can’t touch.” The agent’s $25 budget is “a ceiling, not an amount to charge.” Model spend deserves the same treatment. It is money leaving the account on the model’s judgment.

Three Places a Cap Sits

One cap is not enough, because spend fails in three different shapes.

Per run. A single task gets a ceiling in tokens or dollars, and a ceiling on steps. This catches the runaway loop: the retry storm, the agent that keeps searching because it never found what it wanted, the context that doubles every turn. Set it from real runs. Take the cost distribution of completed tasks, find the long tail, and put the cap a little past it. A run that hits the cap is a run you want to look at anyway.

Per user. Each user, or each tenant, gets a daily or monthly allowance. This catches the user who found a way to make your product do their homework at your expense, and the integration that calls you in a loop. A per-run cap can’t see this. Each run is fine. There are just ten thousand of them.

Per account. The whole system has a ceiling, enforced at the provider and again in your own gateway. Provider limits exist now: Anthropic lets you cap monthly spend per workspace, and an OpenAI project hard limit returns a 429 once it is reached. Both are coarse, and OpenAI notes that enforcement is not instantaneous, so spend can run slightly past the line. This is the backstop for the bug in your other two caps. It should be high enough that you never hit it in a normal month and low enough that hitting it is survivable.

The three are independent. A run can be under its cap while the user is over theirs. Check all of them before the call.

Count Before You Spend

A cap checked after the fact is a report. The check has to happen before the call, against an estimate of what the call will cost.

Input tokens are known before you send them. Output tokens are bounded by the max_tokens you set, and you should always set it. That gives a worst case per call: input at the input rate, plus the output ceiling at the output rate. Reserve that amount against the budget, make the call, then settle to the actual usage the response reports. Two concurrent runs for the same user can’t both spend the last dollar, because the first one reserved it.

This is a small ledger with three operations: reserve, settle, release. It is the same shape as a hotel holding a deposit on your card. Put it in the gateway every model call passes through, which you want for routing and cost attribution anyway.

What the Agent Does at the Limit

Hitting the cap is a designed outcome. Decide in advance what happens.

  • Stop and say so. The run ends with a clear status: budget exhausted, here is what was done, here is what was not. The user sees a real message, and the decision log records the cap that stopped it.
  • Hand back partial work. If the task produced something useful before the limit, return it marked incomplete. A research agent with four of six sources summarized has done most of the job.
  • Ask for more. For work worth finishing, the agent requests a raise from a person with authority to grant it, the same way an employee asks before going over a purchase limit. The request names the amount and the reason. The model drafts the ask; a human, or a policy in code, approves it.
  • Degrade. Fall back to a cheaper model for the remainder, if your evaluations say the cheaper model is good enough for that step. Without the evaluation, this is a quieter way to fail.

What it never does is silently retry the same call and hope.

The Budget Is a Product Decision

Engineers tend to set caps by fear: a round number that feels safe. The better number comes from the task. What is a completed task worth to the user, and what does it cost to produce on the median run and on the bad one? If the bad run costs more than the task is worth, the cap is the place to say so.

That makes the budget a line in the product spec, owned by whoever owns the margin. It should be written down, versioned, and visible in the decision log for every run it stopped. When someone asks why the agent gave up on a task, the answer should be a number someone chose.