HTTP 402: the feature the web forgot

HTTP status code 402 — "Payment Required" — was defined in RFC 1945 in 1992. The specification notes that the code is "reserved for future use" and that it is intended to be used "when some form of digital cash or micropayment scheme is implemented." It has been in the HTTP specification for over thirty years. It has never been meaningfully implemented.

The reason is not technical. HTTP 402 is trivially implementable at the protocol level — it's a status code like any other. The reason it was never implemented is that there was no payment primitive that could deliver on what 402 implied: a machine-to-machine payment that required no intermediary, settled instantly, worked for any amount (including sub-cent amounts), and could be automated without identity verification or pre-established billing relationships.

Credit cards don't meet these requirements. They require identity verification, have per-transaction minimums that make sub-cent payments economically impossible, carry chargeback risk that makes them unsuitable for automated machine transactions, and take days to settle finally. Bank transfers have similar identity requirements and settle even more slowly. PayPal and Stripe add API layers on top of credit cards but inherit all their fundamental limitations.

The web that was built without 402 implemented is a web that monetizes attention (advertising) rather than value (payment per use). Every API that requires a subscription rather than per-call payment, every content site with an ad load rather than a microtransaction model, every service that requires account creation rather than pay-as-you-go — all of these are workarounds for the absence of a payment primitive that works at machine scale.

The architectural gap: the internet was designed with HTTP but not HTTP 402. Lightning Network closes the gap — it is the payment primitive that makes 402 implementable. And autonomous AI agents are the first large-scale consumer that actually needs it.

L402: machine-to-machine payments for real

L402 is an open protocol, developed at Lightning Labs, that implements HTTP 402 using Lightning Network payments and macaroon-based access tokens. The name is a combination of "Lightning" and "402." The protocol is live in production and is the basis for Lightning-native API monetisation.

The flow is elegantly simple. A client makes an HTTP request to an L402-protected resource. The server responds with 402 and a WWW-Authenticate header containing a Lightning invoice (a payment request) and a macaroon (a cryptographically signed token that encodes access rules). The client pays the invoice, which proves they control the funds to meet the payment requirement. They then attach the paid invoice preimage to the macaroon, creating an LSAT (Lightning Service Authentication Token). They resubmit the original request with the LSAT in the Authorization header. The server verifies the preimage, confirms the payment was made, and grants access.

Macaroons are more powerful than simple tokens. They can encode access constraints directly in the token: this LSAT is valid for 10 API calls, or valid until a specific timestamp, or valid only for specific resource paths, or valid only if the request comes from a specific IP range. These constraints are enforced cryptographically — you can't modify a macaroon without invalidating its signature. This makes L402 suitable for sophisticated access control scenarios that would otherwise require a complex server-side policy engine.

For autonomous agents, L402 is transformative. An agent can acquire API access for exactly the resources it needs, at exactly the moment it needs them, for exactly the duration it needs them, without any pre-established account relationship. An agent that needs to call a data API once to answer a question pays for that one call. An agent running a long research task acquires a time-bounded LSAT for the duration of the task. No subscription, no credit card, no human approval required.

How Lightning channels work

Lightning is a layer-2 protocol built on Bitcoin. Understanding how it works at the channel level matters for building production systems, because the operational properties of Lightning channels — liquidity constraints, routing, failure modes — directly affect how you architect agent payment flows.

Channel opening: the funding transaction

A Lightning channel is opened by broadcasting a funding transaction to the Bitcoin blockchain. The funding transaction locks funds into a 2-of-2 multisig output — an on-chain UTXO that requires signatures from both channel parties to spend. The amount locked into this output is the channel capacity. Once the funding transaction confirms (typically one confirmation, though some wallets require more), the channel is open and payments can flow.

Opening a channel costs a Bitcoin transaction fee and typically takes 10-60 minutes to confirm. This is a one-time cost. Once the channel is open, any number of off-chain payments can flow through it instantly at near-zero marginal cost. The on-chain settlement is deferred until the channel is closed.

Commitment transactions: off-chain state updates

Every payment across a Lightning channel updates the channel state without touching the blockchain. The mechanism is commitment transactions: each payment produces a new valid (but unbroadcast) transaction that both parties could use to close the channel. The previous commitment transaction is invalidated by exchanging revocation keys. At any point, either party can unilaterally close the channel by broadcasting their most recent commitment transaction.

This mechanism is what makes Lightning non-custodial. You don't have to trust the counterparty because you can always close the channel and claim your funds on-chain. The threat of unilateral close is what keeps both parties honest — if a counterparty tries to broadcast an old (revoked) commitment transaction, you can use the revocation key to claim all their channel funds as a penalty. This penalty mechanism is the cryptographic enforcement that replaces institutional trust in traditional payment networks.

HTLCs: routing across multiple hops

Payments across the network that don't have a direct channel between sender and receiver route through intermediary nodes via Hash Time-Locked Contracts (HTLCs). An HTLC is a conditional payment: "I will pay you X if you can produce the preimage R such that hash(R) = H, before timestamp T."

The payment originates as: sender locks funds in HTLC to intermediate node A, conditional on the preimage. Node A locks funds to node B under the same condition. Node B locks funds to the recipient. When the recipient claims payment by revealing the preimage, each node in the chain claims their locked funds by passing the preimage back upstream. Settlement propagates backwards through the routing path, with each node claiming their funds in sequence. The payment is atomic: either every hop settles or every hop times out and refunds. There is no state where partial payment occurs.

For multi-hop payments, routing fees are tiny — typically 1-10 parts per million of the payment amount. A 1,000 sat payment routed through three hops might pay a total of 3 sats in routing fees. This is the order of magnitude that makes micropayments economically viable.

Micropayments that actually work

Lightning's practical minimum payment is approximately 1 millisatoshi (0.001 sat), though most wallets enforce a floor of 1 sat (roughly $0.0006 at current prices). This enables payment denominations that are genuinely sub-cent: 100 millisats per API call, 10 sats per kilobyte of data, 1 sat per inference token.

The comparison to on-chain Bitcoin illuminates why layer 2 is necessary for machine payments. An on-chain Bitcoin transaction typically carries fees of $0.50-$5 depending on network conditions. No rational operator structures their API pricing to charge $0.001 per call when the settlement cost is $1. Lightning collapses this cost structure: fees are fractions of a cent per payment, enabling pricing at any granularity the market wants to support.

For agent systems specifically, the pricing models that become viable at Lightning's granularity change the economics of agent deployment substantially. An agent that pays $0.001 per API call for exactly the calls it makes is operating on a fundamentally different cost structure than one that pays $200/month for an API subscription it may use lightly. The marginal cost aligns with the marginal benefit. Agents can compose API calls freely without concern for wasted subscription spend.

Agent custody: wallets, spending limits, automated channel management

Deploying autonomous agents with Lightning payment capability requires decisions about custody that don't have obvious analogies in traditional software. An agent that can spend funds is an agent with a security surface area that requires explicit architectural treatment.

Hot wallet architecture

Agent payments require hot wallets — wallets with private keys accessible to the running process. This is unavoidable: the agent needs to sign payment authorisations in real time without human intervention. The implication is that the funds in the hot wallet are always at risk from a compromised process.

The operational pattern is to size agent hot wallets for expected spending over a short horizon (hours to days), not for the total funds the agent system might eventually spend. An agent that is expected to spend 10,000 sats per day should have a hot wallet with 50,000-100,000 sats — enough buffer for operational variation, not the entire treasury. Funds are topped up automatically from a cold or warm store when the hot wallet balance falls below threshold. The topup mechanism requires a separate process with separate key access, limiting the blast radius of any single compromise.

Spending limits

Lightning wallet software provides native spending limit capability: maximum per-payment amount, maximum per-period total spend, time windows for automated payments. These limits should be set conservatively and enforced at the wallet level, not in application code — application-layer limits can be bypassed by bugs or adversarial inputs; wallet-level limits cannot.

For multi-agent systems, spending limits should be hierarchical. A worker agent has a smaller limit than the orchestrator; the orchestrator has a smaller limit than the treasury management process. Limits should reflect the expected operational envelope of each role, not a general policy applied uniformly.

Automated channel management

An agent that makes many outbound payments will drain outbound liquidity from its channels. An agent that receives many inbound payments will drain inbound liquidity. A production agent with unmanaged channel liquidity will start failing payments when channels run dry on one side.

Automated rebalancing handles this: periodic circular payments that move liquidity from channels with excess outbound to channels with excess inbound, keeping both sides of the channel usable. Tools like Balance of Satoshis (BoS) and RTL automate this for LND nodes. The cost of rebalancing is small routing fees; the alternative (failed payments) is worse. For production systems, channel rebalancing should be automated, monitored, and alerting when rebalance costs exceed threshold.

LND, CLN, LDK: which one for programmatic access

There are three production-grade Lightning implementations worth knowing for developers building programmatic Lightning access. They differ in architecture, language, interface style, and community focus in ways that matter for agent systems.

LND (Lightning Network Daemon)

LND is the implementation with the broadest ecosystem, the most third-party tooling, and the most documented production deployments for agent and automated payment use cases. It is written in Go, maintained by Lightning Labs (the same team that developed L402), and exposes a gRPC API and REST API. The gRPC API is the right choice for programmatic access: it provides type-safe, efficient bindings in most languages, with generated clients available for Go, Python, JavaScript, Rust, and others.

For agent systems, LND is typically the right starting point. The ecosystem — Balance of Satoshis for node management, LNDHub for custodial wallet access on top of LND, Loop for submarine swaps to manage channel liquidity, Pool for channel lease marketplace access — provides production operations tooling that would otherwise need to be built from scratch.

CLN (Core Lightning, formerly c-lightning)

CLN is Blockstream's implementation, written in C with a plugin architecture that allows extending the node with arbitrary functionality. The plugin architecture is more powerful for building custom node behaviour than LND's equivalent; CLN plugins can add new RPC commands, intercept payment flows, and implement custom routing logic. This makes CLN the better choice for teams building Lightning functionality that doesn't fit standard patterns.

CLN exposes a JSON-RPC interface over a Unix socket, and a REST API via a plugin. The community is highly technical; CLN tends to be ahead of LND on protocol implementation of new Lightning specifications, though often behind on ecosystem tooling and documentation.

LDK (Lightning Development Kit)

LDK is a library rather than a daemon. It provides Lightning protocol implementation components that can be embedded in any application without requiring a separate node process. LDK is written in Rust and is designed for mobile wallets and applications where running a full node is impractical.

For agent systems that need embedded Lightning capability — an agent process that handles its own payments without depending on a separate Lightning node — LDK is the right choice. The operational complexity of managing a daemon and its connectivity is eliminated; the application owns its own Lightning keys and payment state. The tradeoff is that you're responsible for more of the infrastructure: channel persistence, peer connectivity, and routing must all be handled in your application rather than delegated to a daemon.

Recommendation for programmatic agent access: Start with LND unless you have a specific requirement that CLN's plugin architecture or LDK's embedded model addresses. LND's ecosystem depth, documentation quality, and L402 tooling makes it the path of least resistance for production agent payment infrastructure.

The streaming money paradigm

Streaming money is the paradigm enabled by Lightning that has no equivalent in traditional finance. The concept is payment that flows continuously, proportional to value delivered in real time, with no accumulation period, no monthly invoice, no settlement delay. Pay by the second. Pay by the byte. Pay by the token. Pay until you stop, and stop paying the moment you stop receiving value.

The implementation is Keysend or AMP (Atomic Multi-Path) payments sent in a rapid series — effectively a payment stream at whatever granularity the economics justify. For compute workloads, 1-second payment intervals are practical. For data streams, payment per kilobyte. For inference, payment per 1,000 tokens of context and output.

The implications for agent economics are significant. An agent running a research task that calls multiple APIs over 20 minutes pays for exactly 20 minutes of API time, not a monthly subscription that covers the same APIs for all-hours access. If the agent finds the answer in 3 minutes, it pays for 3 minutes. If the task runs longer than expected, it pays for exactly the extended time. The payment tracks the consumption curve with no overhead, no reconciliation, and no billing dispute.

For human applications, streaming money changes content and service monetisation fundamentally. A podcast listener pays 10 sats per minute while listening and stops paying when they pause. A newsletter reader pays per article opened. A SaaS tool charges per active second of use rather than per month of subscription. These models have been theoretically possible for decades; they become practically implementable when the payment primitive can handle sub-cent, sub-second settlement without overhead. That's Lightning.

Why stablecoins on other networks don't solve this

The objection that comes up every time Lightning's role as machine payment rail is discussed: "Why not USDC on Ethereum? Why not some stablecoin on some other network? Price stability matters for agents transacting in amounts where Bitcoin volatility is material."

The objection has surface plausibility and fails on examination. The issues are settlement finality, trust requirements, and throughput constraints.

Settlement finality

Ethereum finality is probabilistic and takes minutes to achieve practical irreversibility under normal conditions. Under congestion (which happens regularly), it takes longer and costs more. Lightning settlement is cryptographic and immediate — the preimage exchange is the settlement. There is no "wait for enough confirmations" stage. For automated agent payment flows that may involve thousands of transactions per hour, a settlement latency that averages 15-30 seconds per transaction is not viable.

Ethereum layer-2s (Optimism, Arbitrum) improve throughput and reduce fees substantially, but retain a trust assumption on the sequencer during normal operation, with fraud proof windows of hours to days for dispute resolution. Lightning's trust model is enforced by Bitcoin's timelock and script mechanisms without any trusted sequencer. The security model is meaningfully different.

Trust requirements

Every stablecoin is an IOU issued by a centralized entity — Circle for USDC, Tether for USDT. Holding stablecoins means holding a claim on a counterparty. That counterparty can freeze accounts, block transfers, reverse transactions in coordination with governments, and de-peg if the underlying reserves are managed incorrectly. All of these events have happened in production, with documented examples of each. For autonomous agents managing treasury, the counterparty risk of a stablecoin issuer is a systemic risk that can't be hedged away.

Bitcoin on Lightning has no issuer. The sats in a Lightning channel are sats on Bitcoin, enforced by Bitcoin's proof-of-work security. There is no entity that can freeze them, reverse the payment, or change the rules. For machines operating without human supervision across long time horizons, this matters.

Throughput and cost at micro-scale

Even on efficient EVM chains, the gas costs for small token transfers (under $1) represent a disproportionate fraction of the transfer value. A $0.001 USDC transfer costs more in gas than the transfer amount on most EVM networks. Lightning has no equivalent floor — sub-cent payments work as well as multi-dollar payments, with routing fees measured in millisatoshis.

Production patterns: LSPs, MPP, hold invoices

Building production Lightning payment infrastructure for agent systems requires understanding three patterns that address common operational challenges at scale.

LSPs: solving the inbound liquidity problem

A new Lightning node has no inbound liquidity — no one has opened channels to it, so it cannot receive payments. For an agent system that needs to receive Lightning payments from day one, this is a bootstrapping problem. Lightning Service Providers (LSPs) solve it by opening channels to your node in exchange for a fee or a channel lease.

LSPS (Lightning Service Provider Specification) is the emerging standard protocol for LSP interactions. An agent node can programmatically request a just-in-time channel from an LSP when it needs to receive a payment it doesn't have inbound capacity for. The LSP opens a channel, the payment flows, the agent pays a small fee for the channel lease. This eliminates the manual channel management problem for inbound liquidity.

Production providers offering LSP services include Voltage (infrastructure), Amboss (routing and analytics), and Blocktank (LSP API). For most agent deployments, the right operational pattern is to run your own LND or CLN node with LSP-sourced inbound liquidity rather than relying on custodial solutions.

MPP: multi-path payments for large amounts

A single Lightning payment is limited by the capacity of the smallest channel along its route. For payments above a few hundred thousand sats, a single path is frequently unavailable. Multi-Path Payments (MPP) split a single payment into multiple smaller payments that route through different paths and are assembled atomically at the destination.

MPP is now standard in all three major implementations and is used automatically by modern wallets for payments that exceed single-path capacity. For agent systems making larger payments — treasury management, inter-agent settlements at scale — MPP is what makes those payments practical without requiring single channels with capacity for the maximum expected payment size.

Hold invoices: atomic swaps and escrow

A standard Lightning invoice settles immediately when the recipient claims the payment. Hold invoices (also called HODL invoices) add a delay between when the funds are locked by the payer and when the recipient claims them. The payment is locked but not settled until the recipient deliberately claims it — or times out and reverts to the sender.

This mechanism enables atomic swap patterns: the recipient commits to delivering a service (a data batch, a code artifact, an API response) and claims the payment only after successful delivery. The payer's funds are committed during the escrow period — they can't double-spend — but the recipient doesn't receive them until the delivery condition is met. If the delivery fails or the recipient never claims, the funds automatically revert to the sender when the timelock expires.

For agent-to-agent commerce in multi-agent systems, hold invoices enable trustless task assignment: an orchestrator commits to paying a worker agent, the worker performs the task, delivers the result, and claims the payment. If the worker fails to deliver before the timeout, the orchestrator's commitment expires and the funds are available for a retry with a different worker. This is payment-enforced service-level agreements without a trusted intermediary.

The vision that motivated HTTP 402 in 1992 — a machine-readable payment signal that enables web-native micropayments — is implementable today. It requires Lightning. It requires L402. It requires the operational patterns documented above. The tooling exists; the protocols are stable; the infrastructure is in production.

The first large-scale users of this infrastructure are autonomous AI agents. They are not constrained by the inertia of human payment habits, the friction of account creation, or the institutional requirements that made micropayments unworkable in traditional finance. Agents will pay per call. Agents will stream payment per token. Agents will settle escrow atomically on task completion. The HTTP 402 future is an agent future, and the rail it runs on is Lightning.