# Our agent pays for LLM inference and other metered APIs with MPP (the Machine Payments Protocol) sessions through the mppx client, reserving stablecoin once and paying per request or per streamed token. Which settings actually cap what it can spend, which ones only look like a cap, and how do we set a total budget?

**Short answer:** Use three layers, because each mppx setting caps something different. maxDeposit caps the funds reserved in one session channel, not total spend: an agent that opens channels with ten APIs can reserve ten times that amount. maxAmount caps the price per unit (one request or one token) and needs currencies and decimals set; expectedRecipients rejects offers from any seller address you didn't list. The total budget lives below the SDK: the MPP docs say to cap spend across channels, processes and restarts with a Tempo access key, a delegated signing key with a token spending limit per period (their example is 10 OUSD a day), recipient scopes and an expiry. Two gaps matter for streaming: the session manager used for per-token streams doesn't enforce currencies, expectedRecipients or maxAmount, so stream only from APIs you trust; and by default Mppx.create installs a payment-aware global fetch, so every fetch-based tool and MCP transport in the agent can pay when a server answers with a 402 challenge. Close sessions when the job is done, because the reserve stays locked until the channel closes.

## Checklist
1. Give each agent runtime its own Tempo access key with a daily (or shorter) token spending limit, recipient scopes and an expiry of days, not months. That is the only limit in the MPP docs that holds across channels, processes and restarts.
2. Set maxDeposit to what one job should be able to spend with one API, remembering that it is per channel. The client reserves the smaller of the seller's suggested deposit and your maxDeposit.
3. Set maxAmount (price per request or token) together with currencies and decimals, and list the seller addresses you expect in expectedRecipients, so a changed price or a different payee is rejected before anything is signed.
4. Pin origin and use one channel store per API origin, so one API's session can't be reused against another.
5. For per-token streaming with tempo.session.manager, stream only from APIs you trust and rely on maxDeposit plus the access-key limit, because the manager ignores currencies, expectedRecipients and maxAmount.
6. Decide which code is allowed to pay. Mppx.create patches the global fetch by default, so any tool, plugin or MCP transport using fetch can answer a 402 challenge with the agent's money; keep paid calls behind a wrapper that checks the task's budget first.
7. Close each session with the same manager instance when the job is done (not between requests) and check the receipt's spent value, so unspent reserve comes back and the next job starts from a known balance.
8. Use the SDK's payment hooks to log every challenge, amount, currency and receipt reference with the task that caused it, without logging keys.
9. Test the whole setup on the Moderato testnet with npx mppx before funding a mainnet account.

## What do maxDeposit and maxAmount cap in an mppx MPP session?
- MPP, co-authored by Stripe and Tempo, is an open protocol in which a server answers a request with HTTP 402 and a payment challenge, the client authorizes payment and retries, and the server returns the resource with a receipt. A session is the pay-as-you-go form: the first paid request opens a payment channel and reserves funds on-chain, later requests or streamed tokens are paid with signed off-chain vouchers, and closing settles what was spent and returns the rest.
- In the mppx client, maxDeposit caps the funds reserved per channel and is explicitly not a cap on total spend across channels. maxAmount caps the price per unit, a request or a token, and requires currencies and explicit decimals; it is not a total either. expectedRecipients rejects offers to any other seller address before signing, and origin pins the API origin that saved channels belong to.
- The docs add that explicit session closes bypass the price and recipient limits, so a client can always get its funds back.

## How do you set a total daily budget for an AI agent paying with MPP?
- The MPP guide on managing agent spend points to Tempo access keys: delegated signing keys authorized by a wallet, with token spending limits per period, limits on which contracts or functions can be called, recipient restrictions and an expiry. Its example key can spend up to 10 OUSD per 86,400-second period, can only transfer OUSD to one recipient and expires after seven days. Separate keys for separate apps, tools or deployments each get their own budget, scopes and revocation path, and pinning a key to a runtime keeps two deployments from sharing one budget by accident.
- That key-level limit is what stops an agent that opens many channels, restarts and opens them again, or is tricked into paying a new API. Treat maxDeposit and maxAmount as per-API guards on top of it, and keep a running total per task in your own code if a task budget is smaller than the key's daily limit.

## Does the mppx session manager enforce price and recipient limits when streaming?
- For streamed responses the guide uses tempo.session.manager with .sse(), which signs new vouchers and tops up the channel within maxDeposit without interrupting the stream. The same guide says the manager doesn't enforce currencies, expectedRecipients or maxAmount, so a streaming API can raise its per-token price and the client keeps paying until the reserve or the access-key limit runs out.
- By default Mppx.create installs a payment-aware global fetch. That is how existing HTTP tools and MCP transports pay without code changes, and it also means any code in the process that uses fetch, including a third-party tool or a page the agent was told to open, can trigger a payment when the server returns an MPP challenge. The same client can also pay compatible x402 exact endpoints if you add that method, which widens what a 402 can charge.
- Reserves stay locked until the channel closes, and close() only works on the manager instance that made the requests (or one that has loaded the channel from a shared channelStore on its next request). If a seller stops responding, the payer can request a close on-chain and, after Tempo's 900-second grace period, withdraw whatever the seller hasn't settled; the seller can still settle what was spent until then. On the seller side, Stripe's docs note that usage accrues in units as small as 0.000001 USDC but settles to the Stripe balance in whole cents, with sub-cent remainders forfeited.

## Ask Rightshold (free, no key)
Add the MCP server https://www.rightshold.com/mcp to Claude, Cursor, ChatGPT, Grok or VS Code (one-click setup: https://www.rightshold.com/start?ref=seo), then ask: "Before my research agent opens an MPP session with api.example.com, check the session's $1.00 maximum reserve against its spending policy for this task and record the decision with the session reference, so the total across every API it pays stays inside today's budget."

```json
{
  "tool": "authorize_spend",
  "arguments": {
    "credential_id": "YOUR_AGENT_CREDENTIAL_ID",
    "amount_minor": 100,
    "currency": "USD",
    "merchant_domain": "api.example.com",
    "category": "api-usage",
    "reference": "mpp-session-api.example.com-task-42"
  }
}
```
- Needs a key for your account. It checks the amount against the policy set with set_spend_policy (owner account key only): currency, per-transaction cap, UTC-day cap, allowed merchant domains and categories, expiry. It returns a signed allow or deny with reasons such as over_daily_cap or merchant_not_allowed, recorded on Rightshold's ledger.
- Amounts are whole cents in a 3-letter currency code, so record a stablecoin reserve as its USD value; Rightshold can't express sub-cent per-token prices and doesn't see vouchers, on-chain channels or what a session actually spent. Check the reserve when a session opens and the receipt's spent value when it closes.
- It doesn't sign MPP payments, set Tempo access-key limits or block a 402 challenge. It only sees payments the agent checks with it first, so keep the access-key limit as the hard stop behind it.

_Rightshold records spending decisions your agent asks it for. It never holds or moves money, isn't a wallet or payment processor and isn't affiliated with Stripe, Tempo or the MPP project. The mppx behavior described here comes from the mpp.dev guides and Stripe's MPP docs as checked on November 10, 2026 (mppx 0.18.0 was the latest npm release); settings and defaults may change. Not financial advice._

## Sources
- [MPP: Pay for sessions (buyer guide: maxDeposit, maxAmount, expectedRecipients, closing)](https://mpp.dev/guides/pay-for-sessions)
- [MPP: Managing agent spend (Tempo access keys, spending limits and scopes)](https://mpp.dev/guides/managing-agent-spend)
- [MPP: Tempo sessions (close supervision and grace period)](https://mpp.dev/payment-methods/tempo/session)
- [MPP blog: mppx for agent SDKs and harnesses (payment-aware global fetch)](https://mpp.dev/blog/mppx-agent-runtimes)
- [MPP blog: Payment hooks](https://mpp.dev/blog/payment-hooks)
- [Stripe Docs: MPP](https://docs.stripe.com/payments/machine/mpp)
- [Stripe Docs: Accept streaming payments with MPP sessions](https://docs.stripe.com/payments/machine/mpp/sessions)
- [Stripe blog: Introducing the Machine Payments Protocol](https://stripe.com/blog/machine-payments-protocol)
- [mppx on npm](https://www.npmjs.com/package/mppx)

## Related
- [How to set per-request and per-run spend caps for x402 agent payments](https://www.rightshold.com/answers/how-to-set-per-request-and-per-run-spend-caps-for-x402-agent-payments)
- [How to stop one user of your AI app from running up your LLM bill](https://www.rightshold.com/answers/how-to-stop-one-user-of-your-ai-app-from-running-up-your-llm-bill)
- [How do Stripe shared payment tokens limit what a seller can charge for an AI agent purchase?](https://www.rightshold.com/answers/how-do-stripe-shared-payment-tokens-limit-what-a-seller-can-charge-for-an-ai-agent-purchase)
- [How to stop a prompt injection from making your AI agent buy something](https://www.rightshold.com/answers/how-to-stop-a-prompt-injection-from-making-your-ai-agent-buy-something)

_Not legal advice. Updated 2026-11-10. JSON: https://www.rightshold.com/answers/how-to-cap-what-an-ai-agent-spends-on-pay-per-token-apis-with-mpp-sessions.json_