L402 on NanoGPT: x402-style AI API payments over Lightning

NanoGPT now supports Lightning L402 for accountless API payments.
That means developers and agents can call supported NanoGPT API endpoints without creating an account, without pre-funding a balance, and without sending an API key. Make the request, receive 402 Payment Required, pay a Lightning invoice, then replay the exact same request with an L402 authorization header.
In short: it is the x402 pattern, but paid over Bitcoin Lightning.
What is L402?
L402 is a Lightning-backed payment proof for HTTP APIs. The server returns a 402 Payment Required response with a Lightning invoice and a token describing the quoted request. After paying the invoice, the client uses the Lightning payment preimage as proof and retries the request with:
Authorization: L402 <token>:<preimage>
In NanoGPT's accountless payment flow, this gives Lightning the same basic shape as x402:
- Make a normal API request.
- Receive
402 Payment Requiredwith payment instructions. - Pay.
- Replay or complete the request with payment proof.
For Nano, Base USDC, and Solana USDC, that proof is usually an X-PAYMENT header or a completeUrl flow.
For Lightning L402, the proof is the Authorization header. The token says what request was quoted. The preimage proves the Lightning invoice was paid.
Why this matters
Lightning L402 is useful for the same reason x402 is useful: it makes paid APIs programmable.
For developers, it removes signup and billing setup from quick experiments. For agents, it gives a direct machine-to-machine payment path. For privacy-minded users, it avoids account creation and long-lived API credentials for one-off requests.
Lightning adds a few nice properties:
- Fast settlement for small payments.
- Tiny payment amounts without card minimums.
- No EVM gas or stablecoin transaction setup for clients that already use Lightning.
- A familiar payment rail for Bitcoin-native apps, bots, and agents.
We also currently apply a 10% discount to lightning-l402 accountless quotes compared with the normal accountless quote. The quote includes both the discounted amount and the undiscounted amount when available.
How the flow works
Start with a normal unauthenticated request. Do not send Authorization or x-api-key.
curl -i https://nano-gpt.com/api/v1/data/web/search \
-H "Content-Type: application/json" \
-d '{
"query": "latest AI agent payment protocols",
"max_results": 3
}'
NanoGPT returns 402 Payment Required. If Lightning L402 is available for that endpoint, the response includes a lightning-l402 option:
{
"payment": {
"accepted": [
{
"scheme": "lightning-l402",
"network": "bitcoin-lightning",
"amountFormatted": "9 sats",
"amountUsd": "0.0054",
"invoice": "lnbc...",
"paymentHash": "...",
"l402Token": "...",
"discountRate": 0.1,
"undiscountedAmountUsd": "0.006"
}
]
}
}
The response also includes a WWW-Authenticate: Payment ... challenge header for clients that prefer HTTP auth challenge handling. Most integrations can simply read invoice and l402Token from the JSON body.
Pay the invoice with a Lightning client that returns the payment preimage. Then replay the exact same request:
curl -i https://nano-gpt.com/api/v1/data/web/search \
-H "Content-Type: application/json" \
-H "Authorization: L402 $L402_TOKEN:$PAYMENT_PREIMAGE" \
-d '{
"query": "latest AI agent payment protocols",
"max_results": 3
}'
If the token, preimage, amount, expiration, and request hash all check out, NanoGPT runs the original API request and returns the normal endpoint response.
Supported endpoints
The live source of truth is:
curl https://nano-gpt.com/api/v1/x402/endpoints
At launch, Lightning L402 is advertised for the stable accountless x402 endpoints:
POST /api/v1/images/generationsPOST /api/v1/images/editsfor JSON edit requestsPOST /api/v1/chat/completionsfor non-streaming requestsPOST /api/v1/responsesfor non-streaming requestsPOST /api/v1/data/web/searchPOST /api/v1/data/url/scrape
Streaming chat/responses and long-running video generation are not part of the stable public accountless contract yet.
Things to know before integrating
Lightning L402 does not use X-PAYMENT. Use:
Authorization: L402 <token>:<preimage>
It also does not use completeUrl. That endpoint is for quote-and-complete rails such as Nano and Base USDC direct payments. For Lightning L402, the completion step is replaying the original endpoint with the L402 authorization header.
The replay must match the original request that produced the quote. The L402 token is bound to the method, path, request body hash, quoted amount, and expiration. Each token/preimage pair can be used once.
One practical caveat: your Lightning client needs to expose the payment preimage. Many node APIs and developer-focused Lightning clients do; some consumer wallets do not. If a wallet only shows "paid" without returning a preimage, it is fine for normal payments but not enough for L402 replay.
Also, treat the L402 authorization header like a secret. The token and preimage together are bearer payment proof, so do not log them.
How this fits with NanoGPT x402
Lightning L402 is one more rail in NanoGPT's accountless API payment system. It sits alongside:
nanonano-exactbase-usdcx402-exactx402-solana-usdc
Use the live endpoint matrix to choose what is available for a given endpoint and deployment. If you want standard exact-payment x402, use the advertised X-PAYMENT rails. If you want Lightning, choose lightning-l402 and replay with Authorization: L402.
Get started
Read the docs:
https://docs.nano-gpt.com/api-reference/miscellaneous/x402
Inspect live endpoint support:
https://nano-gpt.com/api/v1/x402/endpoints
And if you just want to see the accountless payment flow in action:
No account required. Just a request, a quote, a Lightning invoice, and the response you asked for.