Skip to main content

Overview

The Token Usage API returns raw LLM token counts aggregated by time bucket, organization, member, and model. Use it to reconcile usage against your own model provider (AWS Bedrock, Anthropic, etc.), build cost dashboards, or audit inference by user and model. This API reports tokens, not ACUs. For ACU-based billing data, use the Usage API (GET /v1/billing/usage). Availability: BYOK deployments only. Deployments that use the TextQL-managed model provider cannot access this API. Base URL: https://app.textql.com/v1/billing Endpoint: GET /v1/billing/token-usage

Authentication

Same as the Usage API. All requests require an API key with billing:read permission. Create keys in Settings → Developers → API Keys. The token is Base64-encoded {member_id}:{api_token}. Pass it in one of two ways:
The API key’s organization determines tenant scope: results include all organizations in that tenant (unless filtered by organization).

Your First Request

Fetch the last 90 days of token usage for your tenant:
Example response:
Each record is one (time bucket × organization × member × model) slice. Token fields are summed across all LLM requests in that slice.

Query Parameters

All parameters are optional query parameters on GET /token-usage. Unrecognized query parameters are rejected with 400 invalid_parameter — in particular, the response fields start_datetime / end_datetime are not valid request filters; use start_date / end_date.

Date range

Timezones are expressed through the RFC 3339 UTC offset (e.g. 2026-07-04T20:00:00-04:00). The offset of start_date (or of end_date when start_date is omitted) also controls:
  • Alignment of day and month buckets (days start at local midnight for that offset)
  • The offset used to render start_datetime / end_datetime in the response
Constraints:
  • start_date must be before end_date.
  • The window end_date − start_date cannot exceed 90 days.
  • Remember to URL-encode + in positive offsets as %2B (e.g. 2026-07-01T00:00:00%2B05:30).

Granularity

Controls time bucket size. Default: day.

Filtering

By organization — comma-separated organization names (not UUIDs). Omit to include all organizations in the tenant.
Unknown organization names return 400 invalid_parameter. By user email — comma-separated, case-insensitive. Only members whose email matches (in the selected orgs) are included. If no members match, the response is an empty data array with 200 OK.
By model — comma-separated model names as stored in usage records (e.g. claude-sonnet-4-6, gpt-4o). Exact match.
Filters can be combined:

Sorting

Use sort to order results before pagination. Prefix with - for descending. Default: -start_datetime (newest buckets first). Tie-break order (when primary sort values match): email → model → start_datetime → organization → total_tokens.

Pagination

Use pagination.total_count to compute total pages. Requesting a page beyond the last page returns an empty data array with the requested page and correct total_count.

Response Fields

Top level

Record object (data[])

total_tokens calculation:

Member Attribution

Usage is attributed to a member when member_id is present on the underlying usage event and the member’s email is not a TextQL staff domain. Non-attributed usage (empty email):
  • Usage with no member attribution
  • Usage from @textql.com or *.textql.com email addresses (TextQL staff)
Non-attributed rows are still returned with "email": "". Clients may display these as “(non-attributed)” in UI.

BYOK Requirement

This API is only available when your deployment uses your own model provider (BYOK — bring your own keys). Error when not BYOK:

Comparison with Usage API

Shared behavior: auth, tenant scoping, organization / email filters, date range defaults, 90-day max window, granularity, pagination.

Code Examples

Python — paginate all token usage for January

JavaScript — top models by token volume (last 90 days)


Error Reference

Errors use the same envelope as the Usage API:
Note: Authentication failures return 403 (not 401) with code: "forbidden".

Troubleshooting & Support

If you’re still running into issues, contact support at support@textql.com and include the full request URL and response body.