Usage
Retrieve aggregate spend, request, and token usage for the authenticated API key
Documentation Index
Fetch the complete documentation index at: https://docs.nano-gpt.com/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Usage API returns bounded aggregate usage for the API key used to authenticate the request. Use it to answer:- What did this API key spend?
- Which models was that spend on?
- How many requests and tokens were used?
- What happened over a specific UTC date range?
Base URL
Authentication
Use the same NanoGPT API key authentication as other API routes:Default Request
If no date range is provided, the endpoint returns the authenticated API key’s last 30 UTC days, grouped by both day and model.Date Ranges
Usefrom and to to request an explicit UTC date range. Both values must be YYYY-MM-DD dates. to is inclusive.
fromandtomust be provided together.tomust be on or afterfrom.tocannot be in the future.- Ranges are capped at 366 days.
- All dates are interpreted in UTC.
Grouping
Usegroup_by to control which aggregate arrays are returned.
| Value | Returned arrays |
|---|---|
day | byDay |
model | byModel |
day,model | byDay, byModel, byDayModel |
day,model is the default. model,day is accepted as an alias for day,model.
Example:
Scope
The endpoint is scoped to the authenticated API key.| Parameter | Default | Notes |
|---|---|---|
scope | current_key | current_key and api_key both return the authenticated API key’s usage. |
api_key_id | current key | Optional current API key ID. Requests for another API key are rejected. |
Response Shape
Field Reference
Top-level fields:| Field | Description |
|---|---|
object | Always usage. |
scope | Echoes the requested scope, either current_key or api_key. |
apiKey.id | Numeric ID of the authenticated API key. |
from | UTC start date. |
to | UTC end date, inclusive. |
timezone | Always UTC. |
groupBy | The effective grouping mode. |
asOf | Timestamp when the aggregate response was generated. Cached responses can be up to 60 seconds old. |
source.rollupDays | Days served from precomputed daily rollups. |
source.liveDays | Days served from live aggregation. Usually today or days not rolled up yet. |
source.missingRollupDays | Closed UTC days that were not available in the rollup table and had to be served live. |
| Field | Description |
|---|---|
requests | Number of billable usage requests in the aggregate bucket. |
costUsd | Gross USD usage cost before refunds. |
refundedUsd | USD amount refunded in the aggregate bucket. |
netCostUsd | max(0, costUsd - refundedUsd) for that aggregate bucket. |
inputTokens | Input tokens counted for the bucket. |
outputTokens | Output tokens counted for the bucket. |
reasoningTokens | Reasoning tokens counted separately when available. |
totalTokens | inputTokens + outputTokens. Reasoning tokens are reported separately and are not added to totalTokens. |
modelvalues are public model labels.- Internal routing providers are not exposed.
- Variants that share the same public label may be combined under that label.
Refund Notes
Refunds are applied at each returned aggregation level with:byModel or byDayModel rows may differ slightly from totals.netCostUsd when refunds cross buckets.
Errors
Errors use the standard NanoGPT API error shape:| Status | Type | Meaning |
|---|---|---|
400 | invalid_request_error | Invalid date range, unsupported parameter, invalid grouping, or request for a different API key. |
401 | missing_api_key / invalid_api_key | Missing or invalid API key. |
429 | rate_limit_exceeded | Too many usage requests. |
503 | usage_not_ready | The requested range needs rollup data that is not ready yet. Try a shorter range or retry after rollup sync completes. |
503 | service_unavailable | Usage API temporarily unavailable. |
500 | server_error | Unexpected usage retrieval failure. |
Legacy Parameter Behavior
The usage endpoint is aggregate-first and rejects legacy row-history parameters. Rejected legacy parameters include:durationpagepageSizesortdirfilterweekOffsettzinclude_summary
from and to dates instead.Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Query Parameters
UTC start date in YYYY-MM-DD format. Must be provided together with to.
"2026-05-01"
UTC end date in YYYY-MM-DD format, inclusive. Must be on or after from and cannot be in the future.
"2026-05-31"
Controls which aggregate arrays are returned. model,day is accepted as an alias for day,model.
day, model, day,model, model,day "day,model"
Usage scope. current_key and api_key both return usage for the authenticated API key.
current_key, api_key Optional current API key ID. Requests for another API key are rejected.
123
Response
Aggregate usage for the authenticated API key
Always usage.
usage Echoes the requested usage scope.
current_key, api_key UTC start date.
"2026-05-01"
UTC end date, inclusive.
"2026-05-31"
Always UTC.
UTC The effective grouping mode.
day, model, day,model "day,model"
Timestamp when the aggregate response was generated. Cached responses can be up to 60 seconds old.
"2026-05-31T12:00:00.000Z"
Returned when grouped by day.
Returned when grouped by model.
Returned when grouped by both day and model.