Bitcoin Lightning + L402: Micropayments for AI Services

Published 2026-04-09 — by MAXIA

L402 is a protocol that turns HTTP 402 "Payment Required" into a real payment rail. Built by Lightning Labs on top of Bitcoin's Lightning Network, it lets an AI agent pay for a single API call in sats (satoshis, 1/100,000,000 of a Bitcoin) without opening an account, providing a credit card, or filling out a form. This guide explains how it works and how MAXIA uses it.

The problem L402 solves

An AI agent wants to call an API. The API costs $0.001 per call. There is no way to charge $0.001 via Stripe — the minimum transaction fee alone is higher than the charge. Subscription models do not work either because the agent might only need one call. This is the classic "internet micropayments" problem that was unsolvable until Lightning made it cheap to send $0.001 in sats.

How L402 works (3 steps)

  1. Agent requests the API — plain HTTP GET, no auth header.
  2. Server replies 402 Payment Required — the response includes an L402 header with a Lightning invoice (BOLT11) and an unpaid macaroon (authentication token).
  3. Agent pays the invoice via Lightning (1-3 seconds), gets back a preimage, adds the preimage to the macaroon, and retries the request with Authorization: L402 macaroon:preimage. The server validates and returns the data.

Total round trip: under 5 seconds including the Lightning payment. Fee to the Lightning network: usually less than 1 sat.

Example request/response

# Step 1: unauth GET
GET /api/expensive-service HTTP/1.1

# Step 2: server responds 402
HTTP/1.1 402 Payment Required
WWW-Authenticate: L402 macaroon="AGIAJEem...", invoice="lnbc100n1p..."

# Step 3: agent pays invoice, then retries
GET /api/expensive-service HTTP/1.1
Authorization: L402 AGIAJEem...:0203abc...

HTTP/1.1 200 OK
{ "data": "..." }

Why this is revolutionary for AI agents

How MAXIA supports L402

MAXIA integrates with ln.bot, a hosted Lightning service that exposes L402 without requiring you to run a Lightning node. The MAXIA client library handles the L402 dance transparently:

from maxia import Maxia
m = Maxia()
# Enable Lightning micropayments (requires ln.bot funded wallet)
m.enable_lightning()

# This call will trigger L402, pay the invoice, and return the result
sentiment = m.call_service("sentiment_analyzer", text="BTC to the moon")

Behind the scenes, MAXIA's client sends the initial request, catches the 402, pays the invoice via ln.bot, attaches the macaroon + preimage, and retries. The agent author never sees any of this.

Alternatives to L402

L402 is the right choice when you want zero-friction pay-per-call, no accounts, and Bitcoin-native.

Try L402 micropaymentsSee the Lightning integration docs.