Spend7

An AI agent budget has to hold when the agent is wrong

AcademySpend7 Content Team6 min read
A robotic arm moving at speed on a production line, the tempo at which an ai agent budget has to hold
A robotic arm moving at speed on a production line, the tempo at which an ai agent budget has to hold Photo via Unsplash.

TL;DR: key takeaways

  • A budget is a rule the agent cannot edit and is evaluated on every payment, not a sentence the agent is asked to remember.
  • Scope and window are separate decisions. A per-agent daily cap and a global per-payment cap do different jobs and you usually need both.
  • Only payments that were allowed should count towards a cap, or a burst of denials locks out the next legitimate payment.
  • A new agent has no baseline, and a good budget says so in its output rather than scoring the unknown as normal.

A budget written into an agent's system prompt is a request, and requests get reasoned around. The agent loops, the context gets truncated, or a fetched page makes an exception look reasonable. None of those need an attacker. An AI agent budget that actually holds has to live somewhere the agent cannot edit, be evaluated on every payment, and say plainly what it does not know. This post sets out what that takes, then works through real numbers from the ruleset behind Spend7's risk check, so you can see where a budget binds and where it does not.

What a budget is, precisely

OWASP's LLM06:2025 Excessive Agency names the problem without the money: a system can take damaging actions because it has more capability than it needs, and the model does not need to be malfunctioning for that to happen. Its mitigations include enforcing authorisation in downstream systems rather than in the model, and rate-limiting so that damage is bounded. A budget is the payments version of both.

The NIST AI Risk Management Framework treats the same risk as something to manage across the whole system that acts, not something to leave to the model's own judgement.

Concretely, a budget is a set of records. Each record has four parts:

PartOptions in Spend7What it decides
Scopeglobal, agent, merchant, category, agent at merchantWhich payments the cap governs
Windowper payment, hourly, daily, weekly, monthlyHow the total is measured
AmountcapMinor in minor units, with a currencyThe ceiling itself
Actionallow, flag, denyWhat happens at the line

The windows are rolling. A daily cap means the last 24 hours from the moment of the check; the policy code labels it "per rolling 24 hours". Rolling windows matter because calendar windows have a well-known hole at the boundary.

Two rules shape the arithmetic. Cap usage counts only payments that were allowed, because a denied payment never moved money and counting it would let a burst of denials lock out the legitimate payment after it. And cap usage is measured against the history Spend7 holds for that agent, which is the payments your code sent through the check. A payment that bypasses the check is not in the total.

A worked example with real numbers

Take a research agent, research-agent-01, that buys market data. The budget the API reference uses as its example is a daily cap of $250 for that agent, plus a global per-payment ceiling of $100. In the request those are capMinor: 25000 and capMinor: 10000 in USD, because minor units are cents. Getting that unit wrong is how a $250 cap quietly becomes a $25,000 one, so the field is explicit.

Assume the agent has thirty days of history, a median payment of $12, and has already had $150 allowed in the last 24 hours. Four requests, four outcomes:

  1. A $400 request. It breaches the $100 per-payment ceiling. The cap-breach signal contributes up to 100 points, which is past the deny line of 80 on its own. Denied, whatever the rest of the score says.
  2. A $60 request. It is within the per-payment ceiling. Adding it brings the rolling total to $210, which is 84% of the $250 daily cap. That passes the 80% warning fraction, so the approaching-cap signal fires at up to 12 points. The amount is also five times the agent's median, which is above the anomaly ratio of four where the amount signal starts to fire. The score stays well under the flag line of 50, so the payment is allowed with both signals recorded.
  3. Four identical $12 payments to one merchant within five minutes. Three identical repeats is the retry-loop threshold, worth up to 30 points. On its own that sits under the flag line. A burst of more than twelve intents in the same five minutes adds up to 25 more, and the two together reach 55, past flag. This is why a retry loop is rarely caught by a cap alone. The cap is the backstop; the pattern is what raises the flag.
  4. A $600 request from a brand-new agent with three payments on record. The agent has not reached the eight settled payments needed before its amount baseline is trusted. The engine says so: an absence of history contributes up to 12 points, and the amount baseline is not used. The absolute-size signal still applies. Its floor is $500, so a $600 payment picks up a small size signal, while a $12 payment picks up none.

Point four is the one most budgets get wrong. An agent with no history is exactly where a compromised key or an injected instruction would do its first damage, so the size floor exists to cover the window before a baseline does.

Why the per-payment ceiling is not optional

Rolling windows bound the total, but they bound it after the money has moved for the earlier payments in the window. A per-payment ceiling is the only control that acts on a single payment before it is settled, regardless of history. Set it at the largest payment you would ever defend, and let the rolling cap govern everything below it.

The two do different jobs, so you usually want both. A ceiling of $100 with a daily cap of $250 stops a single $400 request outright. It also stops a run of $90 requests at the third one, because the rolling total would reach $270 against a $250 cap.

Where a budget stops

A budget is a decision about payments that reach the check. It does not certify a merchant, and it does not move money. A pre-payment decision is not a guarantee of fraud prevention, and it would be dishonest to present a cap as one.

Two numbers in the ruleset are approximations on purpose. The absolute-size signal treats one whole unit of any currency as roughly one dollar, which is exact for USD and the USD stablecoins that dominate x402 and an order of magnitude elsewhere. If you need an exact ceiling in a non-dollar currency, use a per-transaction cap, which is deterministic rather than a prior.

What happens when a policy write fails

A budget that can be half-written is a budget that can silently loosen. The spend-limits endpoint treats the write as a single unit. A payload that fails validation returns 422 with nothing changed. A write that fails on the server returns 500, and the previous policy stays in force. You should check the response on every write, and treat a 500 as "the old budget still applies", not as "the new one applied".

Each decision also records the ruleset version and a hash of the constants that produced it. If a threshold moves, the hash moves, so a payment from three months ago can be defended against the rules that were actually in force. That matters for a dispute, and it matters for a review of why a budget did or did not bind.

Setting one up

The step-by-step version, with the exact request and the rolling-window detail, is in the x402 spend limits guide. The short form is the one in the table above: write each cap as a record, scope it as narrowly as the question you are asking, pick a rolling window and a per-payment ceiling, choose deny or flag for the line, and send every payment through the check before settlement.

Then test the three states that fail quietly: an agent with no history, a rejected write, and a retry loop. If each one produces an explicit answer rather than a silent allow, the budget is doing its job. The history cold-start post covers the first in more detail, and mandate governance covers who is allowed to change a budget in the first place.

The API reference has the full request shape for both the check and the policy, including the context object that lets you test a budget against a sample history without storing anything. A budget you have tested against last month's payments is a better budget than one you have only read about.

Frequently asked questions

How do I set a budget for an AI agent?
Give the agent a stable identifier, then store a cap against that identifier with a scope, a rolling window and an amount in minor units. Choose the action for the line (deny or flag), and send every payment through a risk check before it settles. The cap lives outside the agent, so nothing in its context can move it.
What is a rolling spend cap for an AI agent?
A limit measured over the last N hours, days, weeks or months from the moment of each check, rather than over a calendar period that resets at midnight. Spend7's daily cap means the last 24 hours. That closes the gap where an agent spends its allowance at 23:50 and again at 00:10.
How to stop an AI agent overspending on a retry loop?
Put a per-payment ceiling and a rolling cap in place, and score repeats. Identical merchant-and-amount repeats inside a five-minute window are a retry loop signal in Spend7's ruleset, scoring up to 30 points on their own. A retry loop with a burst of intents reaches the flag line of 50, so it stops being a silent failure.
Does a budget guarantee the agent cannot overspend?
No. A budget decides whether a payment you send through the check is allowed. It cannot stop a payment that never reaches the check, and it does not move money or certify that a merchant is safe. It sets an enforceable boundary you can audit, which is the most a pre-payment decision can honestly offer.

Score a payment before it settles

Spend7 returns allow, flag or deny in one call, with the signals that produced it. The free tier covers a single agent, its spend caps and its full decision log.

Keep reading