Skip to main content

Use case · Compute and API spend

Budgets for the APIs and compute your agents buy.

Set a cap per call and a budget per month, so a loop or a bad prompt cannot run up the bill.

Test keys are free.

Agent run · paid inference calldemo

"summarize this contract on the approved inference endpoint"

Call the endpointinference.example answers 402 · price US$ 0.40 in USDCpriced
Check the mandateEndpoint on the list · cap US$ 1.00 per call · US$ 12.40 of US$ 20.00 this monthallowed
Pay over x402USDC on Base Sepolia · test mode−US$ 0.40paid
Receipt signedrcpt_demo_41c2 · ed25519 · anyone can verifysigned
Call servedThe endpoint answers the paid request · ledger entry in the wallet200
Monthly cap · OctoberUS$ 12.80 of US$ 20.00
balance US$ 49.60receipt rcpt_demo_41c2 · signed

Agent run · demo data

What the agent does

From request to receipt, under a budget.

The agent makes the call and pays for it. The rules sit between every call and the money.

  1. 01

    Request

    The agent calls an endpoint priced with x402. The endpoint answers 402 with its price in USDC.

    402 · US$ 0.40 in USDC
  2. 02

    Rules

    Cap per call, monthly cap and the approved endpoint are checked before anything is paid.

    cap US$ 1.00 · month US$ 20.00
  3. 03

    Payment

    Inside the caps the call is paid in USDC and goes through. Above them it is refused and nothing is paid.

    −US$ 0.40 · x402 · USDC
  4. 04

    Receipt

    Each paid call gets a signed receipt and a ledger entry, both in the audit trail.

    rcpt_demo_41c2 · signed

Behind it

The parts that run it.

One call from the agent. Everything else is the platform: mandate, wallet, payment, receipt.

Mandate and rulesCap per call, monthly cap and approved endpoints, signed by the consumer and checked before anything is paid.Open
WalletThe USDC balance that pays for the calls; every debit is a ledger entry.Open
PaySends the payment under the mandate.Open
Receipt and audit trailA signed receipt for each paid call; every governed action in the audit trail.Open
GateThe other side of x402: charge per call for your own API.Open
TypeScript · @codespar/sdk 0.16.11real SDK
const cs = new CodeSpar();const res = await cs.api.response("post", "/v1/consumers/mandates/{id}/spend", { path: { id: "mnd_demo_cmp" }, body: { amount_minor: 100, payee: "https://inference.example/v1/summarize" } });if (res.ok) console.log(res.data.receipt?.id);// paid in USDC inside the caps · rcpt_demo_41c2 signed

Sandbox run · demo data

Mandate · mnd_demo_cmp demo
Cap per callUS$ 1.00
Monthly capUS$ 20.00 / month
Approved endpointinference.example
Railx402 · USDC · test mode
ExpiryDec 31, 2026

Demo

Try a call against these rules.

Pay for a call inside the cap, try one priced above it, then sign a new mandate with a higher cap and try again. The balance and the monthly cap follow along.

Simulated demo · no real money
Activity demo2 entries
Call priced US$ 1.50Above the cap of US$ 1.00 per call · nothing paid−US$ 1.50refused
Call priced US$ 0.40Inside the rules · test payment · signed receipt−US$ 0.40paid
Simulated result: refused: above the cap per call. Nothing was paid.
Wallet and monthly cap demo

Wallet balance

US$ 49.60

Cap per callUS$ 1.00
Used this monthUS$ 12.80 / US$ 20.00
Approved endpointinference.example
Paid calls1

Test payment to a generic test endpoint. Nothing is called or paid.

Cookbook

Pay per call under a budget, in a few lines.

The consumer signs the mandate on the consent page; the agent makes one REST call per paid request. The same recipe runs in test mode with a test key.

  1. A test keyFrom the Dashboard. Test keys are free; nothing moves real money.
  2. A mandateCap per call, monthly cap and the approved endpoint. The Dashboard opens the consent page; the consumer signs it.
  3. A USDC funding sourceIn test mode the calls settle on Base Sepolia; mainnet is off by default.
@codespar/sdk 0.16.11real SDK
// 1 · the consumer signed mnd_demo_cmp on the consent page: US$ 1.00 per call, US$ 20.00 a month, one endpointimport { CodeSpar } from "@codespar/sdk";const cs = new CodeSpar(); // 2 · pay for one call to the x402-priced endpoint, at most the per-call capconst res = await cs.api.response("post", "/v1/consumers/mandates/{id}/spend", {  path: { id: "mnd_demo_cmp" },  body: { amount_minor: 100, payee: "https://inference.example/v1/summarize", attempt_id: "call_0001" },}); // 3 · inside the caps: paid in USDC, receipt signed · above them: refused, nothing paidif (res.ok) console.log(res.data.receipt?.id, res.data.payment.amountMinor); // rcpt_… 40else console.log(res.status); // 422

Sandbox run · demo data

Related use cases

Use case

Machine spend with x402

Paid calls priced per request.

Use case

Wallet auto top-up

Keep the wallet funded under rules.

Use case

Autonomous procurement

Supplier boletos the agent pays under a mandate.

Give your agents a way to pay and get paid.

Build is free: hosted MCP, SDK and sandbox.

Test keys are free.

REST · api.codespar.devREST API
$ curl https://api.codespar.dev/v1/consumers/mandates/mnd_demo_cmp/spend \    -H "Authorization: Bearer $CODESPAR_API_KEY" \    -H "Content-Type: application/json" \    -d '{"amount_minor":100,"payee":"https://inference.example/v1/summarize"}'  cap US$ 1.00 per call · US$ 12.40 of US$ 20.00 this month  200 · paid US$ 0.40 in USDC (Base Sepolia, test mode) · rcpt_demo_41c2

Sandbox run · demo data

Compute and API spend · CodeSpar