Skip to content
Put a price of 0.001 USDC on an HTTP endpoint and have a client pay it automatically, request by request. You call a paid API, read the server, then run both yourself. The protocol is x402. It uses the HTTP status code 402 Payment Required:
  1. Request. The client calls GET /api/forecast as usual.
  2. Quote. The server answers 402 Payment Required with a price, the token it accepts (USDC), and the address to pay.
  3. Pay. The client signs a USDC transfer for that price.
  4. Retry. The client sends the same request again, with the signed transfer in a payment header.
  5. Return. The server checks the transfer, sends it to the network, waits for it to confirm, and returns the data with the transaction signature as a receipt.
Time: about 30 minutes. You need: nothing for steps 1 and 2. For step 3, Node.js 20.18 or later and npm, plus the Surfpool CLI if you run on a local network; git and pnpm only to run the repository’s tests.
This tutorial implements x402 directly on @solana/kit so you can see every check. It uses the x402 version 1 message shapes (the X-PAYMENT header) and is not the x402 SDK. For production, use the x402 version 2 packages (@x402/express, @x402/fetch, @x402/svm) and a facilitator, as step 4 describes.
Charge per API call · 4 steps · ~30 minPaywall an endpointPrice each request at a fraction of a cent. Clients, whether people’s apps or AI agents, pay inline over HTTP, with no signup, API key, or invoice.
  1. Call a paid API
  2. Read the code
  3. Add it to your server
  4. Go live
Start the tutorial →

​Is this the right tool?

Card billingCredits and API keysx402 on Solana
Smallest chargeSet by fixed per-charge feesA prepaid top-upA fraction of a cent
Client setupAn account and a cardA signup, a key, and a balanceA wallet with USDC
Works for AI agentsNeeds a person-issued cardAfter a person sets it upYes, with its own wallet
Billing code you maintainInvoices, retries, disputesA balance ledgerReceipts, refunds, and a used-payment store

A good fit if

  • You want to price per request, per page, or per unit of compute
  • Your clients are programs or AI agents, not people at a checkout
  • You don’t want to run signups, API keys, and balances

Not the right fit if

  • You charge one flat monthly fee: use your existing billing
  • Your buyers need invoices and payment terms
  • Every request must answer in a few milliseconds, including the first paid one: each paid request waits for its payment to confirm

​Guides