langchain-lightningprox
LangChain integration for LightningProx — pay-per-use AI access via Bitcoin Lightning Network micropayments.
No API keys. No accounts. No subscriptions. Just Lightning payments.
Installation
pip install langchain-lightningprox
Quick Start
from 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)
How It Works
┌──────────────┐ ┌───────────────┐ ┌─────────────┐
│ 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.
Setup
1. Get an LNBits Wallet
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
2. Fund Your Wallet
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.
3. Use It
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)
Configuration
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",
)
Available Models
| 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 |
Examples
Basic Usage
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)
With Environment Variables
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")
)
Multiple Queries
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")
Using Different Models
# Use GPT-4 Turbo instead
llm = LightningProxLLM(
lnbits_admin_key="your_key",
model="gpt-4-turbo"
)
Pricing
- ~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.
Use Cases
Autonomous Agents
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}")
Pay-Per-Use Applications
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)
Cost-Controlled Experiments
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)
Alternative Wallet Providers
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
pass
Supported wallet APIs:
- LNBits (built-in)
- Strike (subclass)
- Voltage (subclass)
- LND (subclass)
- Any wallet with a payment API
Error Handling
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}")
Why Lightning Payments?
- 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
Links
- Website: lightningprox.com
- Docs: lightningprox.com/docs
- API Capabilities: lightningprox.com/api/capabilities
- GitHub: github.com/unixlamadev-spec/langchain-lightningprox
License
MIT
Metadata
Release files for langchain-lightningprox 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| langchain_lightningprox-0.1.0.tar.gz | 6.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| langchain_lightningprox-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.2 kB
Release files / langchain_lightningprox-0.1.0.tar.gz
| Download URL | langchain_lightningprox-0.1.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e14a63d9ebcfb926a624522a1836046b8a22ad34a157576a0813ec74e856ddd
|
|
BLAKE2b-256 checksum How to use checksums |
66147f0b539b0078b0c31c385a39b0f091f5dd1f6e691ec81b16085ab56f8251
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / langchain_lightningprox-0.1.0-py3-none-any.whl
| Download URL | langchain_lightningprox-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f5d2194f10969e7f9d0ddf5e8ca062561ad052dc7df22e66b00a219c2615452
|
|
BLAKE2b-256 checksum How to use checksums |
c5abeb1f3943f66c3aebd5e002914b4e30e528d887d2d28a45a2226812dd3a51
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|