Billing
Read your balance, credit grants, receipts and monthly usage statements. Reads only — no money moves through this API.
What your organization has, what it owes, what it bought and what it used. Reads only.
| Endpoint | Scope | Token owner's role |
|---|---|---|
GET /billing/balance | billing:read | Admin |
GET /billing/grants | billing:read | Admin |
GET /billing/receipts | billing:read | Admin |
GET /billing/receipts/{id} | billing:read | Admin |
GET /billing/statements | billing:read | Admin |
GET /billing/statements/{period} | billing:read | Admin |
GET /billing/invoices | billing:read | Admin |
GET /billing/invoices/{id} | billing:read | Admin |
Billing is admin-only: the token owner must currently be an organization
Admin (403 insufficient_scope otherwise). Payments, payment methods,
credit purchases and billing-mode changes are handled in the portal.
Money is integer nano-USD (*_nanousd, 10⁻⁹ USD — exact), with an exact
decimal *_usd string alongside. Receipts and statements are the same
documents the portal's Billing page shows (Top-up invoices and
Usage statements), read from the same record as
Usage.
Python examples share this setup:
import os
import requests
BASE = "https://portal.<domain>/api/v1/mgmt"
s = requests.Session()
s.headers["Authorization"] = f"Bearer {os.environ['TF_PAT']}"Retrieve the balance
GET /api/v1/mgmt/billing/balanceHow the organization pays (mode) and both balances: the prepaid credit
balance, and the invoiced credit line when staff have set one. The block in
force has active: true.
| Field | Type | Notes |
|---|---|---|
mode | string | prepaid, invoiced (billed by invoice against a credit line) or unlimited. |
prepaid | object | The prepaid credit balance (always present). |
prepaid.active | boolean | true when the organization is prepaid. |
prepaid.available_nanousd / available_usd | integer / string | Credit available. |
prepaid.wallet_present | boolean | false when the organization has never been granted credit. |
invoiced | object | null | The invoiced credit line; null when there has never been one. |
invoiced.active | boolean | true when the organization is invoiced. |
invoiced.credit_limit_* | integer / string | The approved credit line. |
invoiced.used_* | integer / string | Usage on the line since it started (prepaid periods excluded). |
invoiced.paid_* | integer / string | Payments received against the line. |
invoiced.outstanding_* | integer / string | used − paid. |
invoiced.remaining_* | integer / string | credit_limit − outstanding, never below 0. Inference is refused at 0. |
available_nanousd, available_usd, currency, wallet_present | The prepaid credit balance again, kept from the first version of this endpoint (available_usd is a number here). |
curl https://portal.<domain>/api/v1/mgmt/billing/balance \
-H "Authorization: Bearer $TF_PAT"{
"mode": "invoiced",
"prepaid": {
"active": false,
"available_nanousd": 0,
"available_usd": "0.00",
"wallet_present": true
},
"invoiced": {
"active": true,
"credit_limit_nanousd": 500000000000,
"credit_limit_usd": "500.00",
"used_nanousd": 100000000000,
"used_usd": "100.00",
"paid_nanousd": 40000000000,
"paid_usd": "40.00",
"outstanding_nanousd": 60000000000,
"outstanding_usd": "60.00",
"remaining_nanousd": 440000000000,
"remaining_usd": "440.00"
},
"available_nanousd": 0,
"available_usd": 0,
"currency": "USD",
"wallet_present": true
}If billing data is temporarily unavailable the call is 502 upstream_unavailable — retry.
List credit grants
GET /api/v1/mgmt/billing/grantsEvery credit movement on the organization — grants, top-ups, refunds — newest first. Paginated.
| Field | Type | Notes |
|---|---|---|
id | string | A stable id for the row (grant_…). |
created_at | string | |
source | string | Where the credit came from, e.g. stripe (a top-up), signup, promo, admin_grant, refund. Treat it as an open set. |
memo | string | Human description. |
amount_nanousd | integer | Negative for refunds and reversals. |
amount_usd | number | The same amount in USD. |
reference | string | null | The payment reference for a top-up, when there is one. |
curl https://portal.<domain>/api/v1/mgmt/billing/grants \
-H "Authorization: Bearer $TF_PAT"{
"data": [
{
"id": "grant_9f2c41d07a5b3e18",
"created_at": "2026-09-01T12:00:00Z",
"source": "stripe",
"memo": "Credit top-up",
"amount_nanousd": 2000000000000,
"amount_usd": 2000,
"reference": "pi_3P…"
}
],
"has_more": false,
"next_cursor": null
}List receipts
GET /api/v1/mgmt/billing/receiptsOne receipt per credit purchase — the portal's Billing → Top-up invoices. Paginated, newest first.
| Field | Type | Notes |
|---|---|---|
id | string | Receipt id. |
number | string | null | The invoice number printed on the PDF. |
stripe_invoice_id | string | The payment provider's invoice id. |
amount_nanousd / amount_usd | integer / string | The amount paid. |
currency | string | |
status | string | e.g. paid. |
created_at | string | |
pdf_available | boolean | false for the short time before the provider finalizes the PDF. |
curl https://portal.<domain>/api/v1/mgmt/billing/receipts \
-H "Authorization: Bearer $TF_PAT"{
"data": [
{
"id": "5b1e2f7a-3c4d-4e5f-8a9b-0c1d2e3f4a5b",
"number": "TF-0042",
"stripe_invoice_id": "in_1Q…",
"amount_nanousd": 10000000000,
"amount_usd": "10.00",
"currency": "USD",
"status": "paid",
"created_at": "2026-11-10T10:00:00Z",
"pdf_available": true
}
],
"has_more": false,
"next_cursor": null
}Retrieve a receipt
GET /api/v1/mgmt/billing/receipts/{id}The receipt plus its document links: pdf_url (the same PDF the portal
opens) and hosted_url (the provider's invoice page). Both are null while
the provider is still finalizing the document — retry a little later. An id
that is not one of your organization's receipts returns 404.
{
"id": "5b1e2f7a-3c4d-4e5f-8a9b-0c1d2e3f4a5b",
"number": "TF-0042",
"amount_nanousd": 10000000000,
"amount_usd": "10.00",
"status": "paid",
"created_at": "2026-11-10T10:00:00Z",
"pdf_available": true,
"pdf_url": "https://pay.stripe.com/invoice/…/pdf",
"hosted_url": "https://invoice.stripe.com/i/…"
}List usage statements
GET /api/v1/mgmt/billing/statements?months=12The current month (status: in_progress, totals null) and the last
months closed calendar months (1–36, default 12), newest first — the
portal's Billing → Usage statements. Not paged: limit and cursor
are 422 unsupported_filter.
| Field | Type | Notes |
|---|---|---|
period | string | YYYY-MM (UTC). |
period_start, period_end | string | Dates; period_end is exclusive. |
status | string | closed or in_progress. |
total_nanousd / total_usd | integer / string | null | The month's usage cost; null while in progress. |
credit_applied_nanousd | integer | null | How much was settled from prepaid credit. |
has_usage | boolean | false for a closed month with no usage (total 0). |
Retrieve a usage statement
GET /api/v1/mgmt/billing/statements/{period}[?format=json|csv|pdf]One closed month. JSON (the default) carries exact amounts: total_*,
credit_applied_nanousd, one line per provider/model/unit/region, a
subtotal per provider, and downloads with the csv and pdf forms — the
same files the portal downloads, fetched with the same token. A month that
has not ended yet is 422 validation_failed (param period).
curl https://portal.<domain>/api/v1/mgmt/billing/statements/2026-10 \
-H "Authorization: Bearer $TF_PAT"
curl -o statement-2026-10.pdf \
"https://portal.<domain>/api/v1/mgmt/billing/statements/2026-10?format=pdf" \
-H "Authorization: Bearer $TF_PAT"{
"period": "2026-10",
"period_start": "2026-10-01T00:00:00Z",
"period_end": "2026-11-01T00:00:00Z",
"generated_at": "2026-11-19T08:00:00Z",
"currency": "USD",
"total_nanousd": 421193004112,
"total_usd": "421.193004112",
"credit_applied_nanousd": 421193004112,
"lines": [
{
"provider": "openai",
"model": "openai/gpt-4o",
"unit": "token",
"region": "eu",
"quantity_in": 81234567,
"quantity_out": 9876543,
"cost_nanousd": 401193004112,
"cost_usd": "401.193004112",
"price_digest": "sha256:…"
}
],
"by_provider": [
{ "provider": "openai", "cost_nanousd": 401193004112, "cost_usd": "401.193004112" }
],
"price_digests": ["sha256:…"],
"downloads": {
"csv": "/api/v1/mgmt/billing/statements/2026-10?format=csv",
"pdf": "/api/v1/mgmt/billing/statements/2026-10?format=pdf"
}
}Reconcile usage with billing
The monthly statement is the document usage reconciles to.
- Read the statement for a closed month:
GET /billing/statements/2026-10→total_nanousd. - Read daily usage for the same month:
GET /usage?group_by=day&from=2026-10-01T00:00:00Z&to=2026-11-01T00:00:00Z. - The sum of the days'
cost_nanousd(andtotals.cost_nanousd) equals the statement'stotal_nanousdexactly. - Credit purchases are the receipts; between them, watch
GET /billing/balancefall as usage accrues.
st = s.get(f"{BASE}/billing/statements/2026-10", timeout=30).json()
usage = s.get(f"{BASE}/usage", params={
"group_by": "day",
"from": "2026-10-01T00:00:00Z",
"to": "2026-11-01T00:00:00Z",
}, timeout=60).json()
days = sum(d["cost_nanousd"] for d in usage["breakdown"])
assert days == st["total_nanousd"], (days, st["total_nanousd"])Both sides are the same record, so this is a check, not a fix-up — if
they disagree, contact support and quote the X-Request-Id of both
responses. Invoiced organizations reconcile the same way, against the
monthly statement.
Legacy subscription invoices
GET /api/v1/mgmt/billing/invoices
GET /api/v1/mgmt/billing/invoices/{id}Subscription invoices from the earlier billing model, kept so existing integrations keep working. New integrations should use receipts and usage statements. Paginated, newest first.
| Field | Type | Notes |
|---|---|---|
id | string | Opaque id. |
stripe_invoice_id | string | The payment provider's invoice id. |
amount_cents | integer | Invoice total in cents of currency. |
currency | string | |
status | string | e.g. open or paid. |
period_start, period_end | string | null | The billed period. |
pdf_url | string | null | The provider-hosted PDF, once issued. |
created_at | string |
Errors specific to billing
| Status | Code | When |
|---|---|---|
| 400 | invalid_request | A malformed period, months or format. |
| 403 | insufficient_scope | Token lacks billing:read, or the owner is not currently an Admin. |
| 404 | not_found | Receipt or invoice absent or in another organization. |
| 404 | feature_disabled | Receipts, statements or invoices are switched off on this deployment. |
| 422 | validation_failed | The statement month has not ended yet. |
| 422 | unsupported_filter | An unsupported query parameter. |
| 502 | upstream_unavailable | Billing data is temporarily unavailable. Retry. |