POST /v2/analytics.getGatewayRequests endpoint runs SQL queries on the
requests that Unkey routed to your deployments. Use it from a trusted backend
with a root key. Never put a root key in browser code.
For the request and response schemas, see the API
reference.
Authenticate the request
Use a root key with theproject.*.read_gateway_requests permission. This
permission gives access to the gateway request data of all projects in the
workspace.
Unkey limits each query to the workspace of the root key. A query cannot read
the data of a different workspace, and it cannot remove this filter.
Send a query
Send a JSON object with aquery string. The response contains
meta.requestId, which identifies the API request, and data, which contains
an array of result objects.
Response
Select the data of one project, app, or environment
Each row containsproject_id, app_id, and environment_id. Add a filter on
one of these columns to get the data of one deployment target.
IN to select more than one target.
Understand the time range
Two limits control the time range of a query: the 7 day history ofgateway_requests_v1 and the retention setting of your workspace plan. A
query gets only the rows that satisfy both limits. If you do not add a time
filter, Unkey limits the results to your workspace retention range.
Reference available columns
The table contains one row for each request. Unkey filtersworkspace_id
automatically, thus you do not need to add it to a query.
A query must name the columns that it needs. SELECT * fails, because the
table also contains columns of the Unkey infrastructure that a workspace
cannot read.
Read a latency percentile
The table keepstotal_latency, instance_latency, and gateway_latency
as plain numbers. Use quantile on these columns.
Find the paths with the most errors
Group bypath to find the endpoints that return the most server errors. The
table keeps time as Unix milliseconds, thus the time filter uses
toUnixTimestamp64Milli.
Calculate an error rate for each deployment
UsecountIf to count a subset of the rows in the same query. This example
compares the failed requests with all requests of each deployment.
Build a zero-filled time series
UseWITH FILL to get each minute, including the minutes with no requests.
This query gives a dashboard chart the full range without gap filling in the
client.
Compare the status codes of each app
Group byapp_id and response_status to see the response mix of each app.