Skip to main content
The 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 the project.*.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 a query string. The response contains meta.requestId, which identifies the API request, and data, which contains an array of result objects.
Response
Queries follow the SQL limits and the resource limits in Query restrictions. Only SELECT queries are permitted. CTEs, subqueries, UNION, and EXCEPT are also permitted.

Select the data of one project, app, or environment

Each row contains project_id, app_id, and environment_id. Add a filter on one of these columns to get the data of one deployment target.
Use IN to select more than one target.
If you do not add one of these filters, the query reads all projects in the workspace.

Understand the time range

Two limits control the time range of a query: the 7 day history of gateway_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 filters workspace_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 keeps total_latency, instance_latency, and gateway_latency as plain numbers. Use quantile on these columns.

Find the paths with the most errors

Group by path 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

Use countIf 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

Use WITH 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 by app_id and response_status to see the response mix of each app.
Last modified on August 20, 2026