LLM Usage

Documentation for LLM Usage

Base path: /api/v1/llm-usage

Provides a summary of LLM (Large Language Model) token usage and costs for the active organization.

All endpoints require JWT authentication and an x-active-org header.


Endpoints Overview

MethodPathDescription
GET/api/v1/llm-usage/summaryGet aggregated LLM usage summary

GET /api/v1/llm-usage/summary

Returns aggregated LLM usage statistics for the active organization. Supports date range filtering and various grouping options.

Authentication

Requires JWT (authMiddleware).

Query Parameters

ParameterTypeRequiredDescription
startDatestring (ISO 8601)NoFilter usage from this date (inclusive)
endDatestring (ISO 8601)NoFilter usage until this date (inclusive)
groupBystringNoGroup results by: "model", "source", "user", or "day"

Response 200 OK

Without grouping:

json

With groupBy=model:

json

Response fields:

FieldTypeDescription
totalsobjectAggregated totals across all usage
totals.inputTokensnumberTotal input (prompt) tokens
totals.cachedInputTokensnumberCached input tokens (counted at reduced cost)
totals.outputTokensnumberTotal output (completion) tokens
totals.thinkingTokensnumberThinking/reasoning tokens (for supported models)
totals.costMicrosnumber | nullTotal cost in micro-dollars (1,000,000 = $1.00)
breakdownsarray | nullPer-group breakdown (only when groupBy is specified)

Breakdown item fields:

FieldTypeDescription
groupstringThe group value (model name, source, user ID, or date)
inputTokensnumberInput tokens for this group
cachedInputTokensnumberCached input tokens for this group
outputTokensnumberOutput tokens for this group
thinkingTokensnumberThinking tokens for this group
costMicrosnumber | nullCost in micro-dollars for this group

GroupBy Values

ValueDescription
modelGroup by AI model name (e.g. "GPT-4o", "Claude-3-5-Sonnet")
sourceGroup by usage source (e.g. "chat", "chain:schedule-parser", "rules-chat")
userGroup by user ID
dayGroup by calendar day (ISO 8601 date string)

Example

bash

Cost Calculation Note

Costs are tracked in micro-dollars to avoid floating-point precision issues. To convert to dollars:

javascript

If costMicros is null, cost tracking was not available for those records (e.g., for models where pricing is not configured).

api-docs/llm-usage