Skip to main content

यह क्या करता है

l402-kit एक बिल्ट-इन client के साथ आता है जो किसी भी AI एजेंट — या किसी भी स्क्रिप्ट — को L402-protected APIs को बिना खुद payment loop लिखे कॉल करने देता है।
Agent  →  GET /api/data
API    →  402 + BOLT11 invoice
Agent  →  pay invoice (Blink / Alby)
Agent  →  GET /api/data  Authorization: L402 macaroon:preimage
API    →  200 ✓
बीच की सब कुछ — invoice parsing, wallet call, retry — स्वचालित रूप से संभाला जाता है।

Node.js / TypeScript

1. इंस्टॉल करें

npm install l402-kit

2. एक wallet चुनें


Python

1. इंस्टॉल करें

pip install l402kit

2. API को कॉल करें


यह चरण दर चरण कैसे काम करता है

  1. client.fetch / client.get बिना किसी auth header के request भेजता है
  2. यदि API 402 लौटाता है, तो client response body (या WWW-Authenticate header) से invoice और macaroon पढ़ता है
  3. यह आपका बजट जाँचता है — यदि कीमत सीमा से अधिक होगी तो BudgetExceededError फेंकता है
  4. यह wallet.payInvoice(bolt11) को कॉल करता है और preimage का इंतजार करता है
  5. यह Authorization: L402 <macaroon>:<preimage> के साथ request को दोबारा भेजता है
  6. आपके कोड को अंतिम Response/httpx.Response लौटाता है
402 नहीं? Response बिना किसी बदलाव के पास-थ्रू हो जाता है।

खर्च की रिपोर्ट

// TypeScript
const report = client.spendingReport();
// { total: 42, remaining: 958, byDomain: { "api.example.com": 42 }, transactions: [...] }
# Python
report = client.spending_report()
print(f"Spent {report.total} sats, {report.remaining} remaining")

अगले कदम

Wallets

Blink, Alby — पूर्ण सेटअप और विकल्प

Budget control

प्रति-domain सीमाएँ, callbacks, रिपोर्ट

MCP Server

2 मिनट में Claude Desktop integration

LangChain

LangChain एजेंट के लिए drop-in tool