Usage and the request log
Read every request the gateway served, and total usage by day per customer, member, model, key or tag.
Every request the gateway serves is recorded: who it was for, which model answered, its tokens, what it cost and what it was billed, and how it ended. Read the records one by one from the request log, or totals by day from the summary. Requests refused before a provider was called (a bad key, no credit, a limit) are not recorded; webhooks tell you about those that matter.
Records appear a few seconds after the response ends: the gateway hands them to a queue so the request itself never waits on the database.
List requests#
curl "https://api.hixel.dev/v1/usage?customer=org_42&from=2026-11-01T00:00:00Z&limit=50" \
-H "Authorization: Bearer $HIXEL_API_KEY"for await (const record of hixel.usage.list({
customer: "org_42",
from: "2026-11-01T00:00:00Z",
limit: 50,
})) {
console.log(record.request_id, record.model, record.billed_micros);
}Newest first, paginated with cursor and limit (1 to 100). Every
filter is an exact match:
| Query parameter | Keeps requests |
|---|---|
customer | of this customer (your id) |
member | of this member |
model | answered by this model (catalog name) |
key_id | made with this key (key_…) |
tag | carrying this tag |
payer | paid by wallet, tenant (your organization's account) or byok (the customer's own key) |
outcome | that ended completed, aborted, upstream_error, truncated or stream_error |
endpoint | for chat or an endpoint beside chat (embeddings, image_generations, …) |
request_id | with this request id, the x-hixel-request-id the gateway answered |
session_id | of this realtime session |
from, to | that started at or after from and before to (ISO 8601 timestamps) |
GET /v1/usage/{id} reads one record by its id (use_…).
Find a request by its request id#
Every gateway response carries x-hixel-request-id. Log it with your own request, and you can
later find exactly that request's record, its tokens, cost and how it ended:
curl "https://api.hixel.dev/v1/usage?request_id=req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a" \
-H "Authorization: Bearer $HIXEL_API_KEY"const page = await hixel.usage.list({ request_id: "req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a" });
const record = page.data[0]; // undefined until the request is recorded, a few seconds after it ends
console.log(record?.outcome, record?.billed_micros);A record#
{
"id": "use_…",
"request_id": "req_6f1c0e9a2b7d4c3e8a5f0b1d2c3e4f5a",
"key_id": "key_…",
"key_tags": ["backend"],
"customer": "org_42",
"member": "user_7",
"provider": "anthropic",
"api_shape": "openai_chat_completions",
"endpoint": null,
"requested_model": "claude-sonnet",
"model": "claude-sonnet-5-5",
"upstream_model": "claude-sonnet-5-5",
"payer": "wallet",
"attempts": 1,
"stream": true,
"tokens": {
"input": "1200",
"cache_read": "3400",
"cache_write_5m": "0",
"cache_write_1h": "0",
"output": "450",
"reasoning": "0"
},
"usage_completeness": "complete",
"cost_micros": "7240",
"billed_micros": "8688",
"upstream_status": 200,
"outcome": "completed",
"mocked": false,
"cache": null,
"tags": ["feature:summarise"],
"client_token_id": null,
"settlement": { "status": "settled", "basis": "usage", "reason": null },
"started_at": "2026-11-25T10:00:00.000Z",
"duration_ms": 2140,
…
}- Tokens are in disjoint buckets: fresh
input,cache_read, cache writes kept for 5 minutes and for an hour, andoutput.reasoningis part ofoutput, shown apart. cost_microsis what the request cost at the provider's price;billed_microswhat the payer was charged: the cost plus your markup forwalletandtenant,"0"forbyok. Both arenullfor a model without a price.requested_modelis the name the request sent (an alias, perhaps);modelthe catalog model that answered.usage_completenesssays whether the provider reported all of the usage (complete) or not (partial,missing,truncated). When it did not, the request is charged at the larger of what was seen and the estimate reserved before the call, sobilled_microscan be above the price of the tokens shown;usage_cost_microsandusage_billed_microshold the price of the tokens seen.settlement.statussays how the wallet or limits took the request's end;untrackedwhen neither a wallet nor a limit applied.endpointandendpoint_usageare set for an endpoint beside chat, with its media tokens and units (images, audio milliseconds, characters, search units).
Totals by day, and analytics#
The charts of the dashboard's usage pages are API reads too, and the simplest of them is daily
totals: GET /v1/usage/series with bucket=day, grouped by customer, member, model, key, tag,
provider, payer or outcome.
curl "https://api.hixel.dev/v1/usage/series?from=2026-11-01T00:00:00Z&to=2026-12-01T00:00:00Z&bucket=day&group_by=customer" \
-H "Authorization: Bearer $HIXEL_API_KEY"const daily = await hixel.usage.series({
from: "2026-11-01T00:00:00Z",
to: "2026-12-01T00:00:00Z",
bucket: "day",
group_by: "customer",
});
for (const row of daily.series) console.log(row.bucket, row.group, row.billed_micros);{
"from": "2026-11-01T00:00:00.000Z",
"to": "2026-12-01T00:00:00.000Z",
"bucket": "day",
"buckets": ["2026-11-01T00:00:00.000Z", "2026-11-02T00:00:00.000Z", …],
"group_by": "customer",
"series": [
{
"bucket": "2026-11-24T00:00:00.000Z",
"group": "org_42",
"requests": "312",
"tokens": { "input": "…", "cache_read": "…", "cache_write_5m": "…", "cache_write_1h": "…", "output": "…", "reasoning": "…" },
"cost_micros": "1840000",
"billed_micros": "2208000"
}
],
"others": [],
"omitted_groups": 0
}The analytics envelope#
Every analytics read (/v1/usage/series, totals, performance, errors, guardrails, keys,
and /v1/limit_crossings/summary) answers in the same shape:
from,to: the range,toexclusive. At most 92 days, or 7 withbucket=hour;frommust be beforeto(400invalid_rangeotherwise).bucket(dayorhour, UTC) andbuckets: every bucket of the range, oldest first, with requests or not. A row exists only for a bucket and group with requests, so fill the others with zeros frombuckets.group_byandseries: rows by bucket, then group. Only the largest groups are listed one by one:omitted_groupssays how many were left out, andotherssums them per bucket, so nothing is dropped silently. Where a read ranks groups over the whole range, it answers them ingroups, and the range's sum intotal.
Each takes the same exact filters as the request list (customer, member, model, key_id,
tag, payer, outcome, endpoint). Counts and amounts are strings of integers.
| Call | What it answers |
|---|---|
GET /v1/usage/series | Requests, tokens, cost and billed amounts per bucket and group |
GET /v1/usage/totals | One range's totals; call it again with the previous range to compare |
GET /v1/usage/performance | Latency percentiles (p50, p95, p99), retries, cache hits and streaming, by model or provider |
GET /v1/usage/errors | How requests ended, by bucket and group_by (outcome or status_class, required) |
GET /v1/usage/failures | The kinds of failed request (provider, model, upstream status, outcome), most frequent first |
GET /v1/usage/guardrails | What each guardrail rule flagged, masked or blocked |
GET /v1/usage/keys | When each key was last used, and its requests in the range |
With group_by=tag, a request counts once in each of its tags' groups, so a bucket's groups can
add up to more than its total; requests without tags are in the group null.
Limit crossings#
Requests refused at a spend limit, or because a wallet could not cover them, reach no provider and
have no usage record. They are recorded as limit crossings instead: GET /v1/limit_crossings
lists them newest first (filter by customer, limit_type of spend_limit or
insufficient_credits, and from/to). GET /v1/limit_crossings/summary counts them by
bucket and type, in the analytics envelope, and GET /v1/limit_crossings/customers ranks the
customers refused most over a range. The first crossing in a window also sends a
webhook.
In real time#
To receive each record as it happens, subscribe a webhook endpoint to
usage.recorded, or send them to your observability
tools with trace exports.