The pain
The agent needs a paid service and stops, or someone puts a company card in the loop with no limit.
Who uses it
The engineer who runs agents in production.
Who buys it
The platform or infrastructure lead who owns the budget.
The gain
A cap per call and a budget per month, no card at every step, and a refusal with nothing paid when the budget runs out.
The flow, side by side
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.
01Agent
Request
The agent calls an endpoint priced with x402. The endpoint answers 402 with its price in USDC.
402 · US$ 0.40 in USDC02CodeSpar
Rules
Cap per call, monthly cap and the approved endpoint are checked before anything is paid.
cap US$ 1.00 · month US$ 20.0003x402 · USDC
Payment
Inside the caps the call is paid in USDC and goes through. Above either one it is refused and nothing is paid.
−US$ 0.40 · x402 · USDC04Wallet · audit trail
Receipt
Each paid call gets a signed receipt and a ledger entry, both in the audit trail.
rcpt_demo_41c2 · signed
Behind it
Mandate, wallet, payment, receipt.
One call from the agent. Everything else is the platform: mandate, wallet, payment, receipt.
SDK example · demo data · not run on this page
Two ways to pay
Pay per call, or buy credits.
Same mandate, two ways to pay a provider. Per call, x402 pays the price the endpoint quotes and the call goes through. A block of credits is a payment plus the provider's own provisioning.
Path A · x402 per call
SandboxPay the 402, get the response
The agent calls a paid endpoint, gets a 402 with the price in USDC, pays under the mandate and the call goes through. Above the per-call cap nothing is paid.
Runs in test mode on Base Sepolia through the REST spend route.
Path B · credit purchase
Pilot / integrationBuy credits from a provider
The agent pays the provider under the mandate and the provider credits the account. The credit itself is the provider's flow, not CodeSpar's.
Depends on the provider's own provisioning: a pilot or an integration.
What exists today
Exists, sandbox, pilot or direction: one label per control.
What you can run with a test key today, what runs in the sandbox, what depends on a pilot or an integration, and what is only a direction.
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.
- A test keyFrom the Dashboard. Test keys are free; nothing moves real money.
- A mandateCap per call, monthly cap and the approved endpoint. The Dashboard opens the consent page; the consumer signs it.
- A USDC funding sourceIn test mode the calls settle on Base Sepolia; mainnet is off by default.
// 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); // 422SDK example · demo data · not run on this page