Usage API
Read your organization's requests, tokens and spend from code, grouped by model, project, key, tier, region or day.
What it returns#
GET /v1/usage returns your organization's aggregated requests, tokens and spend for a time range: one row per group in data, and the sums in totals. Amounts are what was billed, in integer nano-USD (cost_nano_usd) and formatted in USD (cost_usd).
| Field | Always present | Type | Notes |
|---|---|---|---|
| requests | Yes | integer | |
| input_tokens | Yes | integer | |
| cached_input_tokens | Yes | integer | |
| output_tokens | Yes | integer | Includes reasoning tokens. |
| reasoning_tokens | No | integer | |
| images | No | integer | |
| audio_seconds | No | integer | |
| cost_nano_usd | Yes | integer | Amount billed, in nano-USD. |
| cost_usd | Yes | string | The same amount formatted in USD. |
{
"from": 1790000000,
"to": 1792592000,
"group_by": "model",
"data": [
{
"model": "z-ai/glm-5.3",
"requests": 1200,
"input_tokens": 1800000,
"cached_input_tokens": 0,
"output_tokens": 600000,
"reasoning_tokens": 0,
"cost_nano_usd": 12480000000,
"cost_usd": "12.48"
}
],
"totals": {
"requests": 1200,
"input_tokens": 1800000,
"cached_input_tokens": 0,
"output_tokens": 600000,
"reasoning_tokens": 0,
"cost_nano_usd": 12480000000,
"cost_usd": "12.48"
},
"next_cursor": null
}output_tokens includes reasoning tokens. Where an upstream shares its prompt cache across its customers, cached input is billed and reported as ordinary input, and cached_input_tokens stays 0 for those requests (Prompt caching).
Choose a time range#
from (inclusive) and to (exclusive) are Unix seconds. to defaults to now, and one range spans at most 366 days.
| Parameter | Required | Values | Limits | Notes |
|---|---|---|---|---|
| from | Yes | integer | Start of the range, inclusive, Unix seconds. | |
| to | No | integer | End of the range, exclusive, Unix seconds. Defaults to now. The range may span at most 366 days. | |
| project | No | string | pattern ^prj_[0-9A-Za-z]+$ | Restrict to one project (`prj_…`). |
| model | No | string | Restrict to one canonical model id. | |
| group_by | No | model, project, key, tier, region, day | Dimension to group rows by. Without it the response has one row for the whole range. | |
| limit | No | integer | min 1; max 200 | Page size. |
| cursor | No | string | Opaque cursor from a previous response's `next_cursor`. |
Group and filter#
group_by takes one dimension: model, project, key, tier, region or day (a UTC day). Each row then names its group in the matching field. Without group_by the response has one row for the whole range. project and model restrict the rows to one project or one canonical model id.
curl "https://api.panward.ai/v1/usage?from=1790000000&to=1792592000&group_by=model" \ -H "Authorization: Bearer $PANWARD_API_KEY"
Pagination#
Lists in the API use cursor pagination. limit sets the page size (default 50, at most 200). Pass the response's next_cursor as cursor to get the next page; it is null on the last page.
import os import time import requests headers = {"Authorization": f"Bearer {os.environ['PANWARD_API_KEY']}"} end = int(time.time()) start = end - 7 * 86400 rows = [] cursor = None while True: response = requests.get( "https://api.panward.ai/v1/usage", headers=headers, params={"from": start, "to": end, "group_by": "day", "project": "prj_01JB2K9P6W", "limit": 200, "cursor": cursor}, ) response.raise_for_status() report = response.json() rows.extend(report["data"]) cursor = report["next_cursor"] if cursor is None: break for row in rows: print(row["day"], row["requests"], row["cost_usd"])
type Report = { data: Array<Record<string, unknown>>; next_cursor: string | null }; const headers = { Authorization: `Bearer ${process.env.PANWARD_API_KEY}` }; const end = Math.floor(Date.now() / 1000); const start = end - 7 * 86400; const rows: Report["data"] = []; let cursor: string | null = null; do { const query = new URLSearchParams({ from: String(start), to: String(end), group_by: "day", project: "prj_01JB2K9P6W", limit: "200" }); if (cursor) query.set("cursor", cursor); const response = await fetch(`https://api.panward.ai/v1/usage?${query}`, { headers }); if (!response.ok) throw new Error(`usage: ${response.status}`); const report = (await response.json()) as Report; rows.push(...report.data); cursor = report.next_cursor; } while (cursor); for (const row of rows) console.log(row.day, row.requests, row.cost_usd);
END=$(date +%s) START=$((END - 7 * 86400)) curl "https://api.panward.ai/v1/usage?from=$START&to=$END&group_by=day&project=prj_01JB2K9P6W&limit=200" \ -H "Authorization: Bearer $PANWARD_API_KEY" -o page.json # While next_cursor is not null, ask again with &cursor=<next_cursor>. jq -r .next_cursor page.json
Freshness#
Figures come from hourly rollups and appear within a few minutes of the request.
Scope of a key#
The call needs a key with the usage.read scope and returns the figures of the key's organization. A key with only usage.read cannot call models: an inference request with it is refused with 403 permission_denied. Give reporting jobs a key of their own with this scope (Scopes).
Reconcile with statements and receipts#
Usage totals equal the lines of the monthly statement under Billing. Receipts carry the token counts of each request and no prices, so a sum over receipts reconciles tokens, not money (How a request is priced).
Exports in the console#
For larger ranges, the console's Usage screen exports a CSV file in the background, one row per interval and group, from the same rollups. It holds no request-level rows.