Skip to main content

What is l402-kit?

l402-kit is an open-source middleware that implements the L402 protocol — the open standard for pay-per-call API monetization using the Bitcoin Lightning Network. Add 3 lines of code. Callers pay in sats. You receive in seconds. Works with TypeScript, Python, Go, and Rust.
npm install l402-kit    # TypeScript / Express
pip install l402kit     # Python / FastAPI / Flask
cargo add l402kit       # Rust / axum
# Go — see SDK / Go for setup
go get github.com/shinydapps/l402-kit/go@v1.0.1

▶ Watch end-to-end demo

See the full L402 flow in action — from npm install to first paid API call. Interactive terminal animation, 45 seconds.

npm

l402-kit on npm

PyPI

l402kit on PyPI

Go

Go SDK (net/http)

Rust

Rust SDK (axum)

llms.txt

For AI agents

Whitepaper

Technical design

Como funciona — fluxo completo

┌─────────────────────────────────────────────────────────────────┐
│                                                                 │
│  Cliente / Agente IA                                            │
│         │                                                       │
│         │ 1. GET /sua-api                                       │
│         ▼                                                       │
│  Sua API (l402-kit)  ──── 2. Cria invoice ───► ShinyDapps API  │
│         │                                       (Blink wallet)  │
│         │ 3. Retorna: 402 + invoice BOLT11                      │
│         ▼                                                       │
│  Cliente paga ──────────────────────────────► Lightning Network │
│         │                    (< 1 segundo)                      │
│         │ 4. Envia preimage como prova criptográfica            │
│         ▼                                                       │
│  Sua API verifica: SHA256(preimage) == hash ✓                   │
│         │                                                       │
│         │ 5. Split automático:                                  │
│         │    → 99.7% ──────────────────────► Seu Lightning Addr │
│         │    → 0.3%  ──────────────────────► ShinyDapps (taxa)  │
│         │                                                       │
│         │ 6. Sua API responde: 200 OK + dados                   │
│         ▼                                                       │
│  Cliente recebe o conteúdo                                      │
└─────────────────────────────────────────────────────────────────┘
Transparência total: ShinyDapps recebe o pagamento e envia 99.7% para seu Lightning Address automaticamente. A taxa de 0.3% é o que mantém o projeto vivo. O split é determinístico e verificável — nenhum segredo, nenhum intermediário.

Quickstart in 2 minutes

TypeScript

import express from "express";
import { l402 } from "l402-kit";

const app = express();

app.get("/premium", l402({
  priceSats: 100,
  ownerLightningAddress: "you@blink.sv", // receives 99.7% of every payment
}), (_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@blink.sv",
)
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@blink.sv",
    }, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintln(w, `{"data":"Payment confirmed."}`)
    })))
    http.ListenAndServe(":8080", nil)
}

Rust (axum)

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@blink.sv"));

    let app = Router::new()
        .route("/premium", get(|| async { r#"{"data":"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();
}

Why not Stripe?

Stripel402-kit
Minimum fee$0.30< 1 sat (~$0.001)
Settlement2–7 days< 1 second
ChargebacksYesImpossible
Requires accountYesNo
AI agent supportNoYes — native
Countries blocked~500 — global
Open sourceNoYes — MIT
CensurableYesNo

Security

Every payment is verified mathematically:
SHA256(preimage) == paymentHash
  • Impossible to fake without actually paying
  • Each preimage works exactly once (anti-replay)
  • Tokens expire after 1 hour
  • All logic is deterministic and verifiable — no hidden fees, no intermediaries

Who is it for?

API developers

Charge per call instead of monthly subscriptions. Start in 1 line.

AI agent builders

Agents pay APIs autonomously — no credit card, no human in the loop.

Devs outside the financial system

Argentina, Nigeria, Iran — Bitcoin has no borders or gatekeepers.

Data providers

Charge 1 sat per query. Impossible with Stripe.

Created by

ShinyDapps · github.com/ShinyDapps Lightning: shinydapps@blink.sv