DEV Community

CAI
CAI

Posted on

Budgeting for Autonomous Agents: How CAI Payment Mandates Handle Cloud Compute Costs

Budgeting for Autonomous Agents: How CAI Payment Mandates Handle Cloud Compute Costs

A developer sets up a batch inference job. The agent finds the cheapest GPU provider, spins up 20 instances, runs the workload for 4 hours, and pays 9.60 USDC from the CAI custodial wallet. No one approves the payment. No credit card was entered. The developer set one payment mandate two weeks ago: "allow up to 50/day to any compute provider on this list." Every transaction appears in the weekly audit. The agent never paused to ask for permission.

That is the workflow payment mandates unlock. This article walks through how to create, use, monitor, and revoke them with the CAI API.

What a payment mandate does

A payment mandate is a delegated spending permission your agent checks against before paying. When your agent calls x402_payment_prepare and an active mandate covers the merchant, amount, and domain, the prepare step may skip the per-payment user confirmation. The agent calls x402_payment_execute with the prepared attempt, and the settlement happens autonomously.

CAI mandates are AP2-like limits. They are not full W3C/AP2 card-network credentials, but they deliver the core pattern: set a budget once, let the agent spend within it, and audit everything later.

Key properties from the API contract:

  • merchant_domain — the domain the mandate applies to (e.g. runpod.io). Payments to other domains are not covered.
  • recipient_address — optional. When set, only transfers to that on-chain address count as covered.
  • max_amount_per_payment_usd — hard cap on any single settlement.
  • daily_cap_usd — cumulative limit per rolling day.
  • allowed_resource_patterns — optional URL pattern list for x402 resources (e.g. */gpu/*).
  • expires_in_hours — mandate auto-revokes after this many hours. No indefinite self-spending.

Creating a mandate

The API is straightforward:

POST /payment-mandate-create
{
  "merchant_domain": "runpod.io",
  "max_amount_per_payment_usd": 5,
  "daily_cap_usd": 50,
  "expires_in_hours": 720
}
Enter fullscreen mode Exit fullscreen mode

The user approves the mandate through CAI's hosted verification page or their dashboard. Once approved, status becomes active. The agent can now reference this mandate on calls to x402_payment_prepare for the same domain.

The CAI product applies a $200/day automatic limit on all custodial payments, including mandate-covered ones. New recipients and new devices still need confirmation until an active mandate covers the merchant domain. That means the first payment to a new provider requires a user check. Subsequent payments to the same domain within the mandate caps do not.

How the agent pays within a mandate

When the agent encounters a payment trigger (an HTTP 402 response, a compute job with a price, or an API that requires settlement), the flow looks like this:

  1. Agent calls POST /x402-payment-prepare with the resource URL, recipient address, amount, chain, and token.
  2. CAI checks balance, checks for an active mandate matching the merchant domain and amount. If covered, requires_user_confirm comes back false.
  3. Agent calls POST /x402-payment-execute with the attempt_id from the prepare step and user_confirmed: true.
  4. CAI settles from the custodial wallet. The response includes a tx_hash and optionally settlement proof.
  5. Agent re-requests the resource with the proof. The seller validates and releases the compute.

Without a mandate, step 2 would set requires_user_confirm: true and the agent would need to ask the user. With the mandate in place, the agent moves straight to step 3.

Monitoring what the agent spent

Two endpoints track mandate usage:

  • GET /payment-mandate-status returns the current mandate objects with remaining budget and expiry.
  • GET /wallet-activity-list returns indexed custodial events including every transfer, x402 settlement, and deposit. Filter by category to see only mandate-covered payments.

The audit feed shows the merchant domain, amount, timestamp, and the mandate id that covered the settlement. This is the same feed the developer checks at the end of a compute run.

Revoking a mandate

When the budget expires or the developer decides to cut off spending:

POST /payment-mandate-revoke
{
  "mandate_id": "man_abc123"
}
Enter fullscreen mode Exit fullscreen mode

The mandate status flips to revoked. Any subsequent x402_payment_prepare for that merchant domain will set requires_user_confirm: true again. The agent cannot spend autonomously until a new mandate is created and approved.

Guardrails built into the product

Every CAI custodial wallet operates under product-level limits regardless of mandates:

  • $200/day automatic spending cap on all custodial payments.
  • New recipients and new devices always require user confirmation, mandate or not.
  • Funds come from the custodial wallet. Deposit USDC or use MoonPay for fiat on-ramp. No card on file needed.
  • The vault product (coming) will add credential-based spending: agents pay on behalf of the user using stored site logins, with the same confirmation pattern.

These guardrails mean the mandate is a convenience layer on top of existing safety rails, not a bypass.

Putting it together: the cloud compute scenario

The scenario from the opening paragraph maps to concrete API calls:

  1. Create mandate: POST /payment-mandate-create with merchant_domain: "runpod.io", daily_cap_usd: 50, expires_in_hours: 336 (2 weeks).
  2. User approves in dashboard. Mandate status: active.
  3. Agent finds cheapest GPU across providers. Picks RunPod. Calls POST /x402-payment-prepare with recipient_address, amount: 2.40, chain: "base", token: "USDC".
  4. CAI matches the mandate. requires_user_confirm: false. Agent calls POST /x402-payment-execute.
  5. Settlement completes. Agent re-requests the compute resource with the proof.
  6. Developer checks GET /wallet-activity-list at end of week, sees the 2.40 USDC entry with the mandate id.

The same pattern works for SaaS subscriptions, API credits, inference time, and any metered billing that can express a merchant domain and an amount.

The tooling layer

The CAI MCP server exposes the same endpoints through the @cailab/mcp npm package. Install it:

npm i -g @cailab/mcp
Enter fullscreen mode Exit fullscreen mode

Then configure in your agent's MCP settings with CAI_API_KEY. The tool names are payment_mandate_create, payment_mandate_status, payment_mandate_revoke, x402_payment_prepare, and x402_payment_execute. Every tool follows the same path contract defined in cai.com/skill.md.

Every comment on this article gets read. Bug reports will be replied to within 24 hours. Friction points shape what we document next.

Top comments (0)