A minimal autonomous agent that pays for AI model access using Bitcoin Lightning — with no API keys, no accounts, and no pre-funded balances.
The agent requests an AI response, receives a Lightning invoice, pays it automatically, and retries the request with proof of payment.
Built for LightningProx — a neutral payment layer for AI APIs designed for autonomous software.
- ⚡ Pay-per-request AI access
- 🤖 Automatic Lightning payments
- 🔑 No AI provider API keys
- 👤 No user accounts
- 💰 Real Bitcoin payments (no mocks)
- 🔁 Retry logic after payment
- 🧠 Works with Claude, GPT, and more
This is the core loop an autonomous agent would use to buy intelligence on demand.
- Node.js 18+
- An LNBits wallet (demo.lnbits.com works great)
- A small Lightning balance (~100 sats to test)
git clone https://github.com/unixlamadev-spec/lightningprox-agent-example
cd lightningprox-agent-example
npm installcp .env.example .envEdit .env with your LNBits admin key:
LNBITS_URL=https://demo.lnbits.com
LNBITS_ADMIN_KEY=your_admin_key_here
💡 Get a free LNBits wallet at demo.lnbits.com. Click your wallet → API info → copy the Admin key.
npm start
# or
node agent.js🤖 LightningProx Agent Starting…
Model: claude-sonnet-4-20250514
LNBits: https://demo.lnbits.com
📤 Sending request to LightningProx…
⚡ Invoice received
Charge ID: abc-123-xyz
💸 Paying via LNBits…
Amount: 5 sats (~$0.005)
✅ LNBits payment sent
📤 Retrying with payment proof…
🤖 Agent Response:
Lightning payments allow autonomous AI agents to pay for services instantly...
✅ Agent completed successfully!
┌─────────────┐ ┌───────────────┐ ┌─────────────┐
│ Agent │ ──1──▶ │ LightningProx │ ──2──▶ │ Claude/GPT │
│ │ ◀──3── │ │ │ │
│ │ │ (invoice) │ │ │
│ │ ──4──▶ │ │ │ │
│ (LNBits) │ ──pay─▶ │ (verify) │ ──5──▶ │ (respond) │
│ │ ◀──6── │ │ ◀───── │ │
└─────────────┘ └───────────────┘ └─────────────┘
1. Agent sends prompt
2. LightningProx calculates cost
3. Returns Lightning invoice
4. Agent pays via LNBits
5. LightningProx verifies, forwards to AI
6. Response returned to agent
Each run creates a real Bitcoin Lightning payment. Keep balances small while testing.
LightningProx enforces:
- Single-use invoices
- Payment hash validation
- Protection against double-spending
If you see { "error": "AI provider error" }, simply retry — it's an upstream issue, not a payment problem.
claude-sonnet-4-20250514✅ (recommended)gpt-4-turbo✅
This pattern enables:
- 🤖 Autonomous agents paying for tools
- 🔐 No centralized accounts
- 🔑 No shared API keys
- 📊 Metered, auditable usage
- 🌍 Global, permissionless access
Lightning becomes the payment rail for AI.
- Website: lightningprox.com
- Docs: lightningprox.com/docs
- API Capabilities: lightningprox.com/api/capabilities
MIT