ShinyDapps/l402-kit
๐ โ๏ธ ๐ ๐ช ๐ง - Full-stack L402 SDK: server middleware (Express/FastAPI/axum/net/http) + agent client with auto-pay. 4 languages (TypeScript, Python, Go, Rust). MCP server, LangChain integration, budget control. npx l402-kit-mcp
Quick Install
{
"mcpServers": {
"shinydapps-l402-kit": {
"command": "npx",
"args": [
"-y",
"shinydapps-l402-kit"
]
}
}
}Using an AI coding agent (Claude Code, Cursor, etc.)? Copy a ready-made prompt that tells it to fetch the setup instructions and install this server for you.
Documentation Overview
l402-kit
Add Bitcoin Lightning pay-per-call to any API. 3 lines of code.
โถ Watch end-to-end demo โ install โ 402 โ pay โ 200 OK
Live traction
| SDK | Version | Downloads |
|---|---|---|
| ๐ฆ TypeScript ยท npmjs.com/package/l402-kit | ||
| ๐ Python ยท pypi.org/project/l402kit | ||
| ๐ฆ Rust ยท crates.io/crates/l402kit | ||
| ๐ VS Code Extension ยท marketplace | ||
| ๐ฆซ Go ยท pkg.go.dev |
๐ Available in 11 languages โ click to expand
๐บ๐ธ Charge for your API in Bitcoin Lightning. 3 lines of code. ๐ง๐ท Monetize sua API com Bitcoin Lightning. 3 linhas de cรณdigo. ๐ช๐ธ Monetiza tu API con Bitcoin Lightning. 3 lรญneas de cรณdigo. ๐จ๐ณ ็จ 3 ่กไปฃ็ ๏ผ้่ฟๆฏ็นๅธ้ช็ต็ฝ็ปๆถ่ดนใ ๐ฎ๐ณ เค เคชเคจเฅ API เคเฅ Bitcoin Lightning เคธเฅ 3 เคฒเคพเคเคจเฅเค เคฎเฅเค เคฎเฅเคจเฅเคเคพเคเคเคผ เคเคฐเฅเคเฅค ๐ธ๐ฆ ุงูุณุจ ู ู API ุงูุฎุงุต ุจู ุนุจุฑ Bitcoin Lightning. 3 ุฃุณุทุฑ ููุท. ๐ซ๐ท Monรฉtisez votre API en Bitcoin Lightning. 3 lignes de code. ๐ฉ๐ช Monetarisiere deine API mit Bitcoin Lightning. 3 Zeilen Code. ๐ท๐บ ะะพะฝะตัะธะทะธััะน ัะฒะพะน API ัะตัะตะท Bitcoin Lightning. 3 ัััะพะบะธ ะบะพะดะฐ. ๐ฏ๐ต Bitcoin LightningใงAPIใ3่กใงๅ็ๅใ ๐ฎ๐น Monetizza la tua API con Bitcoin Lightning. 3 righe di codice.
๐ Official docs: ๐บ๐ธ ยท ๐ง๐ท ยท ๐ช๐ธ ยท ๐จ๐ณ ยท ๐ฎ๐ณ ยท ๐ธ๐ฆ ยท ๐ซ๐ท ยท ๐ฉ๐ช ยท ๐ท๐บ ยท ๐ฏ๐ต ยท ๐ฎ๐น
Install
npm install l402-kit # TypeScript / Node.js / Express
pip install l402kit # Python / FastAPI / Flask
go get github.com/shinydapps/l402-kit/go@v1.10.0 # Go / net/http / Chi / Gin
cargo add l402kit # Rust / axum
AI Agents / LLMs: See
llms.txtfor machine-readable instructions. Agent discovery:/.well-known/agent.jsonยท/.well-known/l402.json
For AI Agents
l402-kit is the payment layer for autonomous agents. Agents can pay for APIs without human intervention.
System prompt snippet โ add this to any agent to enable L402 payments:
You have access to paid APIs via the L402 protocol.
When you call an API that returns HTTP 402, use the L402Client from l402-kit
to pay automatically with Bitcoin Lightning.
Budget limit: {BUDGET_SATS} sats per session. Never exceed this limit.
Agent SDK quickstart:
import { l402Client, buildWallet } from "l402-kit/agent";
const client = l402Client({
wallet: buildWallet(process.env), // auto-detects BLINK_API_KEY or ALBY_TOKEN
budgetSats: 1000,
});
const data = await client.fetch("https://api.example.com/paid-endpoint");
MCP Server (for Claude Desktop, Cursor, and any MCP-compatible agent):
{
"mcpServers": {
"l402-kit": {
"command": "npx",
"args": ["l402-kit-mcp"],
"env": { "BLINK_API_KEY": "your-key" }
}
}
}
Compatible with: LangChain ยท OpenAI Agents ยท CrewAI ยท Vercel AI SDK ยท AutoGPT ยท Any MCP client
Protocol support: L402 (Bitcoin Lightning) ยท x402 (USDC/Coinbase) compatible
How it works
1. Client calls your API
โ
2. API returns HTTP 402 + BOLT11 invoice + macaroon
โ
3. Client pays (any Lightning wallet, < 1 second, any country)
โ
4. Client sends Authorization: L402 <macaroon>:<preimage>
โ
5. API verifies SHA256(preimage) == paymentHash โ
โ
6. HTTP 200 OK + your data
โโ Fee flow (managed mode) โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Payment โ 99.7% โ your Lightning Address (instant)
โ 0.3% โ ShinyDapps
Quickstart
TypeScript
import express from "express";
import { l402, AlbyProvider } from "l402-kit";
const app = express();
const lightning = new AlbyProvider(process.env.ALBY_TOKEN!);
app.get("/premium", l402({ priceSats: 100, lightning }), (_req, res) => {
res.json({ data: "Payment confirmed." });
});
app.listen(3000);
Python
from fastapi import FastAPI, Request
from l402kit import l402_required
app = FastAPI()
@app.get("/premium")
@l402_required(price_sats=100, owner_lightning_address="you@yourdomain.com")
async def premium(request: Request):
return {"data": "Payment confirmed."}
Go
package main
import (
"fmt"
"net/http"
l402kit "github.com/shinydapps/l402-kit/go"
)
func main() {
http.Handle("/premium", l402kit.Middleware(l402kit.Options{
PriceSats: 100,
OwnerLightningAddress: "you@yourdomain.com",
}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"data": "Payment confirmed."}`)
})))
http.ListenAndServe(":8080", nil)
}
Rust
use axum::{middleware, routing::get, Router};
use l402kit::{l402_middleware, Options};
use std::sync::Arc;
#[tokio::main]
async fn main() {
let opts = Arc::new(Options::new(100).with_address("you@yourdomain.com"));
let app = Router::new()
.route("/premium", get(|| async { "Payment confirmed." }))
.route_layer(middleware::from_fn_with_state(opts, l402_middleware));
let listener = tokio::net::TcpListener::bind("0.0.0.0:8080").await.unwrap();
axum::serve(listener, app).await.unwrap();
}
Test it live
# Step 1 โ triggers 402 + returns invoice
curl http://localhost:3000/premium
# โ { "error": "Payment Required", "invoice": "lnbc1u...", "macaroon": "eyJ..." }
# Step 2 โ pay the invoice with any Lightning wallet, then:
curl http://localhost:3000/premium \
-H "Authorization: L402 <macaroon>:<preimage>"
# โ { "data": "Payment confirmed." }
Why not Stripe?
| Stripe | l402-kit | |
|---|---|---|
| Minimum fee | $0.30 | < 1 sat (~$0.001) |
| Settlement time | 2โ7 days | < 1 second |
| Chargebacks | Yes | Impossible โ cryptographic proof |
| Requires account | Yes | No โ any Lightning wallet |
| AI agent support | No | Yes โ 4 SDKs, native |
| Countries blocked | ~50 | 0 โ global by default |
| Reversible | Yes | No โ final on receipt |
| Open source | No | Yes โ MIT |
Providers
import { BlinkProvider, OpenNodeProvider, LNbitsProvider } from "l402-kit";
// Blink (recommended โ free, instant setup)
const provider = new BlinkProvider(process.env.BLINK_API_KEY!, process.env.BLINK_WALLET_ID!);
// OpenNode (production, custodial)
const provider = new OpenNodeProvider(process.env.OPENNODE_KEY!);
// LNbits (self-hosted)
const provider = new LNbitsProvider(process.env.LNBITS_KEY!, "https://your.lnbits.host");
Bring your own node โ implement the LightningProvider interface in 5 lines:
import type { LightningProvider } from "l402-kit";
class MyNode implements LightningProvider {
async createInvoice(amountSats: number) { /* return Invoice */ }
async checkPayment(paymentHash: string) { /* return boolean */ }
}
Security model
Invoice creation: paymentHash = SHA256(preimage)
Client payment: Lightning Network releases preimage to payer
API verification: SHA256(preimage) == paymentHash โ
Replay protection: each preimage is marked used โ works exactly once
Token expiry: macaroons expire after 1 hour
- Unforgeable โ SHA256 is a one-way function; you cannot fake a preimage
- No chargebacks โ cryptographic settlement, not reversible card auth
- Replay-safe โ MemoryReplayAdapter (dev) or RedisReplayAdapter (production, multi-instance)
- 600+ automated tests across 5 runtimes (TS, Python, Go, Rust, Cloudflare Workers) โ production-grade reliability for autonomous agent workflows
- Fully auditable โ MIT, every line open source
VS Code Extension
Monitor every sat in real-time without leaving your editor.
- โก Live payment feed per endpoint
- ๐ Bar chart โ 1D / 7D (free) ยท 30D / 1Y / ALL (Pro)
- ๐ 11 languages built-in
- ๐จ Light / dark / auto theme
- ๐ง Zero config โ just set your Lightning Address
Get a Lightning Address (free)
Sign up at dashboard.blink.sv โ free, no credit card, instant.
Your address: yourname@yourdomain.com
Other wallets: Wallet of Satoshi ยท Phoenix ยท Zeus ยท Alby
Links
| Resource | URL |
|---|---|
| ๐ Docs (11 languages) | l402kit.com/docs |
| ๐ฆ npm | npmjs.com/package/l402-kit |
| ๐ PyPI | pypi.org/project/l402kit |
| ๐ฆซ Go | pkg.go.dev/github.com/shinydapps/l402-kit/go |
| ๐ฆ Rust | crates.io/crates/l402kit |
| ๐ VS Code | marketplace.visualstudio.com |
| โก Lightning | shinydapps@blink.sv |
| ๐ GitHub | github.com/ShinyDapps/l402-kit |