get_balance
Check remaining balance on a LightningProx spend token to monitor prepaid access for AI models. Returns balance in sats.
Instructions
Check the remaining balance on a LightningProx spend token. Returns balance in sats.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| spend_token | Yes | LightningProx spend token (starts with lnpx_) |
Implementation Reference
- src/index.ts:143-152 (handler)The getBalance function fetches the balance from the API using the provided spend token.
async function getBalance(spendToken: string): Promise<any> { const res = await fetch(`${LIGHTNINGPROX_URL}/v1/balance`, { headers: { "X-Spend-Token": spendToken }, }); if (!res.ok) { const err = await res.json() as any; throw new Error(err.error || `Balance check failed: ${res.status}`); } return res.json(); } - src/index.ts:62-75 (registration)Tool registration definition for "get_balance".
name: "get_balance", description: "Check the remaining balance on a LightningProx spend token. Returns balance in sats.", inputSchema: { type: "object", properties: { spend_token: { type: "string", description: "LightningProx spend token (starts with lnpx_)", }, }, required: ["spend_token"], }, }, - src/index.ts:250-265 (handler)MCP request handler logic for "get_balance".
case "get_balance": { const { spend_token } = args as any; const data = await getBalance(spend_token); const sats = data.balance_sats ?? data.sats ?? data.balance ?? "?"; const usd = data.balance_usd != null ? ` (~$${Number(data.balance_usd).toFixed(4)})` : ""; return { content: [ { type: "text", text: `⚡ Balance: ${sats} sats${usd}\n\nToken: ${spend_token.slice(0, 16)}…\nTop up: ${LIGHTNINGPROX_URL}/topup`, }, ], }; }