← AUTOMATER NEWSROOM

Lightning Labs' pi402 Lets Coding Agents Pay for Their Own Inference in Bitcoin, Per Token

Lightning Labs' pi402 pays for LLM inference in bitcoin per token from inside a coding agent, with built-in spend caps and no API keys, accounts or Lightning node needed.

Diagram of a Pi coding agent sending a prompt, receiving a 402 challenge with a macaroon and invoice, paying it over Lightning, and getting a completed credential back, with a budget panel below showing a per-request sats ceiling and a daily sats cap each partly filled.Diagram of a Pi coding agent sending a prompt, receiving a 402 challenge with a macaroon and invoice, paying it over Lightning, and getting a completed credential back, with a budget panel below showing a per-request sats ceiling and a daily sats cap each partly filled.
How pi402 turns an HTTP 402 response into a completed Lightning payment and a usable credential, with spend caps checked before the wallet signs.

Lightning Labs published pi402 on November 12, 2026: an open-source extension for the Pi coding-agent harness that pays for its own LLM inference in Bitcoin, one token at a time, with no account, no API key and no card on file. When a model call comes back with an HTTP 402, the agent’s own embedded wallet settles the invoice over the Lightning Network and the request completes, invisibly to whoever is prompting the agent.

For anyone running autonomous or budget-capped agent fleets, the practical change is where the spend limit lives. Instead of a usage dashboard on a vendor’s website, pi402 enforces a per-request ceiling and a daily cap inside the harness itself, checked against each quote before the wallet ever signs a payment. Fund the agent with a fixed amount of sats and that amount is the hard ceiling for what it can spend that day, full stop.

Why Lightning instead of a card

Lightning Labs’ announcement post frames the problem in terms sellers of inference already feel: a card payment is reversible for 60 to 120 days, but the GPU time behind a completed response is spent the moment it’s served. The post cites CEO Dax of OpenCode posting a screenshot of blocked card fraud in the hundreds of millions of dollars over a few days on OpenCode’s own Stripe dashboard — a claim from Lightning Labs’ own writeup, not independently verified here, but it is the company’s stated reason for betting on a non-reversible rail. A Lightning payment settles in seconds and finally; there’s no chargeback to defend against because there’s nothing left to reverse.

Lightning Labs blog post titled Announcing pi402, showing the November 12, 2026 article introducing bitcoin-paid inference for coding agents.
Lightning Labs' November 12, 2026 blog post announcing pi402, captured at the top of the article where it introduces paying for AI inference with bitcoin from inside a coding agent. · Original source

How the payment becomes the API key

The mechanism is L402, the HTTP-402-based scheme Lightning Labs has run in production since 2020. An unauthenticated request gets a 402 response carrying a macaroon (a cryptographic bearer credential) and a Lightning invoice. The macaroon commits to the invoice’s payment hash as a caveat; paying the invoice reveals a preimage, and macaroon-plus-preimage together form a complete, valid credential. Per Lightning Labs’ protocol docs, the server can verify that credential statelessly, with no database lookup and no account to have created in the first place.

pi402 also answers a newer, competing standard. Stripe and Tempo have proposed the Payment HTTP Authentication Scheme, an IETF draft (MPP) with a similar shape but native support for session-style running balances. Lightning Labs’ reverse proxy, Aperture, now ships both in its v0.6.0 release, advertising L402 and MPP on the same 402 challenge and letting the buyer’s client pick whichever it understands. pi402 takes the MPP offer when a seller makes one and falls back to L402 otherwise, though the pi402.tech site notes session-style MPP isn’t usable yet because the swap-backed wallet can’t mint a return invoice.

L402 MPP (Payment HTTP Authentication)
Credential Macaroon + preimage Payload carrying the preimage
Intent supported Pay once, reuse until refused charge (per challenge) or session (running balance)
Origin Lightning Labs, since 2020 IETF draft co-authored by Stripe and Tempo

Metering by the token, not the request

A chat completion can cost a seller a few dozen tokens or a few thousand, and the seller only learns which after serving it. pi402’s companion tool, Lightmeter, converts a model’s published dollar-per-million-token rate into millisatoshis per token and runs four checks around every call: quote the bundle price before the 402 is minted, book the bundle against the credential, authorize each request against the remaining balance, then debit the usage the upstream actually reported once the response finishes. At roughly 1 msat per input token and 2 msat per output token, Lightning Labs’ post works out to about $0.80 and $1.61 per million tokens at current exchange rates — in the range of what metered API billing already charges, but settled per call instead of billed on a cycle.

A wallet inside the harness, on both sides

The part that removes the usual Lightning tax — running a node, managing channels, sourcing inbound liquidity — is Wavelength, Lightning Labs’ hosted wallet service, embedded directly into Pi via a WASM extension. A new /fund command inside Pi prints an invoice that lands in the agent’s wallet within seconds; /deposit returns an on-chain address for slower transfers that get swept in automatically. On the seller side, Aperture mints its challenge invoices from a Wavelength wallet instead of an in-house lnd node, with the swap server crediting Aperture’s seller-side wallet with inbound liquidity directly, so standing up a paid API doesn’t require running Lightning infrastructure either.

Architecture diagram showing a Pi coding agent with an embedded Wavelength wallet connecting through Aperture, which queries Lightmeter for pricing and metering, while a Wavelength swap server supplies inbound liquidity directly to Aperture on the seller side.Architecture diagram showing a Pi coding agent with an embedded Wavelength wallet connecting through Aperture, which queries Lightmeter for pricing and metering, while a Wavelength swap server supplies inbound liquidity directly to Aperture on the seller side.
The pi402 stack: Aperture fronts any OpenAI-compatible model and queries Lightmeter for pricing and metering, while a Wavelength swap server supplies Aperture's seller-side inbound liquidity so neither buyer nor seller runs Lightning channels.

Operators who want to try it can be a buyer with:

pi install npm:@lightninglabs/pi-402
export PI402_MAX_SAT_PER_REQUEST=5000
export PI402_DAILY_CAP_SAT=12000
# inside Pi:
/fund 20000

Selling means putting Aperture and a price server in front of any OpenAI-compatible endpoint, which — per the project’s own framing — requires no change to the model API being sold.

What’s untested

pi402 is a day-one open-source release with no hosted endpoint and, as of this writing, no independent benchmarking of its claims about fraud costs or pricing parity with metered APIs — those numbers come from Lightning Labs itself. The MPP session mode that would let an agent run a standing balance against a seller isn’t functional yet. And the broader pattern it’s testing — a payment rail where the credential and the receipt are the same object — is one more operators of agent fleets will want to watch rather than one with years of production mileage behind this particular integration. For teams already thinking about how agents pay for mid-task services or comparing token-based billing against credit-based plans, pi402 is a concrete, inspectable alternative to add to that comparison, not yet a replacement for the meters most fleets already run — see also how operators are tracking multiple billing meters per job.

Sources

  1. Announcing pi402: Your Agent Can Now Pay for Inference with Bitcoin | Lightning Labs
  2. pi402
  3. L402 | Builder's Guide
  4. GitHub - lightninglabs/L402: Pay for APIs with Lightning. Authenticate with the receipt. HTTP 402, realized. · GitHub
  5. L402 — Pay for APIs with Lightning. Authenticate with the receipt.