How to set a spending limit for an AI agent: a 2026 checklist
Set the limit where the money moves, not in the prompt. Five limits cover most cases: a per-purchase cap, a rolling cap (for example $50 per 30 days), a lifetime cap, a list of allowed categories and countries, and an expiry date. Then test two things: that an over-limit purchase is refused by the server, and that you can revoke the permission. In cartapi these limits are a consent envelope, checked on every charge before Stripe is called.
The default for an agent that buys things is a checkout link: the agent finds the product, you click and pay. That's the safest setup, and it's what most people should use. But if you want your agent to top up a phone every month or buy an eSIM while you're asleep on a plane, you have to let it pay without a click. This checklist is about doing that without giving it a blank cheque.
Rule one: a limit in the prompt is not a limit
"You have a $30 budget" in a system prompt is a suggestion. The model can misread it, round it, or be talked out of it by text on a web page it reads. A real spending limit has three properties:
- It's enforced by the payment side. The server that creates the charge refuses an over-limit request, whatever the agent sends.
- The person approved it. You saw the numbers on a page you trust and confirmed them, rather than the agent describing them to you.
- It fails closed. When a limit is hit, nothing is charged, and the agent gets a reason it can show you.
The two big agent-payment protocols draw the same line. Google's AP2 Payment Mandate carries constraints such as a budget, an amount range, allowed payees and an expiry, and the merchant's processor verifies them. Stripe and OpenAI's ACP delegated payment spec issues a token that "MUST ONLY be usable within the provided Allowance". Neither leaves the limit to the model.
The checklist
| Limit | What it stops | A sensible start | cartapi field |
|---|---|---|---|
| Per-purchase cap | One large mistaken or injected purchase | Just above the most you expect to pay for one item | max_per_txn_cents |
| Rolling window | Many small purchases in a short time | Your expected monthly spend, per 30 days | window (cents + seconds) |
| Lifetime cap | Slow leaks over months | A few months of expected spend | max_total_cents |
| Category scope | Buying the wrong kind of thing | Only what the task needs, e.g. top-ups | allowed_categories |
| Country scope | Buying for the wrong place | The countries the task covers | allowed_countries |
| Expiry | A forgotten permission that lives forever | The end of the trip or the quarter | expires_at |
| Agent binding | A different agent reusing the token | Bind to the one agent you're setting up | agent_id |
Here's each one in more detail.
1. Cap each purchase
Set it at or a little above the largest single item the task needs. For a monthly $10 phone top-up, $15 is plenty. For eSIMs, look up what a plan for your usual trip costs and add a margin. In cartapi a purchase exactly at the cap is allowed and one cent over is refused.
2. Cap a rolling window
A per-purchase cap alone still allows a loop of small purchases. A window cap, such as $50 per 30 days, bounds that. It's a sliding window, not a calendar month: cartapi adds up the envelope's orders created in the last N seconds and refuses the charge if this one would go over.
3. Cap the lifetime total
The backstop. Even if every purchase is small and spaced out, the envelope stops at this number. Orders that were canceled, refunded or failed don't count towards either the window or the lifetime total.
4. Narrow the categories and countries
An agent that only tops up a parent's phone in the Philippines doesn't need to buy gift cards or a Japan eSIM. In cartapi the categories are top_up, esim and gift_card, and countries are two-letter ISO codes. A product outside the list is refused with category_not_allowed or country_not_allowed.
5. Give it an end date
Permissions outlive the reason they were granted. Set expires_at to when the task ends. After that, the token is refused with envelope_expired.
6. Bind it to one agent
If you set agent_id, a checkout from a different agent ID is refused with envelope_agent_mismatch. It's a cheap check worth turning on.
7. Know how to revoke it
Before you grant anything, find the off switch. In cartapi it's POST /v1/envelopes/:id/revoke. A revoked envelope is refused on its next use with envelope_revoked.
How it works in cartapi
A consent envelope is a spending policy you approve once. The money stays with Stripe; cartapi holds no balance. The flow:
- The agent builds a consent link to
https://api.cartapi.io/consentwith your email and the proposed limits in the query string:max_per_txn_cents,window_centsandwindow_days,max_total_cents,allowed_categories,allowed_countries, plusagent_id,agent_nameand an optionalreturn_url. - You open it and read the rules. The page lists each limit in plain terms, such as "Per purchase: up to $15.00" and "Rolling window: $50.00 per 30 days". If the link has no limits at all, the page warns that the agent could spend without limit. Don't approve that.
- You add a card in Stripe's form. It's saved with a Stripe SetupIntent. cartapi never sees the card number, and nothing is charged yet.
- The agent gets a token. It's sent back to the
return_urlasenvelope_token, or shown on the page for you to paste to the agent. Treat it like a password: anyone holding it can spend inside your limits. - The agent buys. It passes
envelope_tokentoget_checkout_linkorcreate_topup_checkout. cartapi checks every limit, then charges the saved card off-session and returns anorder_idwith no redirect.
The limits are checked on the server before Stripe is called. If one fails, the tool returns envelope_denied with a reason and the numbers involved:
{
"error": "envelope_denied",
"message": "window_ceiling_exceeded",
"detail": {
"reason": "window_ceiling_exceeded",
"max": 5000,
"window_seconds": 2592000,
"spent": 4000,
"attempting": 1500
}
}
That example is a $15 purchase refused because $40 of a $50-per-30-days window was already used. Amounts are in cents.
The MCP tool description tells the agent to show that reason to you verbatim, so you can approve the purchase by hand or raise the limit. Each order also stores a snapshot of the limits and balances at the time of the charge, so a receipt shows what you had authorized when it happened, even if you change the envelope later.
Two things the envelope doesn't override. Gift cards are still sold cross-border only, so a saved card issued in the gift card's own country is refused. And if the bank wants to authenticate an off-session charge, it won't complete. In both cases the fallback is a normal checkout link you click yourself.
The envelope endpoints sit on the REST API at https://api.cartapi.io/v1: POST /envelopes, GET /envelopes/:id and POST /envelopes/:id/revoke. The rest of the API is in the docs, and the setup for Claude and ChatGPT is on the install page.
Test it before you trust it
- Ask for something over the per-purchase cap. You should get
per_txn_ceiling_exceededand no charge. - Ask for something outside the scope, such as a gift card on a top-up-only envelope. Expect
category_not_allowed. - Check the agent reports the refusal. If it retries silently with a different product, fix its instructions.
- Revoke and retry. The next purchase should fail with
envelope_revoked. - Read your card statement after the first real purchase. The amount should match what the agent told you.
When not to use a spending limit
If a purchase happens once, a link is better. You see the item and the price on Stripe's page and click, and a prompt injection can't spend anything. The reasons are in Consent-first checkout. Use an envelope when the purchases repeat, are small and predictable, or need to happen while you're not there, such as a monthly top-up for someone abroad (see sending load to the Philippines).
Related guides
- AP2 vs ACP: how each protocol represents the user's limits
- Consent-first checkout: why your agent should never see the card
- MCP URL elicitation for payments vs a checkout link
- How to add Stripe Checkout to an MCP server
Frequently asked questions
How do I set a spending limit for an AI agent?
Put it in the system that moves the money: a per-purchase cap, a rolling cap, a lifetime cap, allowed categories and countries, and an expiry. Then test that an over-limit request is refused and that revoking works.
Can I just tell the agent its budget in the prompt?
Not on its own. A prompt instruction can be misread or overridden by an injection. Only a refusal from the payment side is a limit.
Is a per-transaction limit enough?
No. Fifty purchases just under the cap all pass. Add a rolling-window cap and a lifetime cap.
What happens when the agent hits the limit?
In cartapi, the call returns envelope_denied with a reason, and nothing is charged. The agent should show you the reason.
Does the agent ever see my card number?
No. You enter the card in Stripe's form, Stripe stores it, and the agent receives only the envelope token.
How do I take the permission back?
Revoke the envelope. Its next use is refused with envelope_revoked. An expiry date ends it automatically.
Try it
Building an agent that buys top-ups, eSIMs or gift cards? Start with a checkout link from the docs, then add an envelope for the purchases that repeat. To use cartapi in Claude or ChatGPT, see the install page.