The SQL API lets you query Cloudflare analytics and observability datasets with SQL. Use the API to select fields, filter events, calculate aggregates, group results, and integrate analytics data with your applications.
The SQL API provides GET and POST query endpoints at:
https://api.cloudflare.com/client/v4/analytics/sqlSend one SELECT statement in each request. Use POST to send raw SQL or a JSON request with parameters, request-level scope, and a time range. Use GET for URL-encoded queries. The API validates the statement against the available datasets and supported SQL language before it executes the query.
Use the introspection endpoint to discover dataset names, categories, descriptions, kinds, columns, and data types. You can also run queries with cf sql query and list datasets with cf sql datasets.
The SQL API supports a deliberately limited SQL dialect. It does not pass arbitrary SQL through to the underlying data store. For the complete language surface, refer to the SQL language reference.
Every query must include:
- An account or zone scope, supplied in the SQL statement or request body, that identifies the data you are authorized to query.
- A lower time bound that limits how far back the query reads.
- One schema-qualified dataset, such as
events.httpRequests.
Dataset and field availability depends on your Cloudflare plan and permissions. The API authorizes every account or zone named by a query.
Refer to Get started to create an API token and run your first query.
To query datasets from a Cloudflare Worker without managing an API token, use the Workers binding.