Usage tracking API
The usage tracking system records per-event token consumption and tool execution metrics. You can query aggregated data by agent, model, or time period.The usage tracker records events to a PostgreSQL database whenever an AI completion or tool call is made. The endpoints below are read-only query APIs for retrieving aggregated usage data. When no real usage data exists yet, the cost dashboard returns sample data with a
isMockData: true flag.Test usage logging (deprecated)
Cost dashboard
isMockData set to true and a message field explaining that usage tracking is not yet configured.
Query parameters
Response
Response fields
Errors
The remaining endpoints on this page are planned for a future release. They are not yet available. Usage events are recorded internally but these query APIs have not been deployed. This section documents the intended specification for reference.
Usage summary
Query parameters
Response
Response fields
Usage by agent
Path parameters
Query parameters
Response
Response fields
Usage by model
Query parameters
Response
Response fields
Daily totals
Query parameters
Response
Response fields
Tool stats
Query parameters
Response
Response fields
Usage event schema
Each usage event is stored as a row in theusage_logs table (Prisma model name: UsageLog). Events are recorded automatically whenever an AI completion is made (for example, from the demo chat endpoint or agent chat). Cost is calculated at write time using per-model pricing rates.
The
usage_logs table is created via a dedicated SQL migration (20260323000000_add_usage_logs) rather than through Prisma’s schema push. This ensures the table is created reliably across deployments without requiring Prisma to manage the migration state.Server-side logging
Every usage event emits a structured log line to the server console when it is recorded. This makes it possible to verify that the usage tracking pipeline is working without querying the database. Success log format:Because usage recording is fire-and-forget (it never blocks the API response), these log lines are the primary way to diagnose write failures. Monitor your server logs for
[UsageLogger] Failed to log usage entries if usage data appears to be missing from the cost dashboard.Cost dashboard logging
The cost dashboard endpoint emits its own diagnostic log lines prefixed with[Cost API]. These help you verify that the aggregation query is running and returning data.
Query result log:
500 response is returned:
When accessing the table through the Prisma ORM, use the camelCase field names (
userId, agentId, inputTokens, etc.). When writing raw SQL queries, use the snake_case column names shown above (user_id, agent_id, input_tokens, etc.).user_id, agent_id, created_at, and the composite pairs (user_id, created_at) and (agent_id, created_at) for efficient time-range queries.