modelMetrics, restricted to rows where CacheLookupStatus is set. You can retrieve either distribution (aggregated) or timeseries results with powerful filtering and grouping.
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
WHERE "CacheLookupStatus" IS NOT NULL to every cache query; you do not (and should not) add it yourself. Because cache shares its underlying table with modelMetrics, every model field is reachable in addition to the cache-specific ones below.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")."cacheMetrics" for Gateway cache 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
cacheType, cacheNamespace, cacheLookupStatus, and the cache token columns. cacheType is narrow (IN/NOT_IN only); the others accept the full string or numeric operator set as documented below.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}. Flip to false (and swap groupBy: ["modelName"] for groupBy: ["virtualModel"]) for virtual-model-only cache stats.Distribution examples
Top namespaces by tokens served from cache
Top namespaces by tokens served from cache
cacheReadInputTokens per namespace. Surfaces which buckets do the most work:Lookup latency percentiles by cache type
Lookup latency percentiles by cache type
Savings by model
Savings by model
Semantic cache only
Semantic cache only
Filter namespaces by prefix
Filter namespaces by prefix
STRING_STARTS_WITH on cacheNamespace, handy when prod and staging share a cache type:Hit vs miss breakdown
Hit vs miss breakdown
cacheLookupStatus to see hits vs misses per cache type:Tokens written vs read
Tokens written vs read
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".
Hourly savings by namespace
Hourly savings by namespace
Hourly p99 lookup latency by cache type
Hourly p99 lookup latency by cache type
Hourly tokens read from cache
Hourly tokens read from cache
Hourly hits vs misses
Hourly hits vs misses
cacheLookupStatus over time:Daily savings over a week
Daily savings over a week
5-minute lookup latency in an incident window
5-minute lookup latency in an incident window
Hourly savings for semantic cache only
Hourly savings for semantic cache only
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.sumPotentialCostSavings,p99CacheLookupLatencyMs,sumCacheReadInputTokens).<groupByKey>: one key pergroupByentry. The key is the lowerCamelCase form of the underlying column. Two special mappings:userEmailandvirtualaccountboth map tocreatedBySubjectSlugin the response.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 cache-eligible request inside the window. Note that the server always pins WHERE "CacheLookupStatus" IS NOT NULL, so non-cache rows are filtered out automatically.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,
STRING_CONTAINSoncacheType(it 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.