LangChain integration for LightningProx — pay-per-use AI access via Bitcoin Lightning Network micropayments.
No API keys. No accounts. No subscriptions. Just Lightning payments.
pip install langchain-lightningproxfrom langchain_lightningprox import LightningProxLLM
# Initialize with your LNBits wallet
llm = LightningProxLLM(
lnbits_url="https://demo.lnbits.com",
lnbits_admin_key="your_admin_key_here"
)
# Use it like any LangChain LLM
response = llm.invoke("Explain quantum computing in one sentence.")
print(response)┌──────────────┐ ┌───────────────┐ ┌─────────────┐
│ Your Code │ ──▶ │ LightningProx │ ──▶ │ Claude/GPT │
│ │ │ │ │ │
│ (LNBits) │ ─$─▶ │ (verify) │ │ (respond) │
│ │ ◀── │ │ ◀── │ │
└──────────────┘ └───────────────┘ └─────────────┘
- Your code sends a prompt via the LangChain interface
- LightningProx returns a Lightning invoice (~5-50 sats)
- The library automatically pays via your LNBits wallet
- LightningProx verifies payment and forwards to Claude/GPT
- Response returned to your code
All automatic. No manual intervention.
The easiest way to start is with demo.lnbits.com:
- Go to https://demo.lnbits.com
- Create a new wallet
- Click your wallet → API info
- Copy the Admin key
Send a small amount of sats (~500) to your wallet's Lightning address. You can use any Lightning wallet (Phoenix, Muun, Cash App, etc.) to send.
from langchain_lightningprox import LightningProxLLM
llm = LightningProxLLM(
lnbits_url="https://demo.lnbits.com",
lnbits_admin_key="your_admin_key_here"
)
# Single query
response = llm.invoke("What is Bitcoin?")
print(response)llm = LightningProxLLM(
# Required
lnbits_admin_key="your_admin_key",
# Optional (defaults shown)
lnbits_url="https://demo.lnbits.com",
model="claude-sonnet-4-20250514", # or "gpt-4-turbo"
max_tokens=256,
api_url="https://lightningprox.com/v1/messages",
)| Model | Provider | Best For |
|---|---|---|
claude-sonnet-4-20250514 |
Anthropic | General use (default) |
claude-3-5-sonnet-20241022 |
Anthropic | General use |
gpt-4-turbo |
OpenAI | General use |
from langchain_lightningprox import LightningProxLLM
llm = LightningProxLLM(
lnbits_url="https://demo.lnbits.com",
lnbits_admin_key="your_key"
)
# Simple question
answer = llm.invoke("What causes rainbows?")
print(answer)import os
from langchain_lightningprox import LightningProxLLM
llm = LightningProxLLM(
lnbits_url=os.getenv("LNBITS_URL", "https://demo.lnbits.com"),
lnbits_admin_key=os.getenv("LNBITS_ADMIN_KEY")
)questions = [
"What is photosynthesis?",
"How do airplanes fly?",
"Why is the sky blue?"
]
for q in questions:
print(f"Q: {q}")
print(f"A: {llm.invoke(q)}\n")# Use GPT-4 Turbo instead
llm = LightningProxLLM(
lnbits_admin_key="your_key",
model="gpt-4-turbo"
)- ~5-50 sats per request (depending on response length)
- 50% discount on cached/repeated queries
- No minimums, no subscriptions
At current rates, 1000 sats ≈ $1 USD gets you roughly 20-200 queries.
Perfect for AI agents that need to pay for their own intelligence:
class ResearchAgent:
def __init__(self):
self.llm = LightningProxLLM(
lnbits_admin_key=os.getenv("AGENT_WALLET_KEY")
)
def research(self, topic):
return self.llm.invoke(f"Summarize recent developments in {topic}")Build apps where users pay per query without managing API keys:
def answer_question(user_question, user_wallet_key):
llm = LightningProxLLM(lnbits_admin_key=user_wallet_key)
return llm.invoke(user_question)Test prompts without committing to monthly subscriptions:
# Each query costs ~5-50 sats
# Perfect for experimentation
for prompt_variation in prompt_variations:
result = llm.invoke(prompt_variation)
evaluate(result)While this library uses LNBits by default, you can integrate other Lightning wallets by subclassing:
class StrikeLightningProx(LightningProxLLM):
def _pay_invoice(self, payment_request: str) -> bool:
# Implement Strike API payment
passSupported wallet APIs:
- LNBits (built-in)
- Strike (subclass)
- Voltage (subclass)
- LND (subclass)
- Any wallet with a payment API
from langchain_lightningprox import LightningProxLLM
llm = LightningProxLLM(lnbits_admin_key="your_key")
try:
response = llm.invoke("Hello!")
except RuntimeError as e:
if "Payment failed" in str(e):
print("Insufficient balance in wallet")
else:
print(f"Error: {e}")- Micropayments — Pay fractions of a cent per request
- No accounts — Payment IS authentication
- Instant — Settlements in milliseconds
- Global — Works anywhere, no banking required
- Autonomous — Agents can pay without human intervention
- Website: lightningprox.com
- Docs: lightningprox.com/docs
- API Capabilities: lightningprox.com/api/capabilities
- GitHub: github.com/unixlamadev-spec/langchain-lightningprox
MIT