x402 SDK Snippet Generator

Pick a framework and an endpoint — get runnable pay-per-call code with the correct manual payment flow. No @x402/fetch magic: you see every step.

⚠ base64, not base64url. The PAYMENT-REQUIRED response header and the X-PAYMENT request header are base64 STANDARD. Do not decode/encode them as base64url — only JWT signing uses base64url. (Fleet bug fixed 2026-10-20: clients parsing the header as base64url silently produced garbage payments.) Every snippet below decodes with standard base64.
1 · fetch unpaidSend the request normally, no wallet. Inside trial quota you get 200 straight away.
2 · read the 402Quota exhausted → HTTP 402. Parse PAYMENT-REQUIRED (base64 standard) → accepts[0] has amount, USDC asset, payTo.
3 · signEIP-712 sign an EIP-3009 transferWithAuthorization on USDC/Base with your wallet (viem / ethers / eth_account).
4 · retryX-PAYMENT = base64 (standard) of the payment JSON. Resend the same request with that header → 200.
Prefer drop-in files over copy-paste? Pre-built plugin packages →
Copied ✓

Paid mode needs a funded wallet. Set PRIVATE_KEY (Python) or WALLET_PRIVATE_KEY (TypeScript) to a Base wallet holding a little USDC. Without it the snippets run in trial mode and surface the 402 message. Every snippet caps spend per call (MAX_USD_PER_CALL, default $0.05) — raise it deliberately, never blindly.
Full fleet list: manifest.json · Live schema: mcp-schema.json · Try endpoints free: playground