Skip to content

unixlamadev-spec/lightningprox-agent-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LightningProx Agent Example

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.


What This Shows

  • ⚡ 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.


Quick Start

Requirements

  • Node.js 18+
  • An LNBits wallet (demo.lnbits.com works great)
  • A small Lightning balance (~100 sats to test)

Install

git clone https://github.com/unixlamadev-spec/lightningprox-agent-example
cd lightningprox-agent-example
npm install

Configure

cp .env.example .env

Edit .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.

Run

npm start
# or
node agent.js

Expected Output

🤖 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!

How It Works

┌─────────────┐         ┌───────────────┐         ┌─────────────┐
│   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

Important Notes

⚡ Lightning Is Real Money

Each run creates a real Bitcoin Lightning payment. Keep balances small while testing.

🔁 Safe Retries

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.

🧪 Tested Models

  • claude-sonnet-4-20250514 ✅ (recommended)
  • gpt-4-turbo

Why This Matters

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.


Learn More


License

MIT

About

This repository demonstrates a minimal autonomous agent that pays for AI model access using the Lightning Network — without API keys or accounts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors