# What is L402? The Lightning payment protocol built for machines

> Machine-readable summary of https://payagents.io/l402.html. PayAgents Research, November 20, 2026.

L402 is an open protocol for charging for access to HTTP resources (APIs, data feeds, MCP tools) using Bitcoin's
Lightning Network. A server answers an unpaid request with `402 Payment Required` and a Lightning invoice. The client
pays the invoice, proves it cryptographically, and gets the resource. Between the client and the server there is no signup form, no API key to issue, no card on file.

The protocol was originally published by Lightning Labs under the name LSAT (Lightning Service Authentication Token)
and later renamed L402. It is one of two major revivals of HTTP 402 in the agent economy; the other is x402, which
settles in stablecoins such as USDC. PayAgents supports both.

## How the L402 handshake works

1. The client requests a paid resource, like any ordinary HTTP call.
2. The server responds `402 Payment Required` with a `WWW-Authenticate: L402` header carrying a macaroon and a
   Lightning invoice (a BOLT11 payment request).
3. The client pays the invoice over Lightning. The payment preimage it receives back is cryptographic proof of
   payment.
4. The client retries with an `Authorization: L402 <macaroon>:<preimage>` header. The server verifies the pair
   without touching a payment database and serves the resource.

Illustrative exchange (values shortened):

```
→ GET /api/v2/forecast
← 402 Payment Required
   WWW-Authenticate: L402 token="AgEEbGF...", invoice="lnbc300n1p..."

⚡ Client pays the invoice over Lightning

→ GET /api/v2/forecast
   Authorization: L402 AgEEbGF...:8f3c1a...preimage_hex
← 200 OK (forecast data)
```

Payment and authorization are the same object: the preimage both settles the invoice and unlocks the credential.
Verification is stateless: the server checks the macaroon with its root key, with no database lookup.

## The macaroon: not a cookie, a capability

The credential in an L402 challenge is a macaroon: a bearer token whose permissions are embedded as "caveats". A
service can encode what was bought, for how long, at what rate and up to what spend; the holder can add further
restrictions before passing it on. A macaroon is a bearer instrument: scope it tightly and treat it as a secret.

## A short history of HTTP 402

- 1997: RFC 2068 reserves status code 402 "Payment Required". No digital cash exists to use it.
- 2009: Bitcoin launches, the first decentralized digital cash to reach sustained global use.
- 2018: The Lightning Network reaches mainnet beta; near-instant, low-cost micropayments become practical.
- 2020: Lightning Labs publishes the LSAT specification (later L402) and Aperture, an LSAT/L402-aware reverse
  proxy it has used with its own services.
- 2023: Lightning Labs releases open-source tools that let AI agents send and receive Lightning payments;
  agent frameworks begin adopting L402.

## L402 vs x402: an honest comparison

| | L402 (Lightning) | x402 (Stablecoin) |
| --- | --- | --- |
| Settles in | Bitcoin (sats) over Lightning | USDC on an EVM chain (e.g. Base) |
| Unit of account | Sats: fixed BTC, floating fiat value | Dollar-denominated and stable |
| Cost floor | No chain gas; routing fees on tiny payments are typically a fraction of a sat to a few sats | Gas/settlement costs push toward larger amounts or batching |
| Settlement speed | Often about a second once a route exists; depends on route availability | Bounded by chain block/confirmation times |
| Credential | Macaroon + preimage; stateless; nothing to register | Signed transfer authorization from an EVM address; publicly linkable |
| Honest tradeoff | BTC denomination moves vs fiat; liquidity must be managed | Higher per-call cost and latency; funds sit on one chain |

Working view: tiny, constant, machine-priced calls are Lightning's home turf; dollar-denominated or higher-value
settlement fits stablecoins. The two will likely serve different price bands rather than one replacing the other.

## How PayAgents speaks L402

Setup note: the "no account" property describes the protocol exchange itself. Using L402 through PayAgents involves
a PayAgents account and a funded balance, or your own Lightning address on the seller side; what disappears is the
per-service signup between the agent and each endpoint it pays.

Seller side: one line of middleware gates any route; the handler runs only after payment is verified:

```ts
import express from 'express';
import { PayAgents } from 'payagents';

const pa = PayAgents.server({ apiKey: process.env.PAYAGENTS_API_KEY! });
const app = express();

app.post('/tool', pa.charge({ price: '0.002 USD' }).express(), (req, res) => {
  // Runs ONLY after payment is verified.
  res.json({ data: 'premium result' });
});

app.listen(3000);
```

Buyer side: an agent pays a compatible L402- or x402-gated endpoint within a budget (a bare 402 status alone is not enough; the endpoint must speak one of the two challenge schemes):

```ts
import { PayAgents } from 'payagents';

const client = new PayAgents({ apiKey: process.env.PAYAGENTS_API_KEY });

// Detects whether the challenge is L402 or x402 and routes the payment.
const response = await client.pay('https://api.example.com/gated-route', {
  maxAmount: '0.01 USD'
});
```

Sellers can receive sats directly to their own Lightning address, where PayAgents only verifies payments and never
takes custody, or use a managed USD balance while in beta. (Both SDK examples above are copied from the PayAgents docs and were not executed for this page.)

## FAQ

**What does L402 stand for?** L for Lightning, 402 for the HTTP status code "Payment Required". Formerly LSAT.

**Do I need to run a Lightning node?** Not necessarily. The protocol only requires that the client obtains the
preimage as proof of payment, so any funded Lightning wallet can pay. Sellers can self-host with tooling like
Aperture, or use a payment layer like PayAgents to handle invoices, verification and routing.

**Is L402 only for AI agents?** No. It is a general machine-to-machine payment and authentication scheme. AI agents
simply made the "no human present" problem urgent.

**Does PayAgents require L402?** No. PayAgents is multi-rail: it detects whether an endpoint challenges with L402 or
x402 and routes the payment over Lightning or USDC from one balance.

## Further reading

- L402 protocol specification: https://github.com/lightninglabs/L402
- L402 in the Lightning Builder's Guide: https://docs.lightning.engineering/the-lightning-network/l402
- Aperture, the reference L402 reverse proxy: https://github.com/lightninglabs/aperture
- PayAgents docs: https://payagents.io/docs.html
- Why AI agents will pay in Bitcoin: https://payagents.io/blog/why-ai-agents-will-pay-in-bitcoin.html
