{"_id":"@lightninglabs/l402-ai","name":"@lightninglabs/l402-ai","dist-tags":{"latest":"0.1.0"},"versions":{"0.1.0":{"name":"@lightninglabs/l402-ai","version":"0.1.0","description":"L402 Lightning payment tools for the Vercel AI SDK. Let AI agents pay for APIs with Bitcoin.","type":"module","main":"dist/index.js","types":"dist/index.d.ts","exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js"}},"scripts":{"build":"tsc","test":"vitest run","test:watch":"vitest","lint":"eslint src/ tests/","format":"prettier --write 'src/**/*.ts' 'tests/**/*.ts'","format:check":"prettier --check 'src/**/*.ts' 'tests/**/*.ts'","typecheck":"tsc --noEmit"},"keywords":["l402","lightning","bitcoin","ai","vercel","ai-sdk","agent","payments"],"packageManager":"yarn@4.13.0","author":{"name":"Dario Anongba Varela","email":"dario.anongba@gmail.com"},"license":"MIT OR Apache-2.0","repository":{"type":"git","url":"git+https://github.com/lightninglabs/L402sdk.git","directory":"packages/l402-ai-sdk"},"homepage":"https://github.com/lightninglabs/L402sdk","peerDependencies":{"ai":">=6.0.0","zod":"^3.25.76 || ^4.1.8"},"dependencies":{"@lightninglabs/l402":"^0.1.0"},"devDependencies":{"@types/node":"^25.5.0","ai":"^6.0.116","eslint":"^9.0.0","prettier":"^3.8.1","typescript":"^5.9.3","vitest":"^4.1.0","zod":"^3.25.76"},"_id":"@lightninglabs/l402-ai@0.1.0","bugs":{"url":"https://github.com/lightninglabs/L402sdk/issues"},"_nodeVersion":"22.22.2","_npmVersion":"10.9.7","dist":{"integrity":"sha512-mjZFRgVZTWFMG/jkA/UzV25xr5CdAs1hhbNMmPjhqTL+QqljbwagtXdkGyXfOM00IuiTSnU07L4LjmT9+GKWyg==","shasum":"4da9dff7122ad3a683ce3ed07cd0b2defe6c775a","tarball":"https://registry.npmjs.org/@lightninglabs/l402-ai/-/l402-ai-0.1.0.tgz","fileCount":10,"unpackedSize":20223,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@lightninglabs%2fl402-ai@0.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQDRERO0u07hu/5JVvLXTlhEqCZ5h9QwAPhamx+Yv5pHPwIgXMCpJ9YbkFm6GpQT6kUNp81qx6TVUIs+keuIoKfUz5I="}]},"_npmUser":{"name":"dario_nakamoto","email":"dario.anongba@gmail.com"},"directories":{},"maintainers":[{"name":"roasbeef","email":"laolu32@gmail.com"},{"name":"jamalj","email":"jamal@lightning.engineering"},{"name":"kaloudis","email":"npm@nyxmail.com"},{"name":"dario_nakamoto","email":"dario.anongba@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/l402-ai_0.1.0_1776261362614_0.5857750676144049"},"_hasShrinkwrap":false}},"time":{"created":"2026-04-15T13:56:02.493Z","0.1.0":"2026-04-15T13:56:02.762Z","modified":"2026-04-15T13:56:03.232Z"},"maintainers":[{"name":"roasbeef","email":"laolu32@gmail.com"},{"name":"jamalj","email":"jamal@lightning.engineering"},{"name":"kaloudis","email":"npm@nyxmail.com"},{"name":"dario_nakamoto","email":"dario.anongba@gmail.com"}],"description":"L402 Lightning payment tools for the Vercel AI SDK. Let AI agents pay for APIs with Bitcoin.","homepage":"https://github.com/lightninglabs/L402sdk","keywords":["l402","lightning","bitcoin","ai","vercel","ai-sdk","agent","payments"],"repository":{"type":"git","url":"git+https://github.com/lightninglabs/L402sdk.git","directory":"packages/l402-ai-sdk"},"author":{"name":"Dario Anongba Varela","email":"dario.anongba@gmail.com"},"bugs":{"url":"https://github.com/lightninglabs/L402sdk/issues"},"license":"MIT OR Apache-2.0","readme":"<div align=\"center\">\n  <h1>l402-ai-sdk</h1>\n\n  <p>\n    <strong>L402 Lightning payment tools for the Vercel AI SDK</strong>\n  </p>\n\n  <p>\n    <a href=\"https://www.npmjs.com/package/@lightninglabs/l402-ai\"><img alt=\"npm\" src=\"https://img.shields.io/npm/v/@lightninglabs/l402-ai.svg\"/></a>\n    <a href=\"https://www.npmjs.com/package/@lightninglabs/l402-ai\"><img alt=\"npm downloads\" src=\"https://img.shields.io/npm/dm/@lightninglabs/l402-ai.svg\"/></a>\n    <a href=\"https://github.com/lightninglabs/L402sdk/blob/main/LICENSE-MIT\"><img alt=\"MIT or Apache-2.0 Licensed\" src=\"https://img.shields.io/badge/license-MIT%2FApache--2.0-blue.svg\"/></a>\n  </p>\n\n</div>\n\nLet AI agents autonomously pay for APIs with Bitcoin over the Lightning Network.\n\nAll L402 protocol logic runs in Rust via WASM (`l402-wasm`). This package provides thin Vercel AI SDK tool wrappers.\n\n## What is L402?\n\n[L402](https://docs.lightning.engineering/the-lightning-network/l402) is a protocol that uses HTTP 402 (Payment Required) responses to gate API access behind Lightning Network payments. When a server responds with 402, the client pays a Lightning invoice and retries with proof of payment.\n\nl402-ai-sdk wraps this flow into [Vercel AI SDK tools](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling), so AI agents can access paid APIs without manual intervention.\n\n## Install\n\n```bash\nyarn add @lightninglabs/l402-ai\n```\n\nPeer dependencies: `ai` (>=6.0.0) and `zod` (^3.25 or ^4.1).\n\n## Quick Start\n\n```typescript\nimport { createL402Tools, WasmL402Client, WasmBudgetConfig } from '@lightninglabs/l402-ai';\nimport { generateText } from 'ai';\nimport { openai } from '@ai-sdk/openai';\n\n// Create L402 client backed by LND REST\nconst client = WasmL402Client.withLndRest(\n  'https://localhost:8080',\n  process.env.LND_MACAROON!,\n  new WasmBudgetConfig(1000, 0, 50_000, 0),  // per-request, hourly, daily, total\n  100,  // max routing fee (sats)\n);\n\n// Create AI SDK tools\nconst tools = createL402Tools({ client });\n\n// Use with any Vercel AI SDK model\nconst result = await generateText({\n  model: openai('gpt-4o'),\n  tools,\n  maxSteps: 5,\n  prompt: 'Fetch the premium weather data from https://api.example.com/v1/weather',\n});\n\nconsole.log(result.text);\n```\n\n## Tools\n\n`createL402Tools()` returns two tools:\n\n### `l402_fetch`\n\nFetch any URL, automatically handling L402 payment challenges. When the server returns HTTP 402 with a Lightning invoice, the tool pays it, caches the token, and retries.\n\n**Parameters:**\n- `url` (string, required): The URL to fetch\n- `method` (string, optional): HTTP method (GET or POST). Default: GET\n- `body` (string, optional): Request body for POST (JSON-encoded)\n\n**Returns:** Response body, status code, payment flag, and receipt (if paid).\n\n### `l402_get_receipts`\n\nGet all payment receipts from the current session for cost tracking and auditing.\n\n**Returns:** Total spent, payment count, and detailed receipts.\n\n## Lightning Backends\n\nBackends are configured when creating the `WasmL402Client` (all in Rust/WASM):\n\n### LND REST\n\n```typescript\nimport { WasmL402Client, WasmBudgetConfig } from '@lightninglabs/l402-ai';\n\nconst client = WasmL402Client.withLndRest(\n  'https://localhost:8080',\n  'hex-encoded-admin-macaroon',\n  WasmBudgetConfig.unlimited(),\n  100,\n);\n```\n\n### SwissKnife\n\n```typescript\nconst client = WasmL402Client.withSwissKnife(\n  'https://api.numeraire.tech',\n  'your-api-key',\n  WasmBudgetConfig.unlimited(),\n  100,\n);\n```\n\n## Budget Control\n\nSet spending limits via `WasmBudgetConfig` to prevent runaway costs. Pass `0` for any limit to leave it unlimited.\n\n```typescript\nconst budget = new WasmBudgetConfig(\n  1000,       // per-request max (sats)\n  10_000,     // hourly max (sats)\n  100_000,    // daily max (sats)\n  1_000_000,  // total max (sats)\n);\n\nconst client = WasmL402Client.withLndRest(url, macaroon, budget, 100);\n```\n\n## Architecture\n\n```\nVercel AI SDK → createL402Tools() → WasmL402Client (WASM)\n                                            │\n                                   ┌────────┴────────┐\n                                   ▼                  ▼\n                              l402-core        l402-proto\n                              (Rust/WASM)         (Rust/WASM)\n                                   │\n                     ┌─────────────┼─────────────┐\n                     ▼             ▼             ▼\n                  LnBackend    TokenStore    BudgetTracker\n                  (port)       (port)\n                     │             │\n               ┌─────┴─────┐      │\n               ▼           ▼      ▼\n            LND REST   SwissKnife  InMemory\n            (Rust)     (Rust)      (Rust)\n```\n\nAll protocol logic (challenge parsing, budget enforcement, token caching, receipt tracking) runs in Rust compiled to WASM. The TypeScript layer is a thin wrapper providing Vercel AI SDK tool definitions.\n\n## License\n\nMIT OR Apache-2.0\n","readmeFilename":"README.md","_rev":"1-9362b85ca13bfa237a6d008089e0e074"}