generate_invoice
Create Bitcoin Lightning invoices to add funds to LightningProx spend tokens for pay-per-request AI model access. Specify satoshi amount to generate BOLT11 payment request.
Instructions
Generate a Bitcoin Lightning invoice to top up a LightningProx spend token. Returns a BOLT11 payment request and charge ID. Pay the invoice with any Lightning wallet.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount_sats | Yes | Amount in satoshis to top up (e.g. 5000, 25000, 100000) |
Implementation Reference
- src/index.ts:154-166 (handler)The `generateInvoice` function, which performs the actual API call to LightningProx to generate a BOLT11 invoice and charge ID.
async function generateInvoice(amountSats: number): Promise<any> { const res = await fetch(`${LIGHTNINGPROX_URL}/v1/topup`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ amount_sats: amountSats, duration_hours: 720 }), }); // 402 is expected — it IS the invoice response const data = await res.json() as any; if (!data.payment_request && !data.charge_id) { throw new Error(data.error || `Invoice generation failed: ${res.status}`); } return data; } - src/index.ts:76-90 (registration)Tool definition for `generate_invoice` within the `tools` array.
{ name: "generate_invoice", description: "Generate a Bitcoin Lightning invoice to top up a LightningProx spend token. Returns a BOLT11 payment request and charge ID. Pay the invoice with any Lightning wallet.", inputSchema: { type: "object", properties: { amount_sats: { type: "number", description: "Amount in satoshis to top up (e.g. 5000, 25000, 100000)", }, }, required: ["amount_sats"], }, }, - src/index.ts:267-292 (handler)The `CallToolRequestSchema` handler case for `generate_invoice`, which parses arguments and calls the `generateInvoice` helper function.
case "generate_invoice": { const { amount_sats } = args as any; const data = await generateInvoice(amount_sats); return { content: [ { type: "text", text: [ `⚡ Lightning Invoice Generated`, ``, `Amount: ${data.amount_sats || amount_sats} sats (~$${data.amount_usd || "?"})`, ``, `Invoice (BOLT11):`, data.payment_request, ``, `Charge ID: ${data.charge_id}`, ``, `Pay with any Lightning wallet, then use check_payment with the charge_id to get your spend token.`, ``, `Or pay at: ${LIGHTNINGPROX_URL}/topup`, ].join("\n"), }, ], }; }