Skip to main content

x402 over Lightning

x402 is an HTTP payment protocol: a server answers an unpaid request with 402 Payment Required and a PAYMENT-REQUIRED header describing how to pay, and the client retries with a PAYMENT-SIGNATURE header carrying proof of payment. Its exact scheme on the lnbtc network (Bitcoin Lightning) settles with a BOLT11 invoice and its preimage. Lightning Enable can offer that option on the same 402 that already carries the L402 and MPP challenges, so one paid endpoint can be bought by L402, MPP, and x402-over-Lightning clients.

Lightning Enable does not hold funds. Your payment provider (Strike) or your own Lightning wallet (over Nostr Wallet Connect) creates the invoice and facilitates custody and settlement; Lightning Enable checks the proof of payment and serves the request.

note

This option isn't available yet. It's switched off on api.lightningenable.com (L402:EnableX402Lnbtc, off by default) while it's being tested, so today a 402 carries no PAYMENT-REQUIRED header and a PAYMENT-SIGNATURE header is ignored. Everything on this page describes how it works once it's switched on. To buy from x402 sellers today, see the MCP server's access_l402_resource tool.

Which surfaces and lanes offer it​

x402 is offered on:

  • The reverse proxy, https://api.lightningenable.com/l402/proxy/{proxyId}/{path}.
  • L402-gated routes served by the L402 middleware (for example the premium guides), when the seller is fixed by configuration. A request that sends an X-API-Key header, which can choose the seller on these routes, gets no x402 option.

The producer API (POST /api/l402/challenges) doesn't offer x402.

An x402 invoice must commit to the request it pays for, through a BOLT11 description hash. Only payment lanes that let Lightning Enable set that hash can offer it:

Lanex402 offeredWhy
StrikeYesStrike's receive requests accept bolt11.descriptionHash
Nostr Wallet ConnectYes, if the wallet honors itNIP-47 make_invoice accepts description_hash
OpenNodeNoThe charge API has no description-hash field
Lightning AddressNoLNURL-pay fixes the description hash to the receiver's own metadata

On every lane, Lightning Enable decodes its own invoice before advertising x402 and checks the signed description hash, the signer, the amount, the network, the expiry, and the creation time. If any check fails (for example a wallet that ignored the description hash), that 402 carries the L402 and MPP challenges only.

How one invoice serves three protocols​

With x402 offered, the invoice behind the 402 is created with the request's description hash instead of a text description, and an expiry of exactly maxTimeoutSeconds (600 seconds by default). L402 and MPP don't read either field, so the same invoice backs:

  • WWW-Authenticate: L402 macaroon="...", invoice="..."
  • WWW-Authenticate: Payment ... (MPP)
  • PAYMENT-REQUIRED: <base64 JSON> (x402)

Pay the invoice once and redeem it with any of them. Single use applies within the x402 and MPP draft-00 profiles: a payment redeemed through x402 settles once (the same proof again gets duplicate_settlement) and can't also be redeemed as an MPP draft-00 credential, and the reverse. The classic L402 token over the same invoice is not single use: it stays valid until its own expiry, as it always has. So one payment buys at most one x402 request in addition to what the L402 token already allows.

Every 402 that offers x402 has a fresh invoice. Lightning Enable never re-serves an x402 invoice to another request, client, or challenge. Because those invoices can't come from the challenge cache that otherwise collapses a client's repeated unpaid requests onto one invoice, each client (an IPv4 address, or an IPv6 /64 network) gets at most a few x402 invoices per proxy per minute (L402:X402MintsPerClientPerWindow, default 3, per L402:X402MintWindowSeconds, default 60). Past that, the client gets the ordinary cached 402 with the L402 and MPP challenges and no PAYMENT-REQUIRED, exactly as with x402 switched off; never a 429. The x402 specification defines no request header a client could send to ask for x402 up front.

The x402 challenge​

The PAYMENT-REQUIRED header decodes to a PaymentRequired object with one Lightning option:

{
"x402Version": 2,
"error": "PAYMENT-SIGNATURE header is required",
"resource": { "url": "https://api.lightningenable.com/l402/proxy/forecast-api-a1b2/today?city=Lisbon" },
"accepts": [
{
"scheme": "exact",
"network": "lnbtc:000000000019d6689c085ae165831e93",
"amount": "25000",
"asset": "BTC",
"payTo": "02...",
"maxTimeoutSeconds": 600,
"extra": {
"assetTransferMethod": "bolt11",
"paymentFlow": "upfront",
"requestHash": "<64 hex characters>",
"requestBindingProfile": "http:1",
"requestBindingParams": { "headers": [] },
"invoice": "lnbc250n1..."
}
}
]
}
  • amount is in millisatoshis: the price in sats times 1,000.
  • payTo is the public key that signed the invoice: your wallet's node key on the Nostr Wallet Connect lane, or Strike's node key on the Strike lane.
  • Only Lightning mainnet is offered.

The signing key (payTo)​

x402 identifies the seller by payTo, the key that signed the invoice. Which key that is depends on the payment lane:

LanepayTo isShared with other sellers
StrikeStrike's node keyYes, every seller that settles through Strike
Nostr Wallet Connect, hosted wallet serviceThe wallet service's node keyYes, every account on that service
Nostr Wallet Connect, your own nodeYour node's keyNo

On a hosted lane, payTo therefore names the provider that facilitates custody and settlement, not you. Lightning Enable accepts this and compensates for it on its side: a signature from the right key is never enough to be served. The invoice must also be one Lightning Enable issued for your account and for this exact request, so a paid invoice from another seller on the same provider is refused.

What this means for buyers: a client that keeps an allowlist of payTo keys, or treats payTo as the seller's identity, sees the same key for unrelated sellers on a hosted lane. Identify the seller by the resource URL, and use payTo only for the check the scheme defines (the invoice is signed by the advertised key). If you need a payTo that is yours alone, settle into your own node over Nostr Wallet Connect.

The request binding​

requestHash binds the payment to one exact request, using the spec's http:1 profile: the HTTP method, the absolute URL (with its query string, exactly as sent), a SHA-256 hash of the body, and the Content-Encoding and Content-Type headers (listed in requestBindingParams.headers; an absent header is bound as absent). The list is one setting for every proxy and gated route (L402:X402BoundHeaders); a per-proxy list is future work.

  • The URL's origin is Lightning Enable's configured public origin (https://api.lightningenable.com), never a value taken from the request. A request addressed to another host name gets no x402 option.
  • Bodies up to the proxy's request-size limit (1 MB by default) are bound. A larger body gets no x402 option.
  • Other headers aren't bound. If your upstream API returns different content for different Accept (or other header) values, a buyer who changes that header on the paid retry gets the response for the new value. Design priced routes so that the URL, body, and content type select what is bought.
  • On a request paid with x402, the proxy doesn't forward method-override headers (X-HTTP-Method-Override, X-HTTP-Method, X-Method-Override) to your API, because the payment is bound to the HTTP method. Requests paid with L402 or MPP are forwarded unchanged.

A paid retry must repeat the same method, URL, body, and bound headers. A proof for one request doesn't buy another: a different query string, method, body, or content type is refused. If the route's price changes between the 402 and the paid retry, the paid proof is still honored once at the price it was issued for.

Pay and retry​

  1. Read PAYMENT-REQUIRED, check the option as the x402 exact/lnbtc scheme requires, and pay extra.invoice with a Lightning wallet that returns the preimage.

  2. Retry the same request with a PAYMENT-SIGNATURE header: the base64 of a PaymentPayload that echoes the chosen option as accepted and carries the preimage:

    { "x402Version": 2, "accepted": { "scheme": "exact", "...": "..." }, "payload": { "preimage": "<64 hex characters>" } }
  3. A settled payment is answered by the API with a PAYMENT-RESPONSE header:

    { "success": true, "transaction": "<payment hash>", "network": "lnbtc:000000000019d6689c085ae165831e93" }

    transaction is the invoice's payment hash. Lightning reveals no payer, so payer is omitted.

Lightning Enable checks the proof against its own view of the request, not against the values the client echoes: it recomputes the request hash, prices the route again, and requires the invoice to be one it issued for this seller and this request. It never logs the preimage or the invoice.

If an Authorization header carries an L402 or MPP credential, that credential is used, exactly as before, and PAYMENT-SIGNATURE is ignored.

Errors​

HTTP statusWhenWhat you get
400The PAYMENT-SIGNATURE header can't be read: not base64 JSON, duplicate member names, nested deeper than 64 levels, longer than 16,384 characters, x402Version other than 2, or no accepted/payload objectPAYMENT-RESPONSE with errorReason invalid_payload or invalid_x402_version, and a JSON body with error: "invalid_payment"
402The payment was refusedA fresh challenge (L402, MPP, and x402 when offered) and PAYMENT-RESPONSE with the spec's errorReason, for example invalid_exact_lnbtc_request_mismatch, invalid_exact_lnbtc_preimage_hash_mismatch, invalid_exact_lnbtc_invoice_expired, or duplicate_settlement

The other answers of a paid route are unchanged: a paused proxy answers 503 proxy_paused, an unreachable wallet 503 payment_provider_unreachable, and so on. See Errors.

Delivery failures​

If the request can't be delivered after the payment settles, and nothing reached the upstream API (for the proxy) or the client (for gated routes), the payment is released so you can retry with the same PAYMENT-SIGNATURE. Once the upstream API has been contacted, the payment stays used.

Known limits​

  • On L402-gated routes (not the proxy), a delivery that ends with a 4xx or 5xx status and no body releases the payment, so the same proof can be presented again. This is the rule MPP draft-00 already follows there.
  • The proxy never forwards PAYMENT-SIGNATURE to your API, whether x402 is switched on or off.
  • The list of bound headers is the same for every proxy and gated route. Which further request headers should be bound or withheld from your API is still being decided.

Browser clients​

The proxy's CORS policy allows the PAYMENT-SIGNATURE request header from any origin and exposes PAYMENT-REQUIRED and PAYMENT-RESPONSE, so a page on any site can read the challenge and send the payment.