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.10.0

? 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

Lightning Network — 30-second primer

New to Bitcoin Lightning? Here’s what you need to know:
  • Lightning Network is a fast payment layer on top of Bitcoin. Payments settle in under a second, anywhere in the world, for fractions of a cent.
  • A Lightning Address (like you@blink.sv) is your receive address — it looks like an email. You don’t need to run a node. Wallets like Blink, Alby, and Phoenix give you one for free in 2 minutes.
  • A sat (satoshi) is the smallest unit of Bitcoin — roughly 0.0006at0.0006 at 60k/BTC. A typical API call costs 1–100 sats.
  • Managed vs Soberano — “Managed” means l402kit.com hosts the Lightning node for you (0.3% fee, zero setup). “Soberano” (Spanish for sovereign) means you connect your own wallet (0% fee, ~5 min setup with Blink or Alby).

How it works � full flow

The diagram below shows managed mode (ManagedProvider), where l402kit.com hosts the Lightning node for you. In soberano mode (Blink, Alby, BTCPay, etc.) payments go directly to your wallet � 0% fee.
+-----------------------------------------------------------------+
�                                                                 �
�  Client / AI Agent                                              �
�         �                                                       �
�         � 1. GET /your-api                                      �
�         ?                                                       �
�  Your API (l402-kit)  --- 2. Creates invoice --? ShinyDapps API �
�         �                                        (Blink wallet) �
�         � 3. Returns: 402 + BOLT11 invoice                      �
�         ?                                                       �
�  Client pays -------------------------------? Lightning Network �
�         �                       (< 1 second)                    �
�         � 4. Sends preimage as cryptographic proof              �
�         ?                                                       �
�  Your API verifies: SHA256(preimage) == hash ?                  �
�         �                                                       �
�         � 5. Automatic split:                                   �
�         �    ? 99.7% -----------------------? Your Lightning Addr�
�         �    ? 0.3%  -----------------------? ShinyDapps (fee)  �
�         �                                                       �
�         � 6. Your API responds: 200 OK + data                   �
�         ?                                                       �
�  Client receives content                                        �
+-----------------------------------------------------------------+
Full transparency: ShinyDapps receives the payment and forwards 99.7% to your Lightning Address automatically. The 0.3% fee keeps the project alive. The split is deterministic and verifiable � no secrets. For zero-intermediary operation, use soberano mode (Blink, BTCPay, Alby).

Quickstart in 2 minutes

TypeScript

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

const app = express();

app.get("/premium", l402({
  priceSats: 100,
  lightning: ManagedProvider.fromAddress("you@blink.sv"), // managed mode � no node needed
}), (_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,
    lightning=ManagedProvider.from_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,
        Lightning: l402kit.NewManagedProvider("you@yourdomain.com"),
    }, 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, ManagedProvider};
use std::sync::Arc;

#[tokio::main]
async fn main() {
    let provider = ManagedProvider::new("you@yourdomain.com".into());
    let opts = Arc::new(Options::new(100, provider));

    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.301 sat (~$0.0006)
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
  • 600+ automated tests across 5 runtimes � production-grade reliability for autonomous agent workflows

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

ShinyDappsgithub.com/ShinyDapps Lightning: shinydapps@blink.sv