Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

GraphQL Analytics API Queries, Metrics, Dimensions, and Filters

How Cloudflare's GraphQL Analytics API works: AdaptiveGroups structure, filters, pagination, TURN usage metrics, and limits.

This page summarizes Cloudflare documentation on the GraphQL Analytics API: one HTTP endpoint used to query aggregated metrics for many products (HTTP, Workers, TURN, tunnels, firewall events, and others). Product docs differ mainly by dataset name (the *AdaptiveGroups node), scope (viewer.accounts vs viewer.zones), and field list—the query pattern is the same.

Cloudflare TURN analytics is available over the GraphQL API only.

— Cloudflare, Analytics

GraphQL Analytics API endpoint: how to run analytics queries

Section titled “GraphQL Analytics API endpoint: how to run analytics queries”

GraphQL Analytics queries are HTTP POST requests to https://api.cloudflare.com/client/v4/graphql with a JSON body containing query and variables. Tutorials across the cluster use an API token in the Authorization: Bearer header and Content-Type: application/json. For Realtime TURN analytics, the token needs the Account Analytics permission.

Account-scoped datasets (TURN, Magic Transit tunnels, Workers, Queues, and similar) use viewer { accounts(filter: { accountTag: $accountId }) { ... } }. Zone-scoped datasets (HTTP requests, firewall events, Email Routing, Zaraz) use viewer { zones(filter: { zoneTag: $zoneTag }) { ... } }.

AdaptiveGroups structure: count, sum, avg, and dimensions

Section titled “AdaptiveGroups structure: count, sum, avg, and dimensions”

Aggregated analytics nodes whose names end in AdaptiveGroups share a common shape. Datasets (tables) documents the pattern:

type WhateverGroup {
count
sum { ... }
avg { ... }
uniq { ... }
}

In practice you choose a dataset (for example callsTurnUsageAdaptiveGroups, httpRequestsAdaptiveGroups, magicTransitTunnelTrafficAdaptiveGroups), pass filter, limit, and orderBy, then request dimensions (group-by fields) plus aggregates (count, sum, avg, quantiles, and sometimes confidence).

Prefer data nodes with the Groups suffix over raw adaptive datasets. Aggregated data is pre-processed and less subject to sampling variability.

— Cloudflare, GraphQL API inconsistent results

Use *Adaptive (no Groups) when you need row-level events—for example firewallEventsAdaptive, emailSendingAdaptive, or workersInvocationsAdaptive for troubleshooting single requests or messages. Use *AdaptiveGroups for dashboards, billing views, and time series.

Filtering analytics: time range, OR, AND, and field operators

Section titled “Filtering analytics: time range, OR, AND, and field operators”

Filters are an object on each dataset node. Filtering shows comparisons (datetime_gt, datetime_lt), equality, OR, and operators such as _has / _hasall on list fields—for example ruleIDs_has: "rule-id".

Match the filter field to the time dimension you group on: day buckets often use date_geq / date_leq; minute or hour charts use datetime_geq / datetime_leq or dimension-specific names like datetimeHour_geq. Email Service metrics notes that grouped datasets may prefer date_* filters while event datasets use datetime_* with full ISO-8601 timestamps.

Network and HTTP filters are often case-sensitive for paths and URIs—see GraphQL Analytics for Network Firewall examples.

Pagination and sorting: limit, orderBy, and seek filters

Section titled “Pagination and sorting: limit, orderBy, and seek filters”

Sorting: Sorting uses orderBy with field names and _ASC / _DESC, including aggregate sorts like sum_egressBytes_DESC.

Pagination: Pagination relies on limit plus filters that exclude rows already seen—for example clientCountryName_gt together with datetime_geq when sorting by datetime_ASC, clientCountryName_ASC. Stream bulk analytics uses seek pagination with uid_gt for video UIDs.

TURN analytics metrics: egressBytes, ingressBytes, and concurrentConnections

Section titled “TURN analytics metrics: egressBytes, ingressBytes, and concurrentConnections”

Realtime TURN analytics tracks ingress and egress in bytes and exposes data through callsTurnUsageAdaptiveGroups under the account viewer.

Cloudflare Realtime TURN service counts ingress and egress usage in bytes. You can access this real-time and historical data using the TURN analytics API. You can see TURN usage data in a time series or aggregate that shows traffic in bytes over time.

— Cloudflare, Analytics

Metric Meaning Aggregations
egressBytes Bytes sent from TURN servers to clients sum, avg
ingressBytes Bytes received by TURN servers from clients sum, avg
concurrentConnections Average concurrent connections sum, avg (docs also use avg { concurrentConnectionsFiveMinutes } in five-minute groups)

TURN dimensions: time, geography, keyId, and customIdentifier

Section titled “TURN dimensions: time, geography, keyId, and customIdentifier”
Category Dimensions
Time datetime, datetimeMinute, datetimeFiveMinutes, datetimeFifteenMinutes, datetimeHour
Geography datacenterCity, datacenterCountry, datacenterRegion
Identity keyId, customIdentifier, username

Custom identifiers are useful for accounting usage for different users in your system.

— Cloudflare, Analytics

Filters include datetime range, TURN Key ID, TURN username, and custom identifier. Typical jobs from the TURN analytics examples:

  • Dashboard time series — datetimeFiveMinutes with sum { egressBytes ingressBytes } and avg { concurrentConnectionsFiveMinutes } (five-minute buckets are recommended for dashboards; datetimeMinute is most granular).
  • Top consumers — orderBy: [sum_egressBytes_DESC] with dimensions { keyId } or { customIdentifier }.
  • Per-tenant billing — filter customIdentifier: "tango" (or your label) and group by keyId.
  • Regional distribution — group by datacenterCity, datacenterCountry, datacenterRegion.

Per-customer TURN usage: filter customIdentifier, not multi-tenant GROUP BY

Section titled “Per-customer TURN usage: filter customIdentifier, not multi-tenant GROUP BY”

Replacing existing TURN servers warns that grouping many customers in one query can skew sampled adaptive results; filter to one customIdentifier per query when attributing usage.

Querying TURN usage for multiple customers in a single query can lead to inaccurate results. This is because the usage pattern of one customer could affect the sampling rate applied to another customer’s data, potentially skewing the results.

— Cloudflare, Replacing existing TURN servers

Confidence intervals, errors, and retention limits

Section titled “Confidence intervals, errors, and retention limits”

Sampled grouped nodes can return confidence objects. Confidence intervals defines estimate, lower, upper, and sampleSize—for example an estimated event count with a 95% interval derived from sampleSize.

Error responses include GraphQL errors with messages such as retention violations:

cannot request data older than 2678400s

— Cloudflare, Error responses

Per-product caps appear in product docs—for example Stream bulk analytics limitations lists maximum query interval and retention per dataset; R2 metrics allow up to 31 days (R2 metrics and analytics). Use viewer.accounts settings where documented to read maxDuration and notOlderThan in seconds.

Billable TURN or Stream minutes may not match GraphQL totals exactly when data is sampled—for example Stream states GraphQL minutes delivered may not precisely match invoice line items.

Other AdaptiveGroups datasets (same query habits)

Section titled “Other AdaptiveGroups datasets (same query habits)”

The cluster repeats the same habits on different nodes—only schema and scope change:

Use case Dataset (examples) Doc link
HTTP by colo / path httpRequestsAdaptiveGroups HTTP Requests by Adaptive Groups migration
Tunnel bitrate magicTransitTunnelTrafficAdaptiveGroups Query tunnel bandwidth
Tunnel health magicTransitTunnelHealthChecksAdaptiveGroups (tunnelState 0 / 0.5 / 1) Query tunnel health check results
Endpoint probes magicEndpointHealthCheckAdaptiveGroups Query endpoint health check results
Workers workersInvocationsAdaptive / grouped variants Querying Workers Metrics
Gateway HTTP (e.g. MCP) gatewayHttpRequestsAdaptiveGroups Detect MCP traffic in Gateway logs

Network Analytics v2 replaces older ipFlows* rollups with nodes such as magicTransitNetworkAnalyticsAdaptiveGroups; see Network Analytics v1 to v2 and NAv2 node reference. For ingress-only network views, filters may include direction: "ingress".

Common mistakes when querying GraphQL Analytics

Section titled “Common mistakes when querying GraphQL Analytics”
  • Querying raw *Adaptive for aggregates instead of *AdaptiveGroups, increasing sampling noise (FAQ).
  • Mismatched time granularity—e.g. hourly filters on minute dimensions, or unrelated metric and datetime* fields on tunnel bitrate queries (tunnel bandwidth tutorial).
  • Retention or range errors—widening datetime_* beyond allowed seconds (errors).
  • Multi-tenant TURN in one callsTurnUsageAdaptiveGroups query without per-customIdentifier filters (replacing TURN servers).
  • Case-sensitive URI or path filters on HTTP or firewall datasets (Network Firewall GraphQL Analytics).
  • Assuming uniq.viewers or similar counts are unique people—Stream CMCD metrics defines some uniques as session IDs, not individuals.

Illustrative structure (field names match TURN analytics); run via POST to the GraphQL endpoint with your account tag and token:

query concurrentConnections($accountId: string!, $dateFrom: Time!, $dateTo: Time!) {
viewer {
accounts(filter: { accountTag: $accountId }) {
callsTurnUsageAdaptiveGroups(
limit: 10000
filter: { date_geq: $dateFrom, date_leq: $dateTo }
orderBy: [datetimeFiveMinutes_ASC]
) {
dimensions { datetimeFiveMinutes }
avg { concurrentConnectionsFiveMinutes }
sum { egressBytes ingressBytes }
}
}
}
}

For HTTP POST examples (headers, JSON payload), see Querying Firewall Events or Zaraz Monitoring API.

  1. Create a Cloudflare API token with analytics permissions for your target (for TURN, Account Analytics per TURN analytics).
  2. Run a small *AdaptiveGroups query against https://api.cloudflare.com/client/v4/graphql for a short recent window, following Filtering.
  3. Confirm the response has both data and "errors": null (or inspect errors per Error responses).
  4. For TURN, compare sum { egressBytes } for one customIdentifier against your own metering, using separate filtered queries as in Replacing existing TURN servers.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about.