Skip to main content

Use case · Compute and API spend

Sandbox · x402 in USDC, test mode

Let agents pay for APIs and compute, no card at every step.

A cap per call and a budget per month on a signed mandate. Above either one the call is refused and nothing is paid.

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$ 18.80 of US$ 20.00 this monthallowed
Pay over x402USDC on Base Sepolia · test mode−US$ 0.40paid
Receipt signedrcpt_demo_41c2 · Ed25519 signaturesigned
Call servedThe endpoint answers the paid request · ledger entry in the wallet200
Next call · US$ 0.90Would take the month past US$ 20.00 · nothing paidUS$ 0.90refused
Monthly cap · OctoberUS$ 19.20 of US$ 20.00
balance US$ 49.60receipt rcpt_demo_41c2 · signed

Agent run · demo data

Demo

Try a call against these rules.

Pay for a call inside both caps, try one priced above the per-call cap, then one that would take the month past its budget. The balance and the monthly cap follow along.

Simulated demo · no real money
Activity demo2 entries
CodeSparCall priced US$ 1.50Above the US$ 1.00 per-call cap · nothing paidUS$ 1.50refused
AgentCall priced US$ 0.40Inside both caps · simulated payment · receipt−US$ 0.40paid
Simulated result: refused: above the per-call cap. Nothing was paid.

The session opens with the first two requests already run; Reset brings that state back.

Wallet and monthly cap demo

Wallet balance

US$ 49.60

Cap per callUS$ 1.00
Used this monthUS$ 19.20 / US$ 20.00
Paid calls1
Refused calls1

Nothing is called or paid: the demo runs in your browser.

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.

  1. 01Agent

    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. 02CodeSpar

    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. 03x402 · 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 · USDC
  4. 04Wallet · 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.

Mandate · mnd_demo_cmp demo
Authorized byPlatform lead
Cap per callUS$ 1.00 · above it, refused
Monthly capUS$ 20.00 / month · above it, refused
Approved endpointinference.example
Railx402 · USDC · test mode
ExpiryDec 31, 2026
Three paths under the same mandate demo
Happy pathA call priced US$ 0.40 · inside both caps → paid in USDC, receipt signed, call served.
Above the per-call capA call priced US$ 1.50 · above the US$ 1.00 cap → refused, nothing paid.
Above the budgetA call that would take the month past US$ 20.00 → refused, nothing paid.
TypeScript · @codespar/sdk 0.16.11SDK example
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

SDK example · demo data · not run on this page

What runs it demo
Mandate and rulesExistsCap per call, monthly cap and approved endpoints, signed by the consumer and checked before anything is paid.Open
WalletExistsThe USDC balance that pays for the calls; every debit is a ledger entry.Open
PaySandboxSends the payment under the mandate.Open
Receipt and audit trailExistsA signed receipt for each paid call; every governed action in the audit trail.Open
GateSandboxThe other side of x402: charge per call for your own API.Open

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

Sandbox

Pay 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.

POST …/spend → 402 · US$ 0.40 in USDCpaid under the mandate → 200→ rcpt_demo_41c2 · ledger entry

Runs in test mode on Base Sepolia through the REST spend route.

Path B · credit purchase

Pilot / integration

Buy 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.

pay the provider under the mandate→ credit confirmed by the provider (integration)

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.

Mandate: cap per call, monthly cap, approved endpointChecked before anything is paid; above either cap the call is refused.Exists
x402 payment per callThe REST spend route pays USDC on Base Sepolia in test mode; mainnet is off by default.Sandbox
Signed receipt per paid callEd25519 under the platform key, with the public key published; receipts sealed before it existed carry none.Exists
Buying credit blocks from a providerThe credit is the provider's own flow.Pilot / integration

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.11SDK example
// 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

SDK example · demo data · not run on this page

Related use cases

Use caseSandbox

Autonomous procurement

Supplier orders paid under your rules.

Use caseSandbox

CFO copilot

Pay approved invoices under your approval policy.

Use caseSandbox

WhatsApp: Pix payment request in chat

A Pix charge inside the conversation, paid in the bank app.

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$ 18.80 of US$ 20.00 this month  200 · paid US$ 0.40 in USDC (Base Sepolia, test mode) · rcpt_demo_41c2

Illustrative · demo data

API and compute budgets · CodeSpar