L402 Kit

io.github.ThiagoDataEngineerPublished by GitHub account ThiagoDataEngineerv1.8.7Updated Oct 24, 2026

MCP server for L402-protected APIs via Bitcoin Lightning. Pay-per-call AI tools in sats.

VerifiedSTDIODesktop onlyFinanceDeveloper ToolsAI & ML

Overview

AI-generated overview

Lets an assistant call L402-protected APIs and pay per request automatically over the Bitcoin Lightning Network.

What you can do
L402 Kit is a payment layer for APIs that return HTTP 402 with a BOLT11 Lightning invoice and a macaroon. An agent client can detect the 402, pay the invoice from a configured Lightning wallet, and retry the request with an L402 authorization header. It also ships server-side middleware for TypeScript, Python, Go and Rust so developers can charge for their own endpoints, plus a VS Code extension for monitoring payments.
When to use it
Worth adding when an assistant needs to consume paid APIs that use the L402 or x402 pay-per-call model and you want the payment step handled without a human approving each request. It is aimed at autonomous agent workflows and at developers monetizing their own APIs.
Requirements
Runs locally over stdio, typically launched with npx l402-kit-mcp. Needs Node.js and a Lightning wallet credential supplied through the environment, such as BLINK_API_KEY (with BLINK_WALLET_ID), ALBY_TOKEN, OPENNODE_KEY or LNBITS_KEY, depending on the provider. A Lightning address or self-hosted node is needed to receive payments. Network access to the Lightning provider and the paid API is required.
Before you install
The server spends real Bitcoin over the Lightning Network; payments are final and cannot be reversed. Wallet credentials such as BLINK_API_KEY, ALBY_TOKEN, OPENNODE_KEY and LNBITS_KEY are secrets that should be scoped and stored carefully. Set a per-session budget (the README suggests budgetSats) so an agent cannot overspend. In managed mode a 0.3% fee goes to the provider, and payment details are shared with the Lightning provider and the paid API.

Installation

In SourceWeft

  1. Open L402 Kit in the dashboard and add it to a workspace.
  2. Enable the server for the chats that should use its tools.

Desktop only via STDIO. STDIO servers start a local process, so they need the SourceWeft desktop host.

Other MCP clients

Follow the launch instructions in the repository.

README


🌍 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

bash
npm install l402-kit        # TypeScript / Node.js / Expresspip install l402kit         # Python / FastAPI / Flaskgo get github.com/shinydapps/l402-kit/[email protected]   # Go / net/http / Chi / Gincargo add l402kit           # Rust / axum

AI Agents / LLMs: See llms.txt for 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-kitto pay automatically with Bitcoin Lightning.Budget limit: {BUDGET_SATS} sats per session. Never exceed this limit.

Agent SDK quickstart:

typescript
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):

json
{  "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

[Powered by L402-Kit]


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

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

python
from fastapi import FastAPI, Requestfrom l402kit import l402_required
app = FastAPI()
@app.get("/premium")@l402_required(price_sats=100, owner_lightning_address="[email protected]")async def premium(request: Request):    return {"data": "Payment confirmed."}

Go

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: "[email protected]",    }, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {        fmt.Fprintln(w, `{"data": "Payment confirmed."}`)    })))    http.ListenAndServe(":8080", nil)}

Rust

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("[email protected]"));
    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

bash
# Step 1 — triggers 402 + returns invoicecurl 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." }

▶ Try the interactive demo


Why not Stripe?

Stripel402-kit
Minimum fee$0.30< 1 sat (~$0.001)
Settlement time2–7 days< 1 second
ChargebacksYesImpossible — cryptographic proof
Requires accountYesNo — any Lightning wallet
AI agent supportNoYes — 4 SDKs, native
Countries blocked~500 — global by default
ReversibleYesNo — final on receipt
Open sourceNoYes — MIT

Providers

typescript
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:

typescript
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 payerAPI verification:  SHA256(preimage) == paymentHash  ✓Replay protection: each preimage is marked used — works exactly onceToken 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.

[VS Code Marketplace]

  • ⚡ 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: [email protected]

Other wallets: Wallet of Satoshi · Phoenix · Zeus · Alby


Links


MIT — use freely, build freely.

Bitcoin has no borders.


Built with ⚡ by ShinyDapps


Docs · Demo · VS Code · npm

Source: README.md at commit a9a2161

Tools

0
SourceWeft has not started this package in its sandbox yet, so its tools are not known.

Version history

1
  1. v1.8.7LatestSep 16, 2026

Score

50% of the applicable checks met

How complete this listing is, computed from the registry entry, the endpoint and public sources. Not a rating of the server and not a statement that it is safe or working today: reachability is a dated check, and no installs or reviews go into the score.

  • Reached in the last 30 days25 pts

    Keep the endpoint answering the MCP handshake; SourceWeft probes it every 30 days.

  • Auth declared10 pts

    Declare the credential headers in the registry entry, or keep the endpoint answering the probe so its auth can be classified.

  • Tools listed15 pts

    Answer tools/list without a credential, or ship a package that starts in a sandbox without one.

  • DescriptionRequired15 pts
  • Logo10 pts
  • Documentation15 pts
  • License10 pts