← cartapi.io blog

How to set a spending limit for an AI agent: a 2026 checklist

Published 2026-11-17 · Last updated 2026-11-17 · 8 min read · agent commerce protocol
TL;DR

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:

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

LimitWhat it stopsA sensible startcartapi field
Per-purchase capOne large mistaken or injected purchaseJust above the most you expect to pay for one itemmax_per_txn_cents
Rolling windowMany small purchases in a short timeYour expected monthly spend, per 30 dayswindow (cents + seconds)
Lifetime capSlow leaks over monthsA few months of expected spendmax_total_cents
Category scopeBuying the wrong kind of thingOnly what the task needs, e.g. top-upsallowed_categories
Country scopeBuying for the wrong placeThe countries the task coversallowed_countries
ExpiryA forgotten permission that lives foreverThe end of the trip or the quarterexpires_at
Agent bindingA different agent reusing the tokenBind to the one agent you're setting upagent_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:

  1. The agent builds a consent link to https://api.cartapi.io/consent with your email and the proposed limits in the query string: max_per_txn_cents, window_cents and window_days, max_total_cents, allowed_categories, allowed_countries, plus agent_id, agent_name and an optional return_url.
  2. 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.
  3. 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.
  4. The agent gets a token. It's sent back to the return_url as envelope_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.
  5. The agent buys. It passes envelope_token to get_checkout_link or create_topup_checkout. cartapi checks every limit, then charges the saved card off-session and returns an order_id with 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

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

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.

About the author

Roc Chow

Roc Chow builds cartapi, the commerce layer for AI agents, and runs . The envelope behaviour described here comes from cartapi's own code and tests as of 2026-11-17.

LinkedIn · · cartapi.io