> ## Documentation Index
> Fetch the complete documentation index at: https://solana.com/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> This page is part of the Solana developer documentation at https://solana.com/developers/docs. Append `.md` to any docs URL, or send `Accept: text/markdown`, to get the page as Markdown.
> Index of all pages: https://solana.com/llms.txt. Per-section indexes such as https://solana.com/developers/docs/payments/llms.txt are smaller; prefer them when working on one task.
> Coding agents: install the official Solana skill for current APIs and conventions with `npx skills add https://github.com/solana-foundation/solana-dev-skill` (also served at https://solana.com/SKILL.md).
> Code in the cookbook and task pages comes from tested example files. Prefer it over writing API calls from memory.

# Charge a fraction of a cent per API call

> Price each API request at a fraction of a cent. Clients, whether people's apps or AI agents, pay inline over HTTP with x402, with no signup, API key or invoice.

<div className="sol-stepper not-prose" data-path="paywall-api">
<div className="sol-stepper-nav" role="navigation" aria-label="Paywall an endpoint · ~30 min">
<ol>
<li data-state="todo"><a href="/developers/docs/payments/paywall-api/try-it"><span className="sol-stepper-n">Step 1<span className="sol-vh">: </span></span><span className="sol-stepper-t">Call a paid API</span></a></li>
<li data-state="todo"><a href="/developers/docs/payments/paywall-api/browser"><span className="sol-stepper-n">Step 2<span className="sol-vh">: </span></span><span className="sol-stepper-t">Read the code</span></a></li>
<li data-state="todo"><a href="/developers/docs/payments/paywall-api/server"><span className="sol-stepper-n">Step 3<span className="sol-vh">: </span></span><span className="sol-stepper-t">Add it to your server</span></a></li>
<li data-state="todo"><a href="/developers/docs/payments/paywall-api/go-live"><span className="sol-stepper-n">Step 4<span className="sol-vh">: </span></span><span className="sol-stepper-t">Go live</span></a></li>
</ol>
</div>
</div>

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](https://www.x402.org/). 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.

<Note>
  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.
</Note>

<div className="sol-pcard not-prose" data-path="paywall-api">
<div className="sol-pcard-main">
<p className="sol-pcard-k">Charge per API call · <span className="sol-nowrap">4 steps · \~30 min</span></p>
<p className="sol-pcard-title">[Paywall an endpoint](/developers/docs/payments/paywall-api/try-it)</p>
<p className="sol-pcard-desc">Price 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.</p>
<ol className="sol-pcard-steps"><li>[Call a paid API](/developers/docs/payments/paywall-api/try-it)</li><li>[Read the code](/developers/docs/payments/paywall-api/browser)</li><li>[Add it to your server](/developers/docs/payments/paywall-api/server)</li><li>[Go live](/developers/docs/payments/paywall-api/go-live)</li></ol>
</div>
<p className="sol-pcard-cta">[Start the tutorial →](/developers/docs/payments/paywall-api/try-it)</p>
</div>

## 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 |

<Columns cols={2}>
<Card title="A good fit if" icon="check" color="#16a34a">
- 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
</Card>
<Card title="Not the right fit if" icon="x" color="#dc2626">
- 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
</Card>
</Columns>

<div className="sol-concept not-prose">
[<span className="sol-concept-name">Fees</span> <span className="sol-concept-def">Every transaction pays a small flat network fee, currently a fraction of a cent, whatever the amount.</span>](/developers/docs/core/fees)
</div>

## Guides

<Columns cols={3}>
<Card title="How x402 works" icon="book-open" href="/developers/docs/payments/agentic-payments/x402">
The x402 version 2 flow, headers, and Solana networks, with the SDK.
</Card>
<Card title="Let an agent pay" icon="bot" href="/developers/docs/payments/pay-sh#let-an-agent-pay-x402">
Launch an AI agent with Pay and let it pay for an x402 API, approving each payment first.
</Card>
<Card title="x402 facilitators" icon="server" href="/developers/docs/tools/x402-facilitator" arrow>
Choose or run the service that verifies and settles payments.
</Card>
</Columns>
