An agent pays $0.001 to find a book and $0.01 to buy its complete public-domain text — Project Gutenberg boilerplate stripped, split into chapters, delivered as markdown JSON in the same response. No key, no account, nothing to download afterwards.
git clone https://github.com/nirholas/x402-books
cd x402-books && npm install
npm run dev
| Route | Price | Returns |
|---|---|---|
GET /search | $0.001 | Editions with authors, first publication year, subjects, cover, OpenLibrary ebook access level — and, where the complete text is buyable here, a ready-to-call `readPath` |
GET /read/:gutenbergId | $0.01 | The entire book: metadata, front matter, and one entry per chapter with its markdown body and word count — licence boilerplate already stripped |
GET /, GET /health, GET /.well-known/x402 |
free | Service info, liveness, discovery manifest |
Every paid route returns the purchased artifact in the 200 response body.
The 402 challenge advertises both. Your client picks whichever it can sign.
base-sepolia · base on mainnetsolana · solana-devnet on devnetimport { wrapFetchWithPayment, createSigner } from "x402-fetch";
const signer = await createSigner("base-sepolia", process.env.PRIVATE_KEY!);
const payFetch = wrapFetchWithPayment(fetch, signer);
const res = await payFetch(
"http://localhost:4025/search?q=frankenstein&limit=2"
);
const artifact = await res.json(); // purchased artifact, in-response