Skip to main content

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)

This endpoint was removed in the March 2026 security audit and is no longer available. Requests to this path return 404. Use the cost dashboard endpoint to verify that usage tracking is working.
A debug endpoint that fires a single test event through the usage logging pipeline.

Cost dashboard

Requires session authentication. Returns aggregated cost, token, and call data for the cost dashboard. Breaks down spending by agent, model, and day. Plan subscription costs are sourced from the database. AI token usage is fetched from the backend metrics service when available.

Query parameters

Response

Response fields

Errors


Dashboard stats

Requires session authentication. Returns aggregated agent, skill, and task counts for the authenticated user. Used by the dashboard overview to display real-time stats cards.

Response

Response fields

Plan-based agent limits

The agents.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.
All query endpoints below require bearer token authentication and are served by the backend API.

Usage summary

Returns daily aggregated token usage and cost data across all agents and models.

Query parameters

Response

Response fields

Usage by agent

Returns token usage grouped by model for a specific agent.

Path parameters

Query parameters

Response

Response fields

Usage by model

Returns token usage aggregated by model across all agents.

Query parameters

Response

Response fields

Daily totals

Returns total token usage and cost per day.

Query parameters

Response

Response fields

Tool stats

Returns aggregated tool execution statistics, optionally filtered by agent.

Query parameters

Response

Response fields

Usage event schema

Each usage event is intended to be stored as a row in the usage_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.
The UsageLog Prisma model is not yet in the schema. The usage_logs table was originally created via a dedicated SQL migration (20260323000000_add_usage_logs), but the Prisma model was removed from the build due to build failures. Usage event recording is currently inactive. The schema below documents the intended table structure for when the model is re-added.

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:
For example:
If the database write fails, an error is logged instead:
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:
For example:
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.
If the entire handler fails, a general error is logged and a 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.).
The table is indexed on user_id, agent_id, created_at, and the composite pairs (user_id, created_at) and (agent_id, created_at) for efficient time-range queries.
The usage event schema was updated in the March 2026 release. The previous fields session_id, session_key, cache_read_tokens, cache_write_tokens, and total_tokens are no longer recorded. Use input_tokens + output_tokens to calculate total tokens.

Tool event schema

Each tool event records:

Errors

All usage tracking endpoints return the following error codes: