Ask402

What is L402?

Short answer

L402 is a standard from Lightning Labs for charging for web resources with bitcoin over the Lightning Network. A server answers with status 402, a token and a Lightning invoice. The client pays the invoice, which reveals a secret, and presents the token with that secret to get access. The token, usually a macaroon, can be reused for later requests.

The short version

L402 puts a price on an HTTP request and takes payment in bitcoin, through the Lightning Network. Lightning Labs, which develops it, describes it as "the standard for selling and buying digital resources".

It is older than x402 and was earlier known as LSAT. Some servers still send that name.

How a payment works

  1. The client asks for a resource.
  2. The server replies 402 with a WWW-Authenticate: L402 header holding two things: a token and a Lightning invoice.
  3. The client pays the invoice. Paying it reveals a secret called the preimage.
  4. The client repeats the request with Authorization: L402, sending the token and the preimage together.
  5. The server checks them and returns the resource.

The token is tied to the invoice. A valid token with the matching preimage shows that the invoice was paid.

The two ideas that make it work

IdeaWhat it isWhy it matters
PreimageA secret released only when a Lightning invoice is paidIt is the proof of payment. No one can produce it without paying
MacaroonThe recommended token formatA server can verify one "using only a root key and basic cryptography", with no lookup in a payments database

Macaroons have one more property. Whoever holds one can narrow what it allows before passing it on, for example to a sub-agent with fewer rights.

A pass, not just a payment

In x402, a standard payment buys one response. In L402, the buyer ends up holding a credential. The server decides what that credential is good for: one request, a hundred, or a period of time. So L402 naturally sells access as well as single calls.

What you need

  • To pay: a Lightning wallet holding bitcoin, and a client that understands L402.
  • To charge: a Lightning node or service to issue invoices, and something that speaks L402 in front of your API.

Lightning Labs publishes Aperture for the second part. It is an open-source reverse proxy that issues the invoices and tokens and forwards paid requests to your backend. It handles both gRPC and REST. Lightning Labs' own Loop service uses it.

Key facts

Developed byLightning Labs
Formerly calledLSAT
Pays withBitcoin over the Lightning Network
Prices are inSatoshis, the smallest unit of bitcoin
HTTP status402 for the first challenge
Token formatMacaroons recommended
Reference proxyAperture

L402 and x402

They share a status code and a goal. They differ in the money and in what the buyer holds afterwards. L402 is bitcoin only. x402 works across many blockchains and is mostly used with dollar stablecoins.

They also overlap. The x402 repository includes a specification for its exact scheme on Bitcoin Lightning, where the proof of payment is likewise the invoice preimage.

The full comparison, and which to choose, is in x402 vs L402.

See one

The 402 checker recognizes L402 replies, including older ones that use the LSAT name, and shows the invoice amount.

Sources

Facts checked against these sources on . Protocols change, so the official specification wins if it disagrees with this page. Read this page as Markdown.

Who writes this. Ask402 is published by Havok Holdings LLC, which also runs Agent402, one of the x402 services covered here. Agent402 is labelled wherever it appears. Everything else is described from each project’s own documentation, and nobody pays to be listed.