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:
- Request. The client calls
GET /api/forecastas usual. - Quote. The server answers
402 Payment Requiredwith a price, the token it accepts (USDC), and the address to pay. - Pay. The client signs a USDC transfer for that price.
- Retry. The client sends the same request again, with the signed transfer in a payment header.
- 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.
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.
Start the tutorial →Is this the right tool?
| Card billing | Credits and API keys | x402 on Solana | |
|---|---|---|---|
| Smallest charge | Set by fixed per-charge fees | A prepaid top-up | A fraction of a cent |
| Client setup | An account and a card | A signup, a key, and a balance | A wallet with USDC |
| Works for AI agents | Needs a person-issued card | After a person sets it up | Yes, with its own wallet |
| Billing code you maintain | Invoices, retries, disputes | A balance ledger | Receipts, 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