Lightning-native AI infrastructure for developers and agents
LightningProx provides pay-per-use access to AI models via Lightning Network micropayments. No accounts. No API keys. Payment authorizes each request.
curl -si -X POST https://lightningprox.com/v1/messages \
-H "Content-Type: application/json" \
-d '{
"model": "claude-opus-4-5-20251101",
"max_tokens": 100,
"messages": [{"role": "user", "content": "What is Lightning Network?"}]
}'
HTTP/1.1 402 Payment Required
WWW-Authenticate: L402 macaroon="eyJ...", invoice="lnbc..."
Content-Type: application/json
{
"error": "payment_required",
"message": "Pay the Lightning invoice and retry with Authorization: L402 <macaroon>:<preimage>",
"payment": {
"charge_id": "abc-123-xyz",
"payment_request": "lnbc...",
"amount_sats": 5,
"amount_usd": 0.005
}
}
# After paying the invoice, use the macaroon + payment preimage:
# macaroon = value from WWW-Authenticate header
# preimage = 64-char hex preimage from your Lightning wallet after payment
curl -X POST https://lightningprox.com/v1/messages \
-H "Content-Type: application/json" \
-H "Authorization: L402 <macaroon>:<preimage>" \
-d '{
"model": "claude-opus-4-5-20251101",
"max_tokens": 100,
"messages": [{"role": "user", "content": "What is Lightning Network?"}]
}'
Instead of paying per request, you can prepay with a larger Lightning payment and get a reusable spend token. Use it for multiple requests without generating new invoices each time.
Choose how many sats you want to load (10 - 100,000):
curl -X POST https://lightningprox.com/v1/topup \
-H "Content-Type: application/json" \
-d '{
"amount_sats": 500,
"duration_hours": 72
}'
{
"charge_id": "abc-123-xyz",
"payment_request": "lnbc...",
"amount_sats": 500,
"amount_usd": 0.50,
"duration_hours": 72,
"next_step": "/v1/tokens"
}
After paying the invoice, create a spend token:
curl -X POST https://lightningprox.com/v1/tokens \
-H "Content-Type: application/json" \
-d '{
"charge_id": "YOUR_CHARGE_ID",
"duration_hours": 72
}'
{
"token": "lnpx_a1b2c3d4e5f6...",
"balance_sats": 500,
"expires_at": "2026-02-12T19:00:00Z",
"status": "active"
}
Include X-Spend-Token in your requests — no more invoices:
curl -X POST https://lightningprox.com/v1/messages \
-H "Content-Type: application/json" \
-H "X-Spend-Token: lnpx_a1b2c3d4e5f6..." \
-d '{
"model": "claude-opus-4-5-20251101",
"max_tokens": 500,
"messages": [{"role": "user", "content": "Explain Lightning Network"}]
}'
# Instant response — cost deducted from token balance
curl https://lightningprox.com/v1/balance \
-H "X-Spend-Token: lnpx_a1b2c3d4e5f6..."
{
"balance_sats": 485,
"balance_usd": 0.485,
"requests_left_estimate": 97,
"expires_at": "2026-02-12T19:00:00Z",
"status": "active"
}
The LightningProx MCP Server lets AI agents in Claude Desktop, Claude Code, and Cursor query AI models and pay via Lightning — all through the Model Context Protocol.
go install github.com/unixlamadev-spec/lightningprox-mcp/cmd/mcp-server@latest
Add to your claude_desktop_config.json:
{
"mcpServers": {
"lightningprox": {
"command": "mcp-server",
"args": []
}
}
}
| Tool | Description |
|---|---|
| ask_ai | Query an AI model (pay with invoice or spend token) |
| get_invoice | Generate a Lightning invoice for a request |
| check_balance | Check spend token balance |
| list_models | List available models with pricing |
| get_pricing | Estimate cost before committing |
GitHub: github.com/unixlamadev-spec/lightningprox-mcp
Use the official LangChain integration for seamless Python development.
pip install langchain-lightningprox
from langchain_lightningprox import LightningProxLLM
llm = LightningProxLLM(
lnbits_url="https://demo.lnbits.com",
lnbits_admin_key="your_admin_key_here"
)
# Payments are handled automatically
response = llm.invoke("Explain quantum computing in one sentence.")
print(response)
GitHub: github.com/unixlamadev-spec/langchain-lightningprox
PyPI: pypi.org/project/langchain-lightningprox
For JavaScript agents and bots, use the reference implementation.
git clone https://github.com/unixlamadev-spec/lightningprox-agent-example
cd lightningprox-agent-example
npm install
# .env
LNBITS_URL=https://demo.lnbits.com
LNBITS_ADMIN_KEY=your_admin_key_here
node agent.js
GitHub: github.com/unixlamadev-spec/lightningprox-agent-example
Drop-in replacement for the OpenAI npm package. Change two lines — everything else stays identical.
npm install lightningprox-openai
// Before:
import OpenAI from 'openai'
const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY })
// After:
import OpenAI from 'lightningprox-openai'
const client = new OpenAI({ apiKey: process.env.LIGHTNINGPROX_SPEND_TOKEN })
// Everything else stays identical:
const response = await client.chat.completions.create({
model: 'claude-opus-4-5-20251101',
messages: [{ role: 'user', content: 'Hello' }]
})
console.log(response.choices[0].message.content)
npm: npmjs.com/package/lightningprox-openai
| Model | Provider | Type | Input Cost | Output Cost |
|---|---|---|---|---|
| claude-opus-4-5-20251101 | Anthropic | Chat | $3/1M tokens | $15/1M tokens |
| claude-sonnet-4-20250514 | Anthropic | Chat | $3/1M tokens | $15/1M tokens |
| claude-haiku-4-5-20251001 | Anthropic | Chat | $0.80/1M tokens | $4/1M tokens |
| gpt-4o | OpenAI | Chat | $2.50/1M tokens | $10/1M tokens |
| gpt-4-turbo | OpenAI | Chat | $10/1M tokens | $30/1M tokens |
| meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8 | Together.ai | Chat | $0.36/1M tokens | $0.36/1M tokens |
| meta-llama/Llama-3.3-70B-Instruct-Turbo | Together.ai | Chat | $0.88/1M tokens | $0.88/1M tokens |
| mistralai/Mixtral-8x7B-Instruct-v0.1 | Together.ai | Chat | $0.60/1M tokens | $0.60/1M tokens |
| deepseek-ai/DeepSeek-V3 | Together.ai | Chat | $1.25/1M tokens | $1.25/1M tokens |
| mistral-large-latest | Mistral | Chat | $2/1M tokens | $6/1M tokens |
| mistral-medium-latest | Mistral | Chat | $0.40/1M tokens | $2/1M tokens |
| mistral-small-latest | Mistral | Chat | $0.10/1M tokens | $0.30/1M tokens |
| open-mistral-nemo | Mistral | Chat | $0.15/1M tokens | $0.15/1M tokens |
| codestral-latest | Mistral | Code | $0.30/1M tokens | $0.90/1M tokens |
| devstral-latest | Mistral | Agentic Code | $0.40/1M tokens | $1.20/1M tokens |
| pixtral-large-latest | Mistral | Vision | $2/1M tokens | $6/1M tokens |
| magistral-medium-latest | Mistral | Reasoning | $2/1M tokens | $5/1M tokens |
| gemini-2.5-flash | Chat | $0.15/1M tokens | $0.60/1M tokens | |
| gemini-2.5-pro | Chat Requires thinking_config — automatically handled |
$1.25/1M tokens | $10/1M tokens | |
| gemini-3-flash-preview | Chat | $0.20/1M tokens | $0.80/1M tokens | |
| gemini-3-pro-preview | Chat | $2/1M tokens | $8/1M tokens |
Prices include a 20% markup to cover infrastructure and Lightning fees. All models accessible via spend token — no provider API keys required.
LightningProx is designed for autonomous agents that need to pay for services programmatically. No human intervention required.
Agents can discover LightningProx capabilities programmatically:
curl https://lightningprox.com/api/capabilities
Returns machine-readable JSON with models, pricing, and integration steps.
LightningProx supports streaming responses for real-time token-by-token output. This provides a much better user experience for chat applications.
Add "stream": true to your request. Use a spend token or L402 credential:
# With spend token (recommended for streaming):
curl -X POST https://lightningprox.com/v1/messages \
-H "Content-Type: application/json" \
-H "X-Spend-Token: lnpx_your_token_here" \
-d '{
"model": "claude-opus-4-5-20251101",
"max_tokens": 500,
"stream": true,
"messages": [{"role": "user", "content": "Write a haiku about Bitcoin"}]
}'
# Or with L402 credential:
# -H "Authorization: L402 <macaroon>:<preimage>"
Responses are sent as Server-Sent Events (SSE):
data: {"type":"content_block_delta","delta":{"text":"Digital"}}
data: {"type":"content_block_delta","delta":{"text":" gold"}}
data: {"type":"content_block_delta","delta":{"text":" flows"}}
data: {"type":"message_stop"}
data: [DONE]
const response = await fetch('https://lightningprox.com/v1/messages', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-Spend-Token': spendToken // or: 'Authorization': `L402 ${macaroon}:${preimage}`
},
body: JSON.stringify({
model: 'claude-opus-4-5-20251101',
max_tokens: 500,
stream: true,
messages: [{ role: 'user', content: prompt }]
})
});
const reader = response.body.getReader();
const decoder = new TextDecoder();
while (true) {
const { done, value } = await reader.read();
if (done) break;
const chunk = decoder.decode(value);
const lines = chunk.split('\n');
for (const line of lines) {
if (line.startsWith('data: ') && !line.includes('[DONE]')) {
const data = JSON.parse(line.slice(6));
if (data.delta?.text) {
process.stdout.write(data.delta.text);
}
}
}
}
import requests
response = requests.post(
'https://lightningprox.com/v1/messages',
headers={
'Content-Type': 'application/json',
'X-Spend-Token': spend_token # or: 'Authorization': f'L402 {macaroon}:{preimage}'
},
json={
'model': 'claude-opus-4-5-20251101',
'max_tokens': 500,
'stream': True,
'messages': [{'role': 'user', 'content': prompt}]
},
stream=True
)
for line in response.iter_lines():
if line:
line = line.decode('utf-8')
if line.startswith('data: ') and '[DONE]' not in line:
import json
data = json.loads(line[6:])
if 'delta' in data and 'text' in data['delta']:
print(data['delta']['text'], end='', flush=True)
| Endpoint | Method | Description |
|---|---|---|
| /v1/messages | POST | AI completion — Anthropic format. Auth: spend token or L402 credential |
| /v1/chat/completions | POST | AI completion — OpenAI-compatible format. Same auth as /v1/messages |
| /v1/models | GET | List available models with pricing (OpenAI-compatible format) |
| /v1/tokens | POST | Create a prepaid spend token from a paid invoice |
| /v1/topup | POST | Generate a Lightning invoice for any sats amount (10 - 100,000) |
| /v1/balance | GET | Check spend token balance (X-Spend-Token header) |
| /api/capabilities | GET | Service discovery for agents |
| /health | GET | Service health status |