Billing API

Full billing dashboard backend for the LVNG platform. Query credit balances and burn rates, view aggregated usage charts, configure auto-reload, manage payment methods, download invoices, and set up spending alerts. All endpoints require JWT authentication.

Base path: /api/v2/billing

Balance & Usage

Query current credit balance, burn rate, and aggregated usage data for charts.

GET/api/v2/billing/balanceAuthenticated

Get current credit balance, included and purchased credits, and the burn rate (average credits per hour over the last 24 hours).

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/balance \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"balance": 4250.00,
    400">class="text-emerald-400">"included_credits": 5000,
    400">class="text-emerald-400">"purchased_credits": 2000,
    400">class="text-emerald-400">"burn_rate_per_hour": 12.50,
    400">class="text-emerald-400">"updated_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
  }
}
GET/api/v2/billing/usage-chartAuthenticated

Get aggregated usage data for dashboard charts, broken down by day and model.

Query Parameters

startstringrequired

Start date in ISO 8601 format.

endstringrequired

End date in ISO 8601 format.

granularitystring

Aggregation granularity: "day" (default) or "week".

Request

cURL
400">curl -X 400">GET 400">class="text-emerald-400">"https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/usage-chart?start=2026-03-01&end=2026-04-01&granularity=day" \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"daily_usage": [
      { 400">class="text-emerald-400">"date": 400">class="text-emerald-400">"2026-03-01", 400">class="text-emerald-400">"credits": 45.20, 400">class="text-emerald-400">"requests": 120 },
      { 400">class="text-emerald-400">"date": 400">class="text-emerald-400">"2026-03-02", 400">class="text-emerald-400">"credits": 38.10, 400">class="text-emerald-400">"requests": 95 }
    ],
    400">class="text-emerald-400">"model_breakdown": [
      { 400">class="text-emerald-400">"model": 400">class="text-emerald-400">"claude-sonnet", 400">class="text-emerald-400">"credits": 520, 400">class="text-emerald-400">"requests": 1800 },
      { 400">class="text-emerald-400">"model": 400">class="text-emerald-400">"claude-haiku", 400">class="text-emerald-400">"credits": 85, 400">class="text-emerald-400">"requests": 3200 }
    ]
  }
}

Auto-Reload

Configure automatic credit top-up when your balance drops below a threshold.

GET/api/v2/billing/auto-reloadAuthenticated

Get current auto-reload configuration.

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/auto-reload \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"enabled": true,
    400">class="text-emerald-400">"threshold_credits": 500,
    400">class="text-emerald-400">"reload_amount": 5000,
    400">class="text-emerald-400">"payment_method_id": 400">class="text-emerald-400">"pm_abc123",
    400">class="text-emerald-400">"updated_at": 400">class="text-emerald-400">"2026-03-15T10:00:00.000Z"
  }
}
POST/api/v2/billing/auto-reloadAuthenticated

Create or update auto-reload configuration. Upserts on user_id.

Body Parameters

enabledboolean

Whether auto-reload is active. Defaults to false.

threshold_creditsnumber

Credit balance threshold that triggers a reload. Must be non-negative. Defaults to 500.

reload_amountnumber

Number of credits to add on reload. Must be positive. Defaults to 5000.

payment_method_idstring

UUID of the payment method to charge.

Request

cURL
400">curl -X 400">POST https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/auto-reload \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY" \
  -H 400">class="text-emerald-400">"Content-Type: application/json" \
  -d '{
    400">class="text-emerald-400">"enabled": true,
    400">class="text-emerald-400">"threshold_credits": 1000,
    400">class="text-emerald-400">"reload_amount": 10000,
    400">class="text-emerald-400">"payment_method_id": 400">class="text-emerald-400">"pm_abc123"
  }'

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"user_id": 400">class="text-emerald-400">"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
    400">class="text-emerald-400">"enabled": true,
    400">class="text-emerald-400">"threshold_credits": 1000,
    400">class="text-emerald-400">"reload_amount": 10000,
    400">class="text-emerald-400">"payment_method_id": 400">class="text-emerald-400">"pm_abc123",
    400">class="text-emerald-400">"updated_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
  }
}

Spending Alerts

Create alerts to be notified when spending exceeds a threshold over a given period. Optionally set a hard cap to block usage.

POST/api/v2/billing/alertsAuthenticated

Create a spending alert for a given period.

Body Parameters

periodstringrequired

Alert period: "daily", "weekly", or "monthly".

threshold_creditsnumberrequired

Credit threshold that triggers the alert. Must be positive.

hard_capboolean

If true, blocks usage when threshold is reached. Defaults to false.

workspace_idstring

Scope alert to a specific workspace.

Request

cURL
400">curl -X 400">POST https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/alerts \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY" \
  -H 400">class="text-emerald-400">"Content-Type: application/json" \
  -d '{
    400">class="text-emerald-400">"period": 400">class="text-emerald-400">"daily",
    400">class="text-emerald-400">"threshold_credits": 500,
    400">class="text-emerald-400">"hard_cap": false
  }'

Response 201

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"id": 400">class="text-emerald-400">"alert_abc123",
    400">class="text-emerald-400">"user_id": 400">class="text-emerald-400">"a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11",
    400">class="text-emerald-400">"period": 400">class="text-emerald-400">"daily",
    400">class="text-emerald-400">"threshold_credits": 500,
    400">class="text-emerald-400">"hard_cap": false,
    400">class="text-emerald-400">"workspace_id": null,
    400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
  }
}
GET/api/v2/billing/alertsAuthenticated

List all spending alerts for the authenticated user.

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/alerts \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": [
    {
      400">class="text-emerald-400">"id": 400">class="text-emerald-400">"alert_abc123",
      400">class="text-emerald-400">"period": 400">class="text-emerald-400">"daily",
      400">class="text-emerald-400">"threshold_credits": 500,
      400">class="text-emerald-400">"hard_cap": false,
      400">class="text-emerald-400">"workspace_id": null,
      400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
    }
  ]
}
DELETE/api/v2/billing/alerts/:idAuthenticated

Delete a spending alert.

Path Parameters

idstringrequired

UUID of the alert to delete.

Request

cURL
400">curl -X 400">DELETE https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/alerts/alert_abc123 \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"message": 400">class="text-emerald-400">"Alert deleted"
}

Invoices

List and download billing invoices.

GET/api/v2/billing/invoicesAuthenticated

List all invoices for the authenticated user, ordered by period end date (newest first).

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/invoices \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": [
    {
      400">class="text-emerald-400">"id": 400">class="text-emerald-400">"inv_abc123",
      400">class="text-emerald-400">"period_start": 400">class="text-emerald-400">"2026-03-01",
      400">class="text-emerald-400">"period_end": 400">class="text-emerald-400">"2026-03-31",
      400">class="text-emerald-400">"subscription_amount": 49.00,
      400">class="text-emerald-400">"credits_included": 5000,
      400">class="text-emerald-400">"credits_used": 6200,
      400">class="text-emerald-400">"overage_credits": 1200,
      400">class="text-emerald-400">"overage_amount": 12.00,
      400">class="text-emerald-400">"total_amount": 61.00,
      400">class="text-emerald-400">"status": 400">class="text-emerald-400">"paid",
      400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T00:00:00.000Z"
    }
  ]
}
GET/api/v2/billing/invoices/:id/downloadAuthenticated

Download invoice data as a JSON file. Returns with Content-Disposition header for file download.

Path Parameters

idstringrequired

UUID of the invoice.

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/invoices/inv_abc123/download \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY" \
  -o invoice.json

Response 200

{
  400">class="text-emerald-400">"invoice_id": 400">class="text-emerald-400">"inv_abc123",
  400">class="text-emerald-400">"period_start": 400">class="text-emerald-400">"2026-03-01",
  400">class="text-emerald-400">"period_end": 400">class="text-emerald-400">"2026-03-31",
  400">class="text-emerald-400">"subscription_amount": 49.00,
  400">class="text-emerald-400">"credits_included": 5000,
  400">class="text-emerald-400">"credits_used": 6200,
  400">class="text-emerald-400">"overage_credits": 1200,
  400">class="text-emerald-400">"overage_amount": 12.00,
  400">class="text-emerald-400">"total_amount": 61.00,
  400">class="text-emerald-400">"status": 400">class="text-emerald-400">"paid",
  400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T00:00:00.000Z"
}

Payment Methods

Manage payment methods on file. Stripe integration ready.

POST/api/v2/billing/payment-methodsAuthenticated

Add a payment method. Currently supports card type with brand, last four digits, and expiration.

Body Parameters

brandstringrequired

Card brand (e.g. "visa", "mastercard").

last_fourstringrequired

Last 4 digits of the card number.

exp_monthnumberrequired

Expiration month (1-12).

exp_yearnumberrequired

Expiration year (must not be in the past).

is_defaultboolean

Set as default payment method. Defaults to false.

Request

cURL
400">curl -X 400">POST https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/payment-methods \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY" \
  -H 400">class="text-emerald-400">"Content-Type: application/json" \
  -d '{
    400">class="text-emerald-400">"brand": 400">class="text-emerald-400">"visa",
    400">class="text-emerald-400">"last_four": 400">class="text-emerald-400">"4242",
    400">class="text-emerald-400">"exp_month": 12,
    400">class="text-emerald-400">"exp_year": 2028,
    400">class="text-emerald-400">"is_default": true
  }'

Response 201

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": {
    400">class="text-emerald-400">"id": 400">class="text-emerald-400">"pm_abc123",
    400">class="text-emerald-400">"400">type": 400">class="text-emerald-400">"card",
    400">class="text-emerald-400">"brand": 400">class="text-emerald-400">"visa",
    400">class="text-emerald-400">"last_four": 400">class="text-emerald-400">"4242",
    400">class="text-emerald-400">"exp_month": 12,
    400">class="text-emerald-400">"exp_year": 2028,
    400">class="text-emerald-400">"is_default": true,
    400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
  }
}
GET/api/v2/billing/payment-methodsAuthenticated

List all payment methods for the authenticated user.

Request

cURL
400">curl -X 400">GET https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/payment-methods \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"data": [
    {
      400">class="text-emerald-400">"id": 400">class="text-emerald-400">"pm_abc123",
      400">class="text-emerald-400">"400">type": 400">class="text-emerald-400">"card",
      400">class="text-emerald-400">"brand": 400">class="text-emerald-400">"visa",
      400">class="text-emerald-400">"last_four": 400">class="text-emerald-400">"4242",
      400">class="text-emerald-400">"exp_month": 12,
      400">class="text-emerald-400">"exp_year": 2028,
      400">class="text-emerald-400">"is_default": true,
      400">class="text-emerald-400">"created_at": 400">class="text-emerald-400">"2026-04-01T12:00:00.000Z"
    }
  ]
}
DELETE/api/v2/billing/payment-methods/:idAuthenticated

Remove a payment method. Verifies ownership before deletion.

Path Parameters

idstringrequired

UUID of the payment method.

Request

cURL
400">curl -X 400">DELETE https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/payment-methods/pm_abc123 \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"message": 400">class="text-emerald-400">"Payment method deleted"
}

Swarm Compute

Get swarm compute billing totals for a workspace.

GET/api/v2/billing/swarm-computeAuthenticated

Get swarm compute billing totals for a workspace over a date range. Defaults to the current calendar month.

Query Parameters

workspace_idstringrequired

UUID of the workspace.

startstring

Start date (ISO 8601). Defaults to first of current month.

endstring

End date (ISO 8601). Defaults to now.

Request

cURL
400">curl -X 400">GET 400">class="text-emerald-400">"https:400">class="text-zinc-500">//api.lvng.ai/api/v2/billing/swarm-compute?workspace_id=ws_abc123&start=2026-03-01&end=2026-04-01" \
  -H 400">class="text-emerald-400">"Authorization: Bearer YOUR_API_KEY"

Response 200

{
  400">class="text-emerald-400">"success": true,
  400">class="text-emerald-400">"total_compute_credits": 1250,
  400">class="text-emerald-400">"total_tasks": 48,
  400">class="text-emerald-400">"by_agent": [
    { 400">class="text-emerald-400">"agent_id": 400">class="text-emerald-400">"agt_001", 400">class="text-emerald-400">"agent_name": 400">class="text-emerald-400">"Research Agent", 400">class="text-emerald-400">"credits": 800, 400">class="text-emerald-400">"tasks": 30 },
    { 400">class="text-emerald-400">"agent_id": 400">class="text-emerald-400">"agt_002", 400">class="text-emerald-400">"agent_name": 400">class="text-emerald-400">"Data Processor", 400">class="text-emerald-400">"credits": 450, 400">class="text-emerald-400">"tasks": 18 }
  ]
}