Page - LLM Usage

abstract

Token consumption and cost dashboard — summary KPIs, time-series chart, per-model breakdown table, provider share donut, and pricing reference. Period selector from 1 day to all-time.

Route

PropertyValue
Path/llm-usage
Filefrontend/src/app/llm-usage/page.tsx
Auth RequiredNo
LayoutRoot layout with sidebar
Dynamic SegmentNone

Component Tree

LLMUsagePage (page.tsx)
├── AppHeader (title="LLM Usage")
├── Period selector (Today / 7d / 30d / 3m / 6m / 1y / All)
├── Granularity toggle (daily | hourly)
├── LLMUsageSummaryCards (total tokens, total cost, call count, top model)
├── LLMUsageTimeseriesChart (daily/hourly cost + token bars)
├── LLMUsageModelTable (per-model breakdown: calls, tokens, cost, share%)
├── LLMProviderShareChart (donut: cost by provider)
└── LLMPricingReference (pricing table for all models)

Data Layer

Server State — Promise.all on mount + period change

State VarAPI CallEndpoint
summaryllmUsageApi.getSummary(days)GET /api/v1/llm-usage/summary
timeseriesllmUsageApi.getTimeseries(days, granularity)GET /api/v1/llm-usage/timeseries
modelUsagellmUsageApi.getByModel(days)GET /api/v1/llm-usage/by-model
pricingllmUsageApi.getPricing()GET /api/v1/llm-usage/pricing

pricing is fetched once on mount (doesn't change with period). Others re-fetch when period or granularity changes.

Local State

VariableTypeInitialDescription
periodPeriod"month"Selected time period
granularityGranularity"daily"Chart resolution
loadingbooleantrueLoading state
errorstring | nullnullError message

Period & Days Mapping

type Period = "day" | "week" | "month" | "3-month" | "6-month" | "year" | "all";
 
const PERIOD_DAYS: Record<Period, number> = {
  day: 1, week: 7, month: 30,
  "3-month": 90, "6-month": 180, year: 365, all: 3650,
};

Validation & Conditions

Render Conditions

ConditionWhat Shows
loadingSkeleton
error !== nullAlert with error description + ExternalLink to provider docs
modelUsage.length === 0Empty state in model table
granularity === "hourly"More granular chart; only useful for period="day" or "week"
RoleLink
Backend APIAPI-LLM-Usage
DB SchemaDB - llm_calls