Meter AI consumption, balances, and customer invoices
Read real-time balances, windowed token/tool usage, double-entry ledger rows, and customer invoices via /v1/billing/*.
Meter every token, decision, and GPU-second from the same authoritative ledger the gateway debits. Build accurate usage dashboards, overage alerts, and automated customer invoicing.
Architecture & contract
Tenant scope derives server-side from the verified credential so one org can never read another org's financial data. Window /v1/billing/usage with ISO start and end parameters to reconcile monthly invoices against GET /v1/billing/ledger.
Primary endpoint: GET /v1/billing/usage ยท Status: shipped ยท Level: practitioner
Run it across all four surfaces
CLI
SDK
HTTP
MCP
hanzo billing balance
hanzo billing ledger
hanzo billing invoices listTypeScript
Python
import { Configuration, BillingApi } from 'hanzoai';
const billing = new BillingApi(new Configuration({ accessToken: process.env.HANZO_API_KEY }));
const [bal, usage, ledger] = await Promise.all([
billing.getBillingBalance(),
billing.getBillingUsage(),
billing.getBillingLedger(),
]);
console.log({ balance: bal.data, usage: usage.data, ledger: ledger.data });import os
from hanzoai.cloud import ApiClient, Configuration
from hanzoai.cloud.api import BillingApi
api = BillingApi(ApiClient(Configuration(access_token=os.environ["HANZO_API_KEY"])))
print(api.get_billing_balance())
print(api.get_billing_usage())
print(api.get_billing_ledger())curl -s https://api.hanzo.ai/v1/billing/balance \
-H "Authorization: Bearer $HANZO_API_KEY" | jq '.'
curl -s https://api.hanzo.ai/v1/billing/usage \
-H "Authorization: Bearer $HANZO_API_KEY" | jq '.'
curl -s https://api.hanzo.ai/v1/billing/invoices \
-H "Authorization: Bearer $HANZO_API_KEY" | jq '.'curl -s -X POST https://api.hanzo.ai/v1/mcp \
-H "Authorization: Bearer $HANZO_API_KEY" -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "billing",
"arguments": {"op": "get_billing_balance", "input": {}}
}
}'Verify the outcome
- Reconcile total debits in
GET /v1/billing/ledgeragainstGET /v1/billing/balance.
Production guardrails
- Handle HTTP
402 insufficient_balancegracefully in customer apps with a direct top-up flow.
Next steps & Hanzo University
Was this page useful?
Broken link or missing step? Drop it in #docs on Discord or open a PR.PreviousIsolate customer orgs, Base stores, and entitlementsNextPublish and monetize agents & tools on Marketplace
Last updated Nov 25, 2026