x402 — Pay-Per-Request for AI Agents
Call any model and pay per request in USDC — no account, no API key. Your wallet is the identity, over the open x402 payment protocol. A free testnet sandbox is live now.
POST https://x402.tokligence.ai/v1/chat/completions
OpenAI-compatible request body. No Authorization header — you pay per call instead. Prefer a normal API key? Use the standard API.
How it works
Every request runs a short pay-then-serve loop — your client sends the request twice: once to get a price, once with payment attached.
- Send your request (OpenAI chat body). With no payment you get
402 Payment Requiredand a price quote inaccepts— a USDC ceiling for this exact request. - Sign a payment authorizing up to that ceiling (a Permit2 signature).
- Resend the same request, byte-for-byte, with an
X-PAYMENTheader carrying the signature. - Get
200+ the completion. You are charged the actual usage (always ≤ the ceiling); it settles on-chain and our facilitator pays the gas — so you never need gas beyond the one-time setup below.
Try it free — testnet sandbox
Live now on Base Sepolia. The payment loop is fully real (real signature, real on-chain settle), but the model response is a fixed placeholder — so it costs nothing and you are testing your payment integration, not model output.
-
Fund a wallet you control on Base: test USDC from faucet.circle.com (select Base Sepolia), plus a little Base Sepolia ETH for the one-time approval below.
-
Approve Permit2 once so it can move your USDC at settle time (one transaction, then never again):
token : 0x036CbD53842c5426634e7929541eC2318f3dCF7e (USDC, Base Sepolia)
call : approve(spender, amount)
spender (arg) : 0x000000000022D473030F116dDEE9F6B43aC78BA3 (the Permit2 contract)
amount : max uint256This approves the Permit2 contract on your USDC. It is separate from the per-payment signature below, whose
Spenderfield names the x402 proxy — you approve Permit2 once here, then Permit2 pulls funds via each signed permit. -
Run the loop against the endpoint — get the 402 quote, sign it, resend, receive a 200.
The payment contract you integrate against is identical. Going live means the same code against Base mainnet with real USDC and real model responses.
The 402 response — your quote
An unpaid request returns the price to sign. accepts[0] is what you pay under:
HTTP/1.1 402 Payment Required
{
"x402Version": 2,
"accepts": [{
"scheme": "upto", // authorize a ceiling, pay actual usage
"network": "eip155:84532", // Base Sepolia (sandbox); eip155:8453 = mainnet
"amount": "43", // the ceiling, USDC min units (6 decimals, string)
"asset": "0x036CbD…dCF7e", // USDC
"payTo": "0x…", // where the payment lands
"maxTimeoutSeconds": 600, // how long this quote is valid
"extra": { "facilitatorAddress": "0x…" }
}]
}
Paying — the X-PAYMENT header
Sign a Permit2 PermitWitnessTransferFrom for the quoted ceiling, then resend the byte-identical body with the signature base64-encoded in an X-PAYMENT header. Signing essentials:
| Field | Value |
|---|---|
| Scheme | upto — you authorize the quoted amount (the ceiling); the server settles the real usage-based amount ≤ that |
| Permit2 contract | 0x000000000022D473030F116dDEE9F6B43aC78BA3 (same on every EVM chain) |
| EIP-712 domain | { name: "Permit2", chainId, verifyingContract: <Permit2> } — no version field |
| Spender | 0x4020A4f3b7b90ccA423B9fabCc0CE57C6C240002 (x402 upto proxy, fixed on every EVM chain) |
| Witness | { to: payTo, facilitator: extra.facilitatorAddress, validAfter } |
X-PAYMENT body | base64 JSON with a top-level accepted object (the scheme/network you pay under) alongside the signed payload |
- The paid request body must be byte-identical to the one you quoted — the quote is bound to a hash of the raw bytes; re-serializing (key order, whitespace) invalidates it.
- The
acceptedobject sits at the top level of the X-PAYMENT JSON, next topayload— not inside it.
The x402 protocol spec and reference client tooling live at github.com/coinbase/x402.
Discovering models & prices
GET https://x402.tokligence.ai/v1/models
Lists every payable model with live per-million-token prices, context length, and max output. The 402 quote for a given request is the authoritative price for that exact call.
Errors
| Status | Meaning & what to do |
|---|---|
402 | Payment required (or invalid/expired). Sign accepts[0] and resend the same body with X-PAYMENT. |
400 | Malformed body, a non-payable model, or stream: true (not supported on this rail). Fix the request. |
403 | The quote exceeds the per-request cap, or the payer address is blocked. Lower max_tokens, or stop. |
429 | Rate limited. Back off and retry. |
503 | Model not currently payable, or the rail is momentarily at capacity. Retry later. |