l402-kit White Paper
Version 1.0 โ April 2026Abstract
l402-kit is an open-source middleware library that enables any HTTP API to accept Bitcoin Lightning micropayments using the L402 protocol. Developers add a paywall to any endpoint in 3 lines of code, across TypeScript, Python, Go, and Rust. Payments settle in under one second, fees are 0.3% with no monthly subscription, and no bank account or account creation is required from the end user.1. Problem
The current API monetization stack is broken for small-value, high-frequency access patterns:- Credit cards: Minimum viable transaction is ~0.001 per API call is economically impossible.
- Account walls: Creating an account reduces conversion by 60โ80%. AI agents cannot create accounts.
- Monthly subscriptions: Wrong pricing model for pay-per-use APIs. Developers pay for capacity they donโt use.
- Geographic exclusion: 1.4 billion adults are unbanked. Bitcoin has no geography.
2. Solution: L402 + Bitcoin Lightning
The L402 protocol (HTTP 402 Payment Required) enables a native payment handshake at the HTTP layer:- Client calls an endpoint without payment proof
- Server returns
402 Payment Requiredwith a BOLT11 Lightning invoice - Client pays the invoice (~300ms, any wallet)
- Client re-calls with
Authorization: L402 <token>:<preimage> - Server verifies
SHA256(preimage) == paymentHashcryptographically - Server returns
200 OK
3. Architecture
4. Economic Model
| Tier | Cost | What you get |
|---|---|---|
| Free | 0.3% of payments received | Unlimited calls, 7-day history, 1D/7D charts, all SDKs |
| Pro | Full history, 30D/1Y/ALL charts, CSV export, priority support | |
| Founder | Lifetime Pro, founder badge, direct access |
- **3/month fee
- **30/month fee
- **300/month fee
5. SDKs
l402-kit ships native libraries for all major backend runtimes:| Language | Package | Install |
|---|---|---|
| TypeScript / Node.js | l402-kit on npm | npm install l402-kit |
| Python | l402kit on PyPI | pip install l402kit |
| Go | github.com/shinydapps/l402-kit/go | go get ...@v1.0.1 |
| Rust | l402kit on crates.io | cargo add l402kit |
priceSats and lightningAddress, returns a standard middleware compatible with Express, FastAPI, net/http, and axum.
6. AI Agents & LLMs
l402-kit is natively compatible with the emerging AI agent economy. LLMs and autonomous agents can:- Call L402-gated APIs without human intervention
- Pay for exactly the data or compute they need
- Use any Lightning wallet or custodial account
- Operate across borders with zero friction
llms.txt file at the repository root provides machine-readable integration instructions for AI systems.
7. Security
- Replay prevention:
preimagehas aUNIQUEconstraint in Supabase โ each proof can only be used once. - Cryptographic verification:
SHA256(preimage) == paymentHashis verified in the middleware without any external call. - Webhook integrity: Blink callbacks are verified via
HMAC-SHA256before any database write. - RLS hardening: The Supabase anon key has zero access to
pro_access(Lightning addresses are PII). Payments are filtered byowner_address. - No private keys in code: All secrets are environment variables; the BOLT11 preimage never leaves the verification layer.
8. Decentralization Roadmap
The current managed backend (ShinyDapps-hosted) is a pragmatic starting point. The roadmap toward full decentralization:- v1.0 โ Managed mode: developer provides only a Lightning address, ShinyDapps handles invoice creation and settlement (current)
- v1.5 โ Self-hosted mode: developers point the SDK at their own LNbits or OpenNode instance
- v2.0 โ Direct Lightning: SDK creates invoices and verifies payments directly against LND/CLN via gRPC, no intermediary
- v3.0 โ Multi-provider routing: payment routing optimized for fees and reliability across multiple Lightning nodes
9. Open Source
l402-kit is MIT-licensed. Packages on npm, PyPI, pkg.go.dev, and crates.io. Contributions welcome. Issues and pull requests are reviewed within 48 hours.ShinyDapps ยท l402kit.vercel.app ยท thiagoyoshiaki@gmail.com