|
| 1 | +--- |
| 2 | +title: Smoke-Test Your L402 Integration in One Request |
| 3 | +description: A free public endpoint that charges 1 sat over L402 and returns a fortune — the quickest way to verify your lightning payment flow is wired up correctly. |
| 4 | +date: 2026-04-09 |
| 5 | +tags: ["402", bitcoin, lightning, l402, agents] |
| 6 | +image: /blog/images/2026-04-09-smoke-test-l402-integration.jpg |
| 7 | +imageAlt: A glowing cyan fortune cookie cracked open with a lightning bolt emerging from it, connected to a padlock icon via dotted lines on a dark navy background. |
| 8 | +--- |
| 9 | + |
| 10 | +When you're building an agent that pays for APIs over lightning, there's an awkward gap between "I wrote the code" and "I know it actually works." You need a live L402 endpoint that charges real sats, returns something meaningful, and doesn't require any setup on your side. [@CatalunyaLND](https://x.com/CatalunyaLND) built exactly that: a tiny fortune cookie API that costs 1 sat to call. |
| 11 | + |
| 12 | +## The Simple Way: One Command |
| 13 | + |
| 14 | +If your agent has the Alby payments skill installed, the entire L402 flow collapses to a single command: |
| 15 | + |
| 16 | +```bash |
| 17 | +npx skills add getAlby/payments-skill |
| 18 | +``` |
| 19 | + |
| 20 | +Then fetch the fortune endpoint: |
| 21 | + |
| 22 | +```bash |
| 23 | +npx -y @getalby/cli fetch -u https://l402-fortune-cookie.yf-ae7.workers.dev/api/fortune |
| 24 | +``` |
| 25 | + |
| 26 | +That's it. The CLI detects the 402 response, pays the invoice automatically, and returns the unlocked content: |
| 27 | + |
| 28 | +```json |
| 29 | +{ |
| 30 | + "content": "{\"fortune\": \"The answer you seek is hidden in the next block.\", \"paid\": true, \"sats_paid\": 1}" |
| 31 | +} |
| 32 | +``` |
| 33 | + |
| 34 | +One real payment, end-to-end, no manual steps. If this works, your L402 integration is wired up correctly. |
| 35 | + |
| 36 | +## A Free Sample Too |
| 37 | + |
| 38 | +If you just want to check connectivity without spending sats first, `GET /api/fortune/free` returns a fortune at no cost: |
| 39 | + |
| 40 | +```bash |
| 41 | +curl https://l402-fortune-cookie.yf-ae7.workers.dev/api/fortune/free |
| 42 | +``` |
| 43 | + |
| 44 | +```json |
| 45 | +{ |
| 46 | + "fortune": "Success is a journey, not a destination — but low fees help get there faster.", |
| 47 | + "paid": false, |
| 48 | + "note": "Free sample 🎁 — pay 1 sat at /api/fortune for the real experience" |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +## How L402 Works Under the Hood |
| 53 | + |
| 54 | +For those building their own L402 client, the endpoint exposes the full protocol clearly. A raw request to `/api/fortune` returns HTTP 402 with a `WWW-Authenticate` header: |
| 55 | + |
| 56 | +```bash |
| 57 | +curl -i https://l402-fortune-cookie.yf-ae7.workers.dev/api/fortune |
| 58 | +``` |
| 59 | + |
| 60 | +```http |
| 61 | +HTTP/2 402 |
| 62 | +www-authenticate: L402 macaroon="eyJ...", invoice="lnbc10n1..." |
| 63 | +
|
| 64 | +{ |
| 65 | + "error": "Payment Required", |
| 66 | + "message": "Pay 1 sat to unlock your fortune 🥠", |
| 67 | + "payment_request": "lnbc10n1...", |
| 68 | + "payment_hash": "5ef5d0f0...", |
| 69 | + "macaroon": "eyJ...", |
| 70 | + "instructions": "After paying, retry with: Authorization: L402 <macaroon>:<preimage>" |
| 71 | +} |
| 72 | +``` |
| 73 | + |
| 74 | +The five-step flow the server documents: |
| 75 | + |
| 76 | +1. `GET /api/fortune` → 402 + `WWW-Authenticate` with macaroon and invoice |
| 77 | +2. Pay the lightning invoice → receive preimage |
| 78 | +3. Poll `GET /api/fortune/status/:payment_hash` until `paid: true` |
| 79 | +4. `GET /api/fortune` with `Authorization: L402 <macaroon>:<preimage>` |
| 80 | +5. Receive your fortune |
| 81 | + |
| 82 | +The status polling endpoint lets you confirm payment before retrying — useful if you can't receive a webhook. The Alby CLI's `fetch` command handles all of this automatically. |
| 83 | + |
| 84 | +## Why This Endpoint Is Worth Bookmarking |
| 85 | + |
| 86 | +Most L402 tutorials end with a diagram. This endpoint lets you test the real thing — a live payment gate that responds to correct credentials and rejects bad ones. It's hosted on Cloudflare Workers, so it's fast and available globally. |
| 87 | + |
| 88 | +Use it early in development to confirm your payment flow is wired up. Use it in CI to catch regressions. And if you're building your own L402 server, use it as a reference for what the protocol should look like from the client's perspective. |
| 89 | + |
| 90 | +Thanks to [@CatalunyaLND](https://x.com/CatalunyaLND) for building and hosting it. |
| 91 | + |
| 92 | +## Conclusion |
| 93 | + |
| 94 | +`https://l402-fortune-cookie.yf-ae7.workers.dev` is the quickest smoke-test for L402 available. With the Alby payments skill, one command confirms the full payment flow works — for 1 sat. |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Get started |
| 99 | + |
| 100 | +Need a Lightning wallet for your agent? Create one in one command — no sign-up, no KYC: |
| 101 | + |
| 102 | +```bash |
| 103 | +curl -X POST https://lncurl.lol |
| 104 | +``` |
| 105 | + |
| 106 | +You'll get back a Nostr Wallet Connect URI. Fund it with a few sats and your agent can pay for APIs, services, and tools autonomously. |
| 107 | + |
| 108 | +Or give your agent the lncurl skill directly: [https://lncurl.lol/SKILL.md](https://lncurl.lol/SKILL.md) |
0 commit comments