JavaScript client library for L402 (HTTP 402 Payment Required with Lightning Network) - pay-per-request APIs
l402-js is an early-stage TypeScript project in the AI payments / x402 ecosystem, focused on api, bitcoin, http-402, javascript. It currently has 0 GitHub stars and 0 forks, and sits alongside related tools like l402-go, boltzpay, toll-booth, boltzpay, 402-mcp, satgate.
JavaScript client library for L402 (HTTP 402 Payment Required with Lightning Network) - pay-per-request APIs.
npm install l402
L402 is a protocol for pay-per-request APIs using Lightning Network:
import { fetch } from 'l402';
// Define a wallet that can pay Lightning invoices
const wallet = {
async payInvoice(invoice: string): Promise<string> {
// Use your Lightning wallet (LNbits, LND, Alby, etc.)
const response = await fetch('https://your-wallet/pay', {
method: 'POST',
body: JSON.stringify({ invoice }),
});
return response.json().preimage;
}
};
// Make a paid API request
const result = await fetch('https://api.example.com/paid-endpoint', wallet, {
autoPay: true,
maxSats: 100, // Don't pay more than 100 sats
});
if (result.paid) {
console.log('Paid and received:', result.body);
} else if (result.status === 402) {
console.log('Payment required:', result.challenge);
} else {
console.log('Response:', result.body);
}
If you want to handle payment yourself:
import { parseChallenge } from 'l402';
const response = await fetch('https://api.example.com/paid-endpoint');
const body = await response.text();
if (response.status === 402) {
const challenge = parseChallenge(response.status, response.headers, body);
console.log('Invoice:', challenge.invoice);
console.log('Amount:', challenge.amountSats, 'sats');
console.log('Payment hash:', challenge.paymentHash);
}
| Option | Type | Default | Description |
|---|---|---|---|
autoPay |
boolean | false | Automatically pay invoices |
maxSats |
number | 1000 | Maximum sats to pay automatically |
allowUnknownAmount |
boolean | false | Allow auto-paying when amount is unknown |
retryBackoff |
number[] | [0, 250, 750, 1500] | Milliseconds to wait between retries |
Implement this interface to use auto-pay:
interface Wallet {
payInvoice(invoice: string): Promise<string>; // Returns preimage
}
Try against a real L402 endpoint:
curl -i https://maximumsats.com/api/dvm
# Returns 402 with invoice, then pay and retry with:
# X-Payment-Hash: <payment_hash>
MIT
Go client library for L402 (HTTP 402 Payment Required with Lightning Network) - pay-per-request APIs
Give your AI agents a fetch() that pays. Multi-protocol, multi-chain, open source.
Any API becomes a Lightning toll booth in one line. L402 middleware for Express, Hono, Deno, Bun, and Workers.
Enable AI agents to access paid APIs across multiple protocols and chains with automated payment and data retrieval in one call.
402 client MCP - AI agents discover, pay for, and consume L402 + x402 APIs
Lightning-paid AI inference - monetise any OpenAI-compatible endpoint in 30 seconds
The financial operating system for AI agents. A single HTTP client that intercepts '402 Payment Required', routes across x402, L402, and MPP, persists credentials as recoverable assets, enforces per-envelope budgets, and emits a structured trace.
540 security tests for AI agent systems — MCP, A2A, x402/L402, decision governance, benchmark integrity, skill supply chain. AIUC-1 pre-cert, NIST AI 800-2 aligned, MCP tool-poisoning reproduction. v4.9.1
A neutral landscape analysis of AI agent payment protocols (x402, MPP, L402, Google AP2, Visa TAP + ICC, Mastercard Agent Pay, Amex ACE, Google/Shopify UCP, OpenAI ACP, and others). Maintained by Genesis Software Group, Copenhagen. Updated April 2026. CC BY 4.0.
MCP Server for Lightning Faucet - Give your AI agent a Bitcoin wallet
MCP server for 402 Index: discover 15,000+ paid API endpoints across L402, x402, and MPP
Sovereign oracle protocol — cryptographically signed data over Lightning sats (L402) and USDC on Base (x402). 11 feeds, 9 exchanges, DLC attestations, MCP server. No API keys, no accounts, no trust.