Skip to main content

l402-kit???

l402-kit ??????????3??????API?Bitcoin Lightning??????????????????????????????? ???????????????????????????????????sats???
npm install l402-kit   # TypeScript / Express
pip install l402kit    # Python / FastAPI / Flask
go get github.com/shinydapps/l402-kit/go@v1.10.0  # Go / net/http
cargo add l402kit       # Rust / axum

??????

  • Stripe: 1???????$0.30 � ??????????????
  • ?????????: ????????????????????
  • AI??????: ??????????? � API??????????
l402-kit ???????:Lightning Network???pay-per-call?1??????????????????

??????

  • API??? � ????????????????????????
  • AI?????????? � ???????????API????
  • Stripe?????? � Bitcoin??????
  • ????????? � 1??????1 sat

???????? � TypeScript

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

const app = express();

app.get("/premium", l402({
  priceSats: 100,                           // 1??$0.06
  lightning: new AlbyProvider(process.env.ALBY_TOKEN!, process.env.ALBY_HUB_URL!),    // ??????? � 0% ???
}), (_req, res) => {
  res.json({ data: "????????????" });
});

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": "????????????"}

??????

curl http://localhost:3000/premium
# ? {"error":"Payment Required","priceSats":100,"invoice":"lnbc..."}

??????

5????????API?