You can now track latency metrics for every agent and model call in Mastra platform and Studio. Filter and sort traces, spans, and threads by TTFC (time to first chunk) and TTFT (time to first token) to see where your agents are slow. Or hand off to your coding agent to find and fix issues.
We've spent years optimizing websites with metrics like Time to First Byte and First Contentful Paint, and agents deserve the same attention. TTFC tells you how long a user waits before seeing anything. TTFT tells you how long the model takes to start responding. Together, they show you where your agents are slow and give you a meaningful metric to improve.
Previously, you could use durationMs to see how long a run took, but not how long a user waited for the first response, or whether that wait came from the model or your own code. Mastra now records both metrics on every span, from the model call up to the agent run.
Both TTFC and TTFT are available as fields in trace queries and span queries, alongside status, environment, and agent name. Latency metrics work on Mastra platform and on self-hosted Mastra projects where storage.observability uses DuckDB, PostgreSQL, or ClickHouse. If your trace data lives outside of Mastra, you can bring your existing history over with trace imports.
Get started
Latency metrics need a platform access token and your project ID, sent with each request. Use the correct Mastra observability base URL for your project's region:
- US:
https://observability.mastra.ai - EU:
https://observability.eu.mastra.ai
There are four ways to use latency metrics: Mastra CLI, Mastra platform and Studio, Mastra Client SDK, and observability endpoints. The code examples below find runs from the last 7 days where users waited more than 10 seconds for the first chunk, and runs where the model took more than 3 seconds to start responding.
Mastra CLI
Install or upgrade the Mastra CLI globally:
npm install -g mastra@latestmastra@1.30.0 or later, added in PR #23680.Use the mastra api trace query command to query traces. The CLI reads MASTRA_PLATFORM_ACCESS_TOKEN and MASTRA_PROJECT_ID from your environment.
Find runs where users waited more than 10 seconds for the first chunk:
mastra api --url https://observability.mastra.ai trace query '{
"timeRange": { "from": "2026-10-29T00:00:00.000Z", "to": "2026-11-05T00:00:00.000Z" },
"where": { "op": "gt", "left": { "path": "timeToFirstChunkMs" }, "right": { "literal": 10000 } }
}'Find runs where the model took more than 3 seconds to start responding:
mastra api --url https://observability.mastra.ai trace query '{
"timeRange": { "from": "2026-10-29T00:00:00.000Z", "to": "2026-11-05T00:00:00.000Z" },
"where": { "op": "gt", "left": { "path": "timeToFirstTokenMs" }, "right": { "literal": 3000 } }
}'Mastra platform and Studio
On Mastra platform and Studio, the Traces tab lets you filter and sort by time to first chunk and time to first token. On Mastra platform, turn on the Time to first chunk and Time to first token columns in the column settings to see the values.
Mastra Client SDK
npm install @mastra/client-js@latest@mastra/client-js@1.58.0 or later, added in PR #28699.import { MastraClient } from "@mastra/client-js";
export const mastraClient = new MastraClient({
baseUrl: "https://observability.mastra.ai",
headers: {
Authorization: `Bearer ${process.env.MASTRA_PLATFORM_ACCESS_TOKEN}`,
"X-Mastra-Project-Id": process.env.MASTRA_PROJECT_ID!
}
});Find runs where users waited more than 10 seconds for the first chunk:
import { mastraClient } from "./client";
const { traces } = await mastraClient.queryTraces({
timeRange: {
from: "2026-10-29T00:00:00.000Z",
to: "2026-11-05T00:00:00.000Z"
},
where: {
op: "gt",
left: { path: "timeToFirstChunkMs" },
right: { literal: 10000 }
}
});Find runs where the model took more than 3 seconds to start responding:
import { mastraClient } from "./client";
const { traces } = await mastraClient.queryTraces({
timeRange: {
from: "2026-10-29T00:00:00.000Z",
to: "2026-11-05T00:00:00.000Z"
},
where: {
op: "gt",
left: { path: "timeToFirstTokenMs" },
right: { literal: 3000 }
}
});Observability endpoints
You can also send a POST request to the trace query endpoint. The request includes MASTRA_PLATFORM_ACCESS_TOKEN and MASTRA_PROJECT_ID in the headers.
For more information and full configuration options, see:
