Every API you use today requires a human at some point in the payment flow. Someone signs up for a Stripe account. Someone enters a credit card. Someone approves a subscription renewal. The entire API economy is built on the assumption that a person will eventually show up to handle the money.
AI agents break that assumption. An agent making 1,500 API calls per prompt doesn't have a credit card. A sub-agent spawned at 3 AM to translate a document can't wait for human approval. An autonomous research pipeline that discovers a new data source mid-task can't pause to sign up for a developer account.
The L402 protocol solves this by making API payments machine-native. It combines HTTP's long-dormant 402 Payment Required status code with Lightning Network micropayments and macaroon proof-of-payment tokens to create a payment flow that requires zero human involvement — from discovery through payment through access.
This post explains exactly how the L402 protocol works, why it matters for the agent economy, and how to implement it today.
What Is the L402 Protocol?
L402 is a protocol that enables machine-to-machine API payments using three components that already exist:
1. HTTP 402 Payment Required — The status code the HTTP spec reserved in 1997 for “future use.” L402 puts it to work as a standard signal that says: “This resource costs money. Here's how to pay.”
2. Lightning Network invoices — Bitcoin's Layer 2 payment network enables instant, sub-cent micropayments that settle in milliseconds. No credit cards, no bank accounts, no minimum transaction sizes.
3. Macaroon tokens — Capability-based bearer tokens that carry cryptographically enforced constraints (budgets, expiration, scopes). Once you pay a Lightning invoice, you receive a macaroon that proves payment and grants access.
Together, these three components create a payment flow where an API can say “pay me 50 satoshis to access this endpoint,” an agent can pay instantly, and the proof-of-payment doubles as the access credential. No signup. No API keys. No human approval.
How L402 Works: Step by Step
The L402 protocol flow is elegant in its simplicity. Here's what happens when an AI agent encounters an L402-protected API:
Step 1: Agent makes an API request
─────────────────────────────────
GET /api/v1/translate?text=hello&target=es
Host: api.example.com
Step 2: Server returns 402 with payment details
─────────────────────────────────────────────────
HTTP/1.1 402 Payment Required
WWW-Authenticate: L402 macaroon="<base64-macaroon>", invoice="<lightning-invoice>"
Content-Type: application/json
{
"message": "Payment required",
"amount": 50,
"unit": "satoshis",
"description": "Translation API - 1 request"
}
Step 3: Agent pays the Lightning invoice (~200ms)
─────────────────────────────────────────────────
Agent's Lightning wallet pays the invoice automatically.
Payment settles in milliseconds. Agent receives preimage
(cryptographic proof-of-payment).
Step 4: Agent retries with proof-of-payment
────────────────────────────────────────────
GET /api/v1/translate?text=hello&target=es
Host: api.example.com
Authorization: L402 <macaroon>:<preimage>
Step 5: Server validates and responds
──────────────────────────────────────
HTTP/1.1 200 OK
Content-Type: application/json
{
"translation": "hola",
"source": "en",
"target": "es"
}The entire flow — from initial request through payment through access — happens in under a second. No account creation. No OAuth flow. No API key provisioning. The payment is the authentication.
The Macaroon: More Than a Receipt
The macaroon returned in the WWW-Authenticate header isn't just a receipt — it's a capability token with embedded constraints called caveats. These caveats define exactly what the payment grants access to:
# Decoded macaroon caveats
token_id = "txn-a1b2c3d4"
scope = "/api/v1/translate"
expires = "2026-04-02T15:00:00Z"
budget_id = "budget-xyz-789"
# The macaroon is cryptographically bound:
# - Can't remove caveats without invalidating the token
# - Can add MORE caveats to create restricted sub-tokens
# - Preimage proves the Lightning payment was madeThis is what makes L402 fundamentally different from simple pay-per-request schemes. The macaroon carries capabilities, not just payment proof. And because macaroons support attenuation, an agent can create more restricted tokens for sub-agents — enabling the kind of delegated authority that multi-agent systems require.
Why Existing Payment Models Fail for AI Agents
Before diving into comparisons, let's understand why existing API payment models weren't built for autonomous consumers:
Subscriptions Require Signup
Monthly subscriptions assume a human will fill out a form, enter billing details, and agree to terms. An AI agent that discovers a useful API at 2 AM can't complete a signup flow. Subscriptions also force commitment before usage — agents don't know if they'll need 10 requests or 10,000.
OAuth Requires Human Consent
OAuth flows are designed around a human clicking “Authorize” in a browser. They work beautifully for human-in-the-loop integrations. They fail completely for autonomous agents that need to access new services dynamically.
API Keys Lack Payment
API keys handle authentication but have no concept of payment. They're issued by a provider to a known customer. There's no mechanism for an unknown agent to obtain an API key, pay for access, and start consuming — all in a single automated flow.
Credit Card Processing Is Too Slow and Expensive
Credit card transactions have minimum fees (typically $0.30 + 2.9%), take days to settle, and require merchant accounts. When an agent needs to make a $0.001 API call, credit card infrastructure is three orders of magnitude too expensive and too slow.
L402 vs Traditional API Payment Models
Here's how L402 stacks up against the payment models APIs use today:
❌ Traditional: Subscription + API Key
• Requires human signup and credit card on file
• Monthly commitment regardless of actual usage
• No delegation — keys are tied to one account
• Overages billed after the fact (30-day invoice cycles)
• Minimum viable customer: a developer with a Stripe account
✅ L402: Pay-Per-Request with Instant Settlement
• Zero signup — payment is the authentication
• Pay only for what you use, per request
• Macaroon tokens support safe delegation to sub-agents
• Payment settles before the response is sent — no invoicing
• Minimum viable customer: any agent with a Lightning wallet
❌ Traditional: Usage-Based Billing (Stripe Metered)
• Records usage, bills monthly — risk of non-payment
• Minimum transaction costs make sub-cent pricing impossible
• Provider takes on credit risk for the billing period
• Agents can accumulate unbounded charges before cutoff
• Reconciliation happens days or weeks after consumption
✅ L402: Prepaid Micropayments
• Payment before access — zero credit risk for the provider
• Lightning enables sub-cent transactions (1 satoshi ≈ $0.001)
• No minimum transaction size — charge exactly what the call costs
• Real-time settlement — revenue hits your wallet instantly
• No billing infrastructure needed — the protocol is the billing
Real-World Use Cases
1. API Monetization Without Billing Infrastructure
You built a useful API. You want to charge for it. With traditional billing, you need Stripe integration, customer management, invoicing, dunning emails, and a pricing page. With L402, you add a gateway in front of your API that returns 402 Payment Required with a Lightning invoice. Your first paying customer can arrive in the time it takes to deploy the gateway.
2. Agent-to-Agent Commerce
In multi-agent systems, agents regularly need services from other agents: a research agent buys data from a scraping agent, a coding agent pays for test execution from a CI agent. L402 makes this frictionless — the calling agent discovers the service, pays the Lightning invoice, and gets access. No human negotiates the contract. No platform takes a 30% cut.
3. MCP Tool Access and Monetization
The Model Context Protocol (MCP) lets AI agents discover and use tools dynamically. L402 adds the missing economic layer — tool providers can charge per invocation, and agents can pay instantly. Note that in SatGate's architecture, MCP tool access uses enterprise budget enforcement via Redis and PostgreSQL for fiat-based billing, while L402 operates as a per-payment protocol on the HTTP gateway layer. The two complement each other: L402 for permissionless micropayments, enterprise budgets for organizational cost control.
Implementing L402 with SatGate
SatGate implements L402 as a policy mode in its HTTP gateway. When you configure a route with the l402 policy (also available as the charge or monetize aliases), every request to that route must include a valid L402 token. No token? The gateway returns 402 Payment Required with a Lightning invoice.
# satgate.yaml — L402 route configuration
routes:
- path: /api/v1/translate
target: http://localhost:8080
policy: l402 # Also accepts "charge" or "monetize"
price_sats: 50 # Cost per request in satoshis
description: "Translation API — per-request pricing"
- path: /api/v1/premium
target: http://localhost:8080
policy: l402
price_sats: 200
description: "Premium endpoint — higher quality, higher price"
# How it works in the gateway:
# 1. Request arrives at /api/v1/translate
# 2. Gateway checks for valid L402 token in Authorization header
# 3. No token → return 402 with Lightning invoice for 50 sats
# 4. Valid token → proxy request to target backend
# 5. L402 is per-payment: no budget tracking neededThe key difference between L402 and SatGate's other policy modes: L402 is per-payment with no budget enforcement. Each request is a discrete payment. The gateway validates the L402 token format — it doesn't track cumulative spend or enforce budget ceilings. That's by design: L402 is a micropayment protocol, not a cost management framework.
For use cases that need budget enforcement on top of payments — say, an enterprise that wants agents to pay per-call but also cap total department spend — SatGate offers the fiat402 policy, which combines payment requirements with Redis-backed budget tracking. Different tool for different requirements.
The Bigger Picture: L402 as Agent Economy Infrastructure
L402 isn't just a payment protocol. It's infrastructure for a new kind of economy where machines are the primary consumers of digital services.
Consider what happens when API payments become machine-native:
Discovery becomes economic. An agent searching for a translation service doesn't just evaluate quality and latency — it evaluates price. APIs compete on cost per request, and agents route to the cheapest provider that meets their quality threshold. Markets emerge for every API category.
Access becomes permissionless. Any agent with a Lightning wallet can use any L402-protected API. No partnerships. No sales calls. No enterprise agreements. The barrier to entry for both providers and consumers drops to near zero.
Monetization becomes instant. You deploy an API, set a price in satoshis, and agents start paying you immediately. Revenue doesn't wait for monthly billing cycles — it arrives with every request. A solo developer with a useful model can earn money from their first agent customer within minutes of deployment.
Delegation becomes safe. Because L402 uses macaroons, agents can create attenuated tokens for sub-agents — granting limited access that can never exceed the parent's authority. Multi-agent workflows can operate with proper economic boundaries at every level.
This is why HTTP 402 was worth waiting for. The original spec authors couldn't have predicted AI agents, but they correctly intuited that HTTP would eventually need a native way to say “this costs money.” L402 fulfills that vision with a protocol stack — Lightning for payment, macaroons for proof, HTTP 402 for signaling — that's purpose-built for machine-speed commerce.
Getting Started with L402
If you're building APIs that agents will consume, L402 is worth understanding now — even if you don't implement it today. The protocol is open, the tooling is maturing, and the demand from agent developers is growing.
For API providers: Start with one endpoint. Set a price. Deploy SatGate with the l402 policy and see what happens when agents can pay for your API without signing up.
For agent developers: Add Lightning wallet support to your agent and teach it to handle 402 Payment Required responses. Your agent gains access to every L402-protected API on the internet — no integration work per service.
For enterprises: L402 and budget enforcement aren't mutually exclusive. Use L402 for external API monetization and SatGate's enterprise budget policies for internal cost control. The gateway handles both.
Ready to Add L402 Payments to Your API?
SatGate implements L402 as a gateway policy — deploy in front of any API to enable machine-native micropayments with zero changes to your backend. Open source. Production ready.