Mastra opens production metrics as a query API: cost, latency and error rates by model and thread
Synopsis
Mastra has released a Metrics API that lets developers query token usage, model cost, latency and error rates for production projects through the client SDK, CLI or observability endpoints. Previously these metrics were only viewable in the Mastra platform and Studio, with no way to construct custom queries. Queries can now combine time ranges, status filters and grouping to produce totals, breakdowns, time series and percentile data for custom reports, dashboards, downstream delivery and alerts when cost or error rates rise.
Interpretation
Model cost, latency and error rates in production can now be queried around your own question instead of only through preset platform views. Previously these metrics could only be viewed in the Mastra platform and Studio, and users could not construct their own queries. Results cover totals, breakdowns, time series and percentiles, and can be combined with time ranges and status filters.
Queries work on an aggregate view: traces record what happened in a single run, while metrics aggregate across every run. This makes it possible to see which model, conversation or tool call costs the most, runs the slowest or fails most often. Example queries include cost by token type, conversations ranked by cost via threadId, grouping by model or by agent and workflow, daily usage, p50 and p95 run durations, and failed runs filtered by status label.
Access uses a request carrying a platform access token and project ID, with the observability base URL chosen by the project's region. The US region uses observability.mastra.ai and the EU region uses observability.eu.mastra.ai. The client SDK, CLI and observability endpoints run the same kinds of queries and all return JSON; the timestamp filter is optional, and omitting start and end returns all available data.
Perspective
This report is for developers and operators of production projects on the Mastra platform; the queryable objects are token usage, model cost, latency and error rates, accessed through the client SDK, CLI and observability endpoints, returning JSON. The material does not state whether the API applies to self-hosted or non-Mastra deployments.
The material states that the timestamp filter is optional and that omitting start and end returns all available data, so the query scope is left to the caller. It does not give a retention period or sampling scheme for the metric data.
