Prerequisites
To try the example, you need:- Node.js 20 or later
- A wallet with USDC on Base mainnet. USDC on another chain or a testnet won’t work.
x402 Search Agent
A complete example with a research agent, spending caps, and a step-by-step
curl demo.How it works
- You send a search request without an API key.
- The Gateway responds with
402 Payment Requiredand aPAYMENT-REQUIREDheader describing the price, network, and recipient. - Your client signs a USDC authorization for exactly that amount and retries the request with a
PAYMENT-SIGNATUREheader. - The Gateway verifies the payment, forwards the request to Ceramic, and returns the search results with a
PAYMENT-RESPONSEreceipt.
- Failed searches cost nothing. The Gateway only settles payment after a successful response.
- You don’t need ETH for gas. The Gateway submits and pays for the on-chain transfer.
- Your private key never leaves your client. It signs a one-time authorization for the quoted amount, valid for a limited window.
- The price comes from the
402response. Check thePAYMENT-REQUIREDheader for the current price per search.

