mastra 1.34.1-alpha.2 → 1.34.1-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,7 +3,7 @@ name: mastra
3
3
  description: Documentation for mastra. Use when working with mastra APIs, configuration, or implementation.
4
4
  metadata:
5
5
  package: "mastra"
6
- version: "1.34.1-alpha.2"
6
+ version: "1.34.1-alpha.3"
7
7
  ---
8
8
 
9
9
  ## When to use
@@ -16,7 +16,7 @@ Read the individual reference documents for detailed explanations and code examp
16
16
 
17
17
  ### Docs
18
18
 
19
- - [API Reference: Mastra platform](references/docs-mastra-platform-api.md) - Use the Mastra platform REST API to manage members, tokens, Studio and Server deployments, gateways, observability feedback, and project-scoped resources.
19
+ - [API Reference: Mastra platform](references/docs-mastra-platform-api.md) - Use the Mastra platform REST API to manage members, tokens, Studio and Server deployments, gateways, observability feedback and metrics, and project-scoped resources.
20
20
  - [Observability](references/docs-mastra-platform-observability.md) - Collect, import, and query hosted traces, logs, metrics, scores, and feedback from Mastra applications with Mastra Platform Observability and local fallback storage.
21
21
 
22
22
  ### Reference
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.34.1-alpha.2",
2
+ "version": "1.34.1-alpha.3",
3
3
  "package": "mastra",
4
4
  "exports": {},
5
5
  "modules": {}
@@ -179,6 +179,94 @@ The API returns `401` for invalid credentials, `403` for organization authorizat
179
179
 
180
180
  Hosted observability doesn't provide a feedback creation route. Export feedback from the application as described in [Export feedback to Mastra Platform](https://mastra.ai/docs/observability/feedback).
181
181
 
182
+ ## Metrics API
183
+
184
+ The Metrics API queries metrics exported to Mastra Platform Observability. Because the API is unversioned, backwards compatibility isn't guaranteed. Rate limits, retention, and ingestion-to-query freshness aren't published contracts.
185
+
186
+ The endpoints share their query parameters, request bodies, and response types with the Mastra runtime metric routes. See the [metric queries reference](https://mastra.ai/reference/observability/metrics/queries) for the full contract, including [shared filters](https://mastra.ai/reference/observability/metrics/queries), [analytics methods](https://mastra.ai/reference/observability/metrics/queries), and [metric discovery](https://mastra.ai/reference/observability/metrics/queries).
187
+
188
+ Use the root URL for your environment's data-residency region:
189
+
190
+ | Region | Root URL |
191
+ | -------------- | ------------------------------------------------------ |
192
+ | United States | `https://observability.mastra.ai/api/observability` |
193
+ | European Union | `https://observability.eu.mastra.ai/api/observability` |
194
+
195
+ Telemetry stays in its residency region. Querying the other region returns no records for the environment. See [Observability co-location](https://mastra.ai/docs/mastra-platform/regions) for the environment-to-region mapping.
196
+
197
+ ### Authentication and project scope
198
+
199
+ Every request requires a platform access token. Create one in [Mastra Platform](https://projects.mastra.ai), or use the token written to `.env` during Platform setup.
200
+
201
+ Include `X-Mastra-Project-Id` to limit results to one project. If you omit it, the query covers metrics in every project available to the token's organization.
202
+
203
+ ```bash
204
+ curl -sS "https://observability.mastra.ai/api/observability/discovery/metric-names?prefix=mastra_model_" \
205
+ -H "Authorization: Bearer $MASTRA_PLATFORM_ACCESS_TOKEN" \
206
+ -H "X-Mastra-Project-Id: $MASTRA_PROJECT_ID" | jq
207
+ ```
208
+
209
+ Use an organization-scoped Platform access token. Gateway inference keys such as `mk_*` keys aren't accepted. Queries remain constrained to the token's organization even when you supply a project ID.
210
+
211
+ ### Endpoints
212
+
213
+ | Method | Endpoint | Description |
214
+ | ------ | -------------------------------- | --------------------------------------- |
215
+ | GET | `/metrics` | List raw metric records |
216
+ | POST | `/metrics/aggregate` | Return one aggregate value |
217
+ | POST | `/metrics/breakdown` | Group metrics by dimensions |
218
+ | POST | `/metrics/timeseries` | Bucket metrics by interval |
219
+ | POST | `/metrics/percentiles` | Return percentile series for one metric |
220
+ | GET | `/discovery/metric-names` | List metric names |
221
+ | GET | `/discovery/metric-label-keys` | List label keys for a metric |
222
+ | GET | `/discovery/metric-label-values` | List values for a metric label key |
223
+
224
+ The list and discovery endpoints take their arguments as query parameters. See [`listMetrics(args)`](https://mastra.ai/reference/observability/metrics/queries) and [metric discovery](https://mastra.ai/reference/observability/metrics/queries) in the metric queries reference for the parameters each one accepts.
225
+
226
+ Analytics endpoints accept the same JSON request bodies and return types as the [metric queries reference](https://mastra.ai/reference/observability/metrics/queries), including `name`, `aggregation`, `filters`, `groupBy`, `interval`, `percentiles`, `comparePeriod`, `limit`, `orderDirection`, and `distinctColumn`.
227
+
228
+ ```bash
229
+ curl -sS "https://observability.mastra.ai/api/observability/metrics/aggregate" \
230
+ -X POST \
231
+ -H "Authorization: Bearer $MASTRA_PLATFORM_ACCESS_TOKEN" \
232
+ -H "X-Mastra-Project-Id: $MASTRA_PROJECT_ID" \
233
+ -H "Content-Type: application/json" \
234
+ --data '{"name":["mastra_model_total_input_tokens","mastra_model_total_output_tokens"],"aggregation":"sum","filters":{"timestamp":{"start":"2026-09-13T00:00:00Z","end":"2026-10-13T00:00:00Z"}},"comparePeriod":"previous_period"}' | jq
235
+ ```
236
+
237
+ `filters.timestamp` is optional. If you omit `start` and `end`, the query covers all retained data. `comparePeriod` requires both `start` and `end`. Without them, the previous-period fields are `null`.
238
+
239
+ The API returns `401` for invalid credentials, `403` for organization authorization failures, and `400` for malformed query arguments or JSON bodies.
240
+
241
+ #### `MastraClient`
242
+
243
+ `MastraClient` from `@mastra/client-js` exposes the analytics and discovery methods. Set `baseUrl` to the region's host without the `/api/observability` path:
244
+
245
+ ```typescript
246
+ import { MastraClient } from '@mastra/client-js'
247
+
248
+ const mastraClient = new MastraClient({
249
+ baseUrl: 'https://observability.mastra.ai',
250
+ headers: {
251
+ Authorization: `Bearer ${process.env.MASTRA_PLATFORM_ACCESS_TOKEN}`,
252
+ 'X-Mastra-Project-Id': process.env.MASTRA_PROJECT_ID!,
253
+ },
254
+ })
255
+
256
+ const result = await mastraClient.getMetricAggregate({
257
+ name: ['mastra_model_total_input_tokens', 'mastra_model_total_output_tokens'],
258
+ aggregation: 'sum',
259
+ })
260
+ ```
261
+
262
+ #### CLI
263
+
264
+ The [`mastra api metric`](https://mastra.ai/reference/cli/mastra) commands target the United States endpoint by default. Pass `--url` to query the European Union region:
265
+
266
+ ```bash
267
+ mastra api --url https://observability.eu.mastra.ai metric aggregate '<json>'
268
+ ```
269
+
182
270
  ## Gateway proxy endpoints
183
271
 
184
272
  Visit the [Gateway documentation](https://gateway.mastra.ai/docs) for more details.
@@ -168,6 +168,8 @@ The CLI can infer platform credentials from your project environment. See the [`
168
168
 
169
169
  You can query exported feedback over HTTP. See the [Feedback API](https://mastra.ai/docs/mastra-platform/api) for its current status, regional endpoints, authentication, project scoping, and supported query parameters such as `traceId` and `environment`.
170
170
 
171
+ You can query exported metrics over HTTP, with `MastraClient`, or with `mastra api metric`. See the [Metrics API](https://mastra.ai/docs/mastra-platform/api) for regional endpoints, authentication, project scoping, and supported endpoints.
172
+
171
173
  ## Import existing traces
172
174
 
173
175
  Use `mastra traces import` to move existing trace history from a supported observability provider into an existing Mastra Platform project. The command reads and validates complete traces at the source, converts them into Mastra spans, then uses a shared workflow for preparation, upload, resume, and verification.