L402 Kit

io.github.ThiagoDataEngineer由 GitHub 帳號 ThiagoDataEngineer 發布v1.8.7更新於 Oct 24, 2026

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

概覽

AI 產生的概覽

讓助理呼叫受 L402 保護的 API,並透過比特幣閃電網路按次自動付款。

可以做什麼
L402 Kit 是 API 的付款層:API 會回傳 HTTP 402,以及 BOLT11 閃電發票和 macaroon。代理用戶端可以辨識 402、用設定好的閃電錢包支付發票,再帶上 L402 授權標頭重試請求。它也提供 TypeScript、Python、Go 與 Rust 的伺服器端中介軟體,方便開發者對自己的端點收費,並附帶一個用來監控付款的 VS Code 擴充套件。
適用情境
當助理需要取用採用 L402 或 x402 按次付費模式的付費 API,而你希望付款步驟不必每次由人工核准時,適合安裝。它鎖定自主代理工作流程,也鎖定想把自己 API 變現的開發者。
執行需求
以 stdio 在本機執行,通常透過 npx l402-kit-mcp 啟動。需要 Node.js,以及透過環境變數提供的閃電錢包憑證,例如 BLINK_API_KEY(搭配 BLINK_WALLET_ID)、ALBY_TOKEN、OPENNODE_KEY 或 LNBITS_KEY,視所選服務商而定。收款需要閃電地址或自架節點。需要能連線到閃電服務商與付費 API 的網路。
安裝前請注意
此伺服器會透過閃電網路花用真實比特幣,付款一旦完成即定案、無法撤回。BLINK_API_KEY、ALBY_TOKEN、OPENNODE_KEY、LNBITS_KEY 等錢包憑證屬於機密,應謹慎限定權限並妥善保存。建議設定單次工作階段預算(README 中為 budgetSats),以免代理超支。託管模式下會向服務商支付 0.3% 手續費,付款資訊會與閃電服務商及付費 API 共享。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 L402 Kit,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

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

來源:README.md,提交 a9a2161

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.8.7最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分