Skip to content

Billing Rail

Usage metering and invoicing endpoints.

Overview

The Billing rail provides:

  • Usage metering
  • Invoice generation
  • Payment processing
  • Subscription management

Integrated with Stripe for payment processing.

Endpoints

Record Usage

http
POST /v1/billing/usage
typescript
const usage = await iof.billing.recordUsage({
  workspaceId: "ws_123",
  metric: "api_calls",
  quantity: 1000,
  timestamp: new Date(),
});

Get Usage

http
GET /v1/billing/usage
typescript
const usage = await iof.billing.getUsage({
  workspaceId: "ws_123",
  metric: "api_calls",
  startDate: "2024-01-01",
  endDate: "2024-01-31",
});

Response:

json
{
  "metric": "api_calls",
  "total": 45000,
  "breakdown": [
    { "date": "2024-01-15", "quantity": 1500 },
    { "date": "2024-01-16", "quantity": 2000 }
  ]
}

Create Invoice

http
POST /v1/billing/invoices
typescript
const invoice = await iof.billing.createInvoice({
  workspaceId: "ws_123",
  period: {
    start: "2024-01-01",
    end: "2024-01-31",
  },
});

Response:

json
{
  "id": "inv_abc",
  "workspaceId": "ws_123",
  "status": "draft",
  "subtotal": 500,
  "tax": 50,
  "total": 550,
  "lineItems": [
    { "description": "API Calls (45,000)", "amount": 450 },
    { "description": "Contracts (100)", "amount": 50 }
  ]
}

Get Invoice

http
GET /v1/billing/invoices/:id
typescript
const invoice = await iof.billing.getInvoice("inv_abc");

Pay Invoice

http
POST /v1/billing/invoices/:id/pay
typescript
const payment = await iof.billing.payInvoice("inv_abc", {
  paymentMethod: "pm_card_123",
});

Metrics

MetricDescriptionUnit
api_callsAPI requestsCount
contractsContracts createdCount
kyc_checksKYC verificationsCount
storageData storageGB

Invoice Status

StatusDescription
draftNot yet sent
openAwaiting payment
paidSuccessfully paid
voidCancelled
overduePast due date

Webhooks

EventDescription
billing.usage.recordedUsage recorded
billing.invoice.createdInvoice created
billing.invoice.paidInvoice paid
billing.invoice.overdueInvoice overdue

Next Steps

Licensed under the Apache License 2.0