Skip to content

lightninglabs/L402sdk

L402sdk

L402 client SDK for AI agent frameworks. Pay for APIs with Lightning.

crates.io npm (WASM) npm (AI SDK) PyPI MIT or Apache-2.0 Licensed Rustc Version 1.85.0+

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.

Install

# 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-langchain

Quick Start

import { 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.

Packages

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

Supported Lightning Backends

  • 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 LnBackend trait

Documentation

License

Licensed under either of Apache-2.0 or MIT at your option.

Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

About

L402 client SDK for AI agent frameworks — pay for APIs with Lightning

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors