Skip to content

Billing

Billing guides connect logged usage to billing cycles, line-item previews, invoices, billing documents, and ledger operations.

Example: List Customer Billing Cycles

curl "$SPENDWARE_BASE_URL/api/v1/customers/CUSTOMER_ID/billing/cycles?token_unit_size=million&request_unit_size=thousand" \
  -H "Authorization: Bearer $SPENDWARE_API_KEY"
cycles = client.billing.list_customer_cycles(
    "CUSTOMER_ID",
    token_unit_size="million",
    request_unit_size="thousand",
)
const cycles = await client.billing.listCustomerCycles("CUSTOMER_ID", {
  tokenUnitSize: "million",
  requestUnitSize: "thousand",
});

Example: Preview Project Line Items

curl "$SPENDWARE_BASE_URL/api/v1/billing-preview/projects/PROJECT_ID/line-items" \
  -H "Authorization: Bearer $SPENDWARE_API_KEY"
preview = client.billing.preview_project_line_items("PROJECT_ID")
const preview = await client.billing.previewProjectLineItems("PROJECT_ID");

Notes

  • Billing math uses raw token and request counts.
  • Presentation unit options affect read responses only.
  • Customer credits are granted and consumed independently of billing. A customer_credit_consumption template rule creates a negative line from actual credit consumed in the invoice period, after ordinary charges and capped at the pre-credit subtotal. It cannot be configured with a fixed amount or rate.
  • Use idempotency keys for invoice generation and other side-effecting billing workflows where the API supports them.