Skip to main content

API

The Token Usage Dashboard interface fetches all its data through a JSON API. You can query it yourself too, for example with curl, as long as the server is running. For example, this is how you query the metrics for September 2026:

curl "http://127.0.0.1:8000/api/metrics?from=2026-09-01&to=2026-09-30"

JSON API endpoints​

The following table lists the endpoints of the Token Usage Dashboard JSON API with their contents and supported parameters:

EndpointContentsreloadfrom/tomodels
GET /api/dataraw data, file list, models, months, period, check result, runtimeyes––
GET /api/metricsall metrics of the overviewyesyesyes
GET /api/healthonly the check result with the export statusyes––
GET /api/projectsmetrics per projectyesyesyes
GET /api/sessionsmetrics per session, sorted and pagedyesyesyes
GET /api/blocksmetrics of the 5-hour blocksyesyes–
GET /api/rtkmetrics of the RTK savingsyesyes–
GET /LICENSElicense text of the AGPL-3.0–––

JSON API parameters​

The Token Usage Dashboard JSON API accepts these general parameters:

  • reload=1 reads all files again, like the Reload data button.
  • from and to limit the period, as a date YYYY-MM-DD.
  • models selects models. The parameter may occur several times and hold lists: ?models=a,b&models=c.

/api/blocks and /api/rtk ignore models. The block source reports no per-model cost split, and the RTK source knows nothing about models. Both responses therefore carry modelFilterSupported: false.

Extra parameters for /api/sessions​

The following table lists the extra parameters of the /api/sessions endpoint with their values and defaults:

ParameterValuesDefault
projectexact project key, empty means allempty
sortstart, duration, project, cost, tokenscost
dirasc, descdesc
pagepositive integer1

A page holds 50 sessions. A page beyond the last is clamped to the last one; the actual number is in page.number. An unknown project is not an error but a valid filter without matches.

JSON API responses and errors​

All responses of the Token Usage Dashboard JSON API are JSON with Cache-Control: no-store. Timestamps appear as ISO-8601 in UTC; only the interface converts them to local time.

Messages and errors never come as a finished sentence, but as a key with parameters, for example:

{ "code": "http.param_invalid", "params": { "name": "sort", "value": "price" } }

The server knows no language; only the browser builds the text in the selected language.

The following table lists the error keys of the JSON API and their meaning:

KeyMeaning
http.path_unknownunknown path
http.param_invalidinvalid value for sort, dir or page (HTTP 400)
http.file_missingfile missing
http.data_directoryproblem with the data directory
http.internal_errorinternal error

HEAD is treated like GET.