Query Flexible Metrics
Query AI Gateway analytics through a single endpoint across six datasources (modelMetrics, mcpMetrics, guardrailMetrics, cacheMetrics, configMetrics, agentMetrics). Every datasource shares the same request and response shape; what changes is the set of groupBy fields, aggregation columns, and filter fields available. Pick type: "distribution" for a single aggregated snapshot, or type: "timeseries" (with interval) for time-bucketed data.
The server enforces a per-field operator allow-list and a per-datasource field allow-list. For the complete per-datasource reference (allowed groupBy keys, aggregation columns, filter fields, and operators), see the per-datasource guides: Model Metrics, MCP Metrics, Guardrail Metrics, Cache Metrics, Routing Metrics, and Agent Metrics.
Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
Inclusive lower bound of the query window as an ISO 8601 timestamp.
"2025-01-21T00:00:00.000Z"
Exclusive upper bound of the query window as an ISO 8601 timestamp.
"2025-01-22T00:00:00.000Z"
Which Gateway data source to query.
modelMetrics, mcpMetrics, guardrailMetrics, cacheMetrics, configMetrics, agentMetrics distribution returns one aggregated row per groupBy combination. timeseries returns one row per bucket per groupBy combination and requires interval.
distribution, timeseries Aggregations to compute. When omitted, only the implicit total = COUNT(*) is returned.
Field names to group results by. Custom metadata keys are supported with a metadata. prefix (for example, "metadata.environment"). Allowed field names depend on the datasource.
AND-combined filters that narrow the rows feeding each aggregation.
Filters are AND-combined; there is no OR-group support. Use fieldName for standard datasource fields and metadataKey for custom request-metadata keys.
- MetricsFieldFilter
- MetricsMetadataFilter
Required for type: "timeseries". Bucket size as <positive integer> <unit> where <unit> is one of second, minute, hour, day, week, month, year (with or without a trailing s). Compound expressions like "1 hour 30 minute" are rejected.
"1 hour"
Deprecated alias for interval, in seconds (for example, 3600 for hourly). Prefer interval in new code. If both are provided, interval wins.
Response
Aggregated metrics for the requested datasource. Every row always contains total (implicit COUNT(*)), one key per requested aggregation (named <type><Column> in camelCase, for example sumInputTokens or p99LatencyMs), and one key per groupBy entry. Timeseries responses additionally include startTimestamp and endTimestamp as ISO 8601 timestamp strings (for example "2026-04-21T00:00:00.000Z"); endTimestamp equals the next bucket's startTimestamp. If groupBy is empty or omitted, the response collapses to a single row (or one row per timeseries bucket).