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.
Test usage logging (deprecated)
Cost dashboard
Query parameters
Response
Response fields
Errors
Dashboard stats
Response
Response fields
Plan-based agent limits
Theagents.limit value is determined by the user’s subscription plan:
Error handling
On failure, the endpoint returns a fallback response with zeroed-out values instead of an error status code: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 intended to be stored as a row in theusage_logs table (Prisma model name: UsageLog). Events will be 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.
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:
The cost dashboard now sources plan subscription costs from the database and AI token usage from the backend metrics service. If the backend is unavailable, plan-based cost data is still returned.
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.