Skip to main content

AI Agent Integration

The open-source (MIT) Lightning Enable MCP server lets an AI agent such as Claude pay Lightning invoices and L402-protected APIs from a wallet you connect. Paying needs only a wallet; selling access (l402_producer) and some agent-marketplace actions need a Lightning Enable API key.

How auto-pay works​

When the agent calls access_l402_resource on a URL that answers 402 Payment Required, the MCP server:

  1. Reads the Lightning invoice (and macaroon) from the 402 response.
  2. Checks the price against your budget limits, and asks you for a confirmation code if the payment is above your auto-approve threshold.
  3. Pays the invoice from your wallet and gets the preimage.
  4. Retries the request with Authorization: L402 <macaroon>:<preimage> and returns the response.
User → Agent → MCP server → L402 API
↓
Your Lightning wallet (LND, NWC, or Strike)

L402 needs a wallet that returns the preimage: LND, Strike, or an NWC wallet such as CoinOS, CLINK, or Alby Hub. OpenNode and Primal can pay plain invoices with pay_invoice but can't complete L402.

Set it up​

  1. Install and connect a client. Follow MCP Quick Start, or the client guides for Claude Code, Cursor, Hermes, or Buzz.
  2. Pick a wallet. See Wallet Configuration or LND Node Setup.
  3. Set spending limits in ~/.lightning-enable/config.json before the first payment. See AI Spending Security.

Tools you'll use most​

ToolWhat it does
access_l402_resourceFetch a URL and pay its L402 challenge automatically
pay_l402_challengePay an invoice (and macaroon) you already hold; returns the credential
pay_invoicePay any BOLT11 invoice and return the preimage
discover_apiSearch the L402 registry, or read one API's manifest and prices
get_balanceWallet balance and session spend
budgetRead limits (action="status") or lower them for this session (action="tighten")
receiptsList payments (source="durable" or source="session")

The MCP Complete Guide lists every tool, its parameters, and the tool profiles.

Example​

User: Get the 7-day forecast from the Lightning weather API at
https://api.example.com/l402/proxy/weather/forecast/7day

Agent: [Uses access_l402_resource]
The forecast cost 25 sats, paid from your wallet. Here it is: ...

Building your own integration​

Outside an MCP client, use the L402 client libraries. They detect a wallet from the same environment variables (LND > NWC > Strike > OpenNode).

Python (l402-requests):

# pip install l402-requests
from l402_requests import AsyncL402Client

async with AsyncL402Client() as client:
response = await client.get("https://api.example.com/paid-resource")
print(response.json())

.NET (L402Requests):

// dotnet add package L402Requests
using L402Requests;

using var client = new L402HttpClient(new L402Options { MaxSatsPerRequest = 1000 });
var response = await client.GetAsync("https://api.example.com/paid-resource");
Console.WriteLine(await response.Content.ReadAsStringAsync());

Both packages document their budget controls and domain allowlists.

Next steps​