L402sdk gives AI agents the ability to autonomously pay for L402-gated APIs using the Lightning Network. Built in Rust with TypeScript and Python bindings.
# Rust
cargo add l402-core l402-lnd
# TypeScript (Vercel AI SDK)
yarn add @lightninglabs/l402-ai
# TypeScript (WASM bindings only)
yarn add @lightninglabs/l402
# Python
pip install l402
# Python (LangChain tools)
pip install l402-langchainimport { createL402Tools, WasmL402Client, WasmBudgetConfig } from '@lightninglabs/l402-ai';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const client = WasmL402Client.withLndRest(
'https://localhost:8080',
process.env.LND_MACAROON!,
new WasmBudgetConfig(1000, 0, 50_000, 0),
100,
);
const tools = createL402Tools({ client });
const result = await generateText({
model: openai('gpt-4o'),
tools,
maxSteps: 5,
prompt: 'Fetch the premium data from https://api.example.com/v1/data',
});See the l402-ai-sdk README for full TypeScript documentation and the L402 Explorer for an interactive demo.
| Package | Description |
|---|---|
l402-core |
L402 client engine, budget tracker, token cache, receipts |
l402-proto |
Protocol types and port traits (LnBackend, TokenStore) |
l402-lnd |
LND backend (gRPC + REST) |
l402-cln |
Core Lightning backend (gRPC + REST) |
l402-nwc |
Nostr Wallet Connect (NIP-47) backend |
l402-swissknife |
Numeraire SwissKnife backend |
l402-mock |
Mock L402 server for testing |
l402-sqlite |
SQLite persistent token store |
@lightninglabs/l402 |
WebAssembly bindings (npm) |
@lightninglabs/l402-ai |
Vercel AI SDK tools (npm) |
l402-ffi |
C FFI layer for Go/Swift/Kotlin |
l402-python |
Python bindings (PyO3) |
l402-go |
Go bindings (CGo) |
l402-langchain |
LangChain Python tools |
- LND — gRPC and REST
- Core Lightning (CLN) — gRPC and REST
- Nostr Wallet Connect (NWC) — NIP-47
- Numeraire SwissKnife — REST
- Mock — for testing without a real node
- Custom — implement the
LnBackendtrait
- Architecture Guide
- Getting Started — First L402 payment with mock server
- Custom Backend — Implement
LnBackendfor your node - Budget Control — Spending limits for autonomous agents
- CONTRIBUTING.md — Development setup and PR workflow
- CHANGELOG.md
Licensed under either of Apache-2.0 or MIT at your option.
Contributions welcome! Please read CONTRIBUTING.md first.