Skip to main content Switch to mobile version l402sdk-langchain 0.2.1 LangChain integration for L402sdk — L402 Lightning payments in AI agents
pip install l402sdk-langchain==0.2.1 Copy PIP instructions
LangChain tools for L402 Lightning payments
Enable AI agents to autonomously pay for L402-gated APIs using the Lightning Network.
pip install l402-langchain Quick Start
from l402_langchain import create_l402_client, L402FetchTool, L402BudgetTool # Create a client backed by LND REST client = create_l402_client( backend="lnd", url="https://localhost:8080", macaroon="hex-encoded-admin-macaroon", budget={"per_request_max": 500, "daily_max": 5000}, ) # Create LangChain tools fetch_tool = L402FetchTool(client=client) budget_tool = L402BudgetTool(client=client) # Use directly result = fetch_tool.invoke("https://api.example.com/data") print(result) # [Paid 100 sats (+0 fee) | status 200] # {"ok": true} # Check spending print(budget_tool.invoke("")) # Total spent: 100 sats across 1 payment(s). Tools
Makes HTTP requests with automatic L402 payment handling.
Input: URL string (GET) or JSON {"url": "...", "body": "..."} (POST)
# GET result = fetch_tool.invoke("https://api.example.com/data") # POST result = fetch_tool.invoke('{"url": "https://api.example.com/data", "body": "{\"query\": \"BTC\"}"}') L402BudgetTool
Reports spending: total sats, receipt count, per-endpoint breakdown.
result = budget_tool.invoke("") # Total spent: 250 sats across 2 payment(s). # # #1: https://api.example.com/weather — 50 sats (+0 fee, status 200, 5ms) # #2: https://api.example.com/market — 200 sats (+0 fee, status 200, 3ms) Callbacks
PaymentCallbackHandler hooks into LangChain's callback system for payment observability:
from l402_langchain import PaymentCallbackHandler handler = PaymentCallbackHandler( on_payment=lambda event: print(f"Paid {event.amount_sats} sats"), max_payment_alert=500, on_alert=lambda event: print(f"ALERT: {event.amount_sats} sats!"), ) # Pass to LangChain agent executor.invoke({"input": "..."}, config={"callbacks": [handler]}) Lightning Backends
from langchain_openai import ChatOpenAI from langchain.agents import create_tool_calling_agent, AgentExecutor from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder from l402_langchain import create_l402_client, L402FetchTool, L402BudgetTool client = create_l402_client( backend="lnd", url="https://localhost:8080", macaroon="deadbeef...", budget={"per_request_max": 500}, ) tools = [L402FetchTool(client=client), L402BudgetTool(client=client)] llm = ChatOpenAI(model="gpt-4o") prompt = ChatPromptTemplate.from_messages([ ("system", "You can fetch data from L402-gated APIs. " "Use l402_fetch for data, l402_check_budget for spending."), ("human", "{input}"), MessagesPlaceholder("agent_scratchpad"), ]) agent = create_tool_calling_agent(llm, tools, prompt) executor = AgentExecutor(agent=agent, tools=tools) response = executor.invoke({"input": "Get weather data, then report costs."}) License
Released: Dec 1, 2026
Author: Dario Anongba Varela
MIT OR Apache-2.0 View SPDX License List
ai-agents bitcoin l402 langchain lightning payments
Development Status 3 - Alpha
Intended Audience Developers
License OSI Approved :: Apache Software License
OSI Approved :: MIT License
Programming Language Python :: 3
Topic Software Development :: Libraries
Release files for l402sdk-langchain 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
Built distribution (wheel)
Total release size: 19.1 kB
Release files / l402sdk_langchain-0.2.1.tar.gz
Release files / l402sdk_langchain-0.2.1-py3-none-any.whl
Security for l402sdk-langchain 0.2.1
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.
Release history Release notifications | RSS feed
Dec 1, 2026 2 release files No provenance
Oct 29, 2026 2 release files No provenance
Apr 15, 2026 2 release files No provenance
"PyPI", "Python Package Index", and the blocks logos are registered trademarks of the Python Software Foundation.
© 2026 Python Software Foundation
Deployed from a8e35ed











