Authorization: Bearer <your_api_key> and Content-Type: application/json.
Access control
Access to metrics is governed by the data access rules configured by your tenant. The server applies these rules automatically based on the caller’s identity—you don’t pass any RBAC or scoping fields in the request. What a caller can query (their own data, their team’s data, or tenant-wide data) depends entirely on the rules an admin has set up. See Configure Data Access for how these rules are defined and evaluated.Authentication
Get your API key
Get your API key
- Personal Access Token (PAT): Go to Access → Personal Access Tokens in your TrueFoundry dashboard
- Virtual Account Token (VAT): Go to Access → Virtual Account Tokens (requires admin permissions)
Quick start
groupBy and aggregations[].column use virtualModel. In filters[].fieldName and in response keys, the name is virtualModelName. They refer to the same underlying database column.- Distribution query
- Timeseries query
API reference
Post JSON to the endpoint above withAuthorization: Bearer <your_api_key> and Content-Type: application/json.
Request parameters
"2026-04-21T00:00:00.000Z")."2026-04-22T00:00:00.000Z")."modelMetrics" for Gateway model metrics."distribution": returns aggregated rows (one row pergroupBycombination)."timeseries": returns time-bucketed rows (one row per bucket pergroupBycombination). Requiresinterval.
{ type, column } objects describing the aggregations to compute. When omitted, only the implicit total = COUNT(*) is returned.Supported aggregation types
Supported aggregation types
Supported aggregation columns
Supported aggregation columns
metadata. prefix (e.g. "metadata.environment").Available group-by fields
Available group-by fields
groupBy contains userEmail (without virtualaccount), the server auto-injects WHERE CreatedBySubjectType = 'user'. virtualaccount alone auto-injects 'virtualaccount'. When both appear, scope it yourself with createdBySubjectType if needed.<positive integer> <unit>, where <unit> is one of second, minute, hour, day, week, month, year (with or without a trailing s). Examples: "30 second", "5 minute", "1 hour", "1 day". Compound expressions like "1 hour 30 minute" are rejected.interval. Accepts a positive integer number of seconds (e.g. 3600 for hourly). Prefer interval in new code. If both are provided, interval wins.Filtering
Filters narrow down the rows that go into each aggregation and group. They are AND-combined; there is no OR-group support. The server enforces a per-field operator allow-list, so the exact subset of operators you can use depends on the field.- Field filters
- Metadata filters
fieldName:Filterable fields and allowed operators
Filterable fields and allowed operators
EQUAL, NOT_EQUAL, IN, NOT_IN, STRING_CONTAINS, STRING_NOT_CONTAINS, STRING_STARTS_WITH, STRING_NOT_STARTS_WITH, STRING_ENDS_WITH, STRING_NOT_ENDS_WITH. A few fields are narrower: providerAccountType and createdBySubjectType are comparison-only (no STRING_* operators), traceId is equality-only, and virtualModelName additionally supports IS_NULL.cacheType, cacheNamespace, cacheLookupStatus, and the cache token columns), see Cache Metrics.Filter operators reference
Filter operators reference
team)Custom metadata, team unnesting, and combining filters
Custom metadata, team unnesting, and combining filters
- Filter:
{ "metadataKey": "environment", "operator": "EQUAL", "value": "prod" } - Group: include
"metadata.environment"in thegroupByarray (string literal, prefix ismetadata.).
team is in groupBy (or used as the column of an aggregation), the server transparently UNNESTs the Teams array CTE before applying RBAC. Callers don’t need to do anything extra. Rows whose Teams array is NULL or empty drop out naturally.Combining multiple filters. Filters are AND-combined:Query examples
Every example posts a JSON body to the endpoint above. To keep the snippets short, only thejson body is shown; the request wrapper is identical to the Quick start.
{"fieldName": "virtualModelName", "operator": "IS_NULL", "value": true}. To target virtual models, flip the value to false and swap groupBy: ["modelName"] for groupBy: ["virtualModel"] (the alias used in groupBy/aggregations).Distribution examples
Count by model name
Count by model name
Sum tokens by model
Sum tokens by model
Latency percentiles by model
Latency percentiles by model
Group by metadata
Group by metadata
Multi-dimensional grouping
Multi-dimensional grouping
Filter high-latency requests
Filter high-latency requests
Filter by latency range
Filter by latency range
Filter by token counts
Filter by token counts
Filter by team
Filter by team
Filter by metadata
Filter by metadata
Virtual-model metrics only
Virtual-model metrics only
virtualModel in groupBy/aggregations but virtualModelName in filters:Complex filter combination
Complex filter combination
Timeseries examples
Every timeseries query must includeinterval (or the deprecated intervalInSeconds). Buckets are expressed as <positive integer> <unit> strings like "5 minute", "1 hour", or "1 day".
Basic hourly counts
Basic hourly counts
5-minute intervals
5-minute intervals
Hourly counts by model
Hourly counts by model
Hourly p99 latency by model
Hourly p99 latency by model
Hourly counts by team
Hourly counts by team
Timeseries with model + latency filter
Timeseries with model + latency filter
Hourly cost by model
Hourly cost by model
Hourly metadata breakdown
Hourly metadata breakdown
Daily over a week
Daily over a week
Complex timeseries query
Complex timeseries query
Response format
Every successful response has the same outer shape:total: implicitCOUNT(*)for the row. Always present.<aggregationKey>: one key per requested aggregation. The key is<type><Column>in camelCase (e.g.sumLatencyMs,p99LatencyMs,countModelName,countDistinctToolName).<groupByKey>: one key pergroupByentry. The key is the lowerCamelCase form of the underlying column. Two special mappings:userEmailandvirtualaccountboth map tocreatedBySubjectSlugin the response (the underlying column isCreatedBySubjectSlug, differentiated byCreatedBySubjectType).teammaps toteam(the value is a single unnested scalar, not an array). All othergroupBykeys preserve their lowerCamelCase name.
startTimestamp/endTimestamp: present only for timeseries responses. Bucket start and end as ISO 8601 timestamp strings;endTimestampequals the next bucket’sstartTimestamp. Distribution responses omit both.
Distribution response example
Distribution response example
Timeseries response example
Timeseries response example
groupBy is empty or omitted, the response collapses to a single row (or one row per timeseries bucket) summarising every request inside the window.virtualModelName key in the response (not virtualModel), because the response key is the lowerCamelCase of the underlying database column.Error responses
A malformed query returns400 Bad Request:
Common causes and other status codes
Common causes and other status codes
400:- Operator not allowed on this field, for example,
EQUALon a field that supports onlyIN/NOT_IN. - Missing required
value(or wrong shape, e.g. scalar where array is expected forIN/BETWEEN). - Unknown field name for the datasource.
- Invalid
intervalformat (compound expressions, unrecognised unit, non-positive integer). - Missing required
intervalfor a timeseries query.
401 Unauthorized: missing or invalid bearer token.403 Forbidden: caller does not have permission for the requested scope.500 Internal Server Error: unexpected server error while executing the query.