date_range, path, host, userAgent, and requests columns.
Before you start
- Your domain must be proxied through Cloudflare (the DNS record’s cloud icon is orange, not grey).
- You need Super Administrator or Administrator access on the Cloudflare account to create an API token for method 1.
- You need Permission group: “Analytics Read” policy access on the Cloudflare account to create an API token for method 2.
- You need
python3installed — runpython3 --versionto check.
Part 1: Create a Cloudflare API token
Both Account API Tokens and User API Tokens work with the GraphQL Analytics API. Choose based on your situation:Step 1: Log in to Cloudflare
Log in to the Cloudflare dashboard. Then follow one of the two methods below.Method 1: Account API Token
- In the left sidebar, click Manage Account.
- Click Account API Tokens (or go to
https://dash.cloudflare.com/{Account ID}/api-tokens). - Click Create Token.
- Name the token something like
AI traffic GraphQL read. - The Permission policies section should default to custom scope at the account level. Add the first policy:
- Analytics & Logs → Account Analytics → Read
- Click + Add policy to add a zone-level policy with:
- DNS & Zones → Zone → Read
- Analytics & Logs → Zone Analytics → Read
- Click Review Token, then Create Token.
- Copy the token somewhere safe.
Method 2: User API Token
- Go to your domain’s overview, scroll down to the API section, and click Get your API token (or go to
https://dash.cloudflare.com/profile/api-tokens). - Click + Create Token.
- Click Get started next to “Create Custom Token”.
- Add a token name (e.g.
AI traffic GraphQL read). - For permission 1: Account → Account Analytics → Read.
- Click Add more. For permission 2: Zone → Zone → Read.
- Click Add more. For permission 3: Zone → Zone Analytics → Read.
- Scroll down to Zone Resources and set it to: Include → Specific zone →
yourdomain.com. - Optionally set a TTL for when the token expires.
- Click Continue to summary, then Create Token.
- Copy the token somewhere safe.
Part 2: Get your Zone ID
- In Cloudflare, go to Websites and click your domain.
- Go to Overview.
- On the right side, find Zone ID and copy it. You’ll use this in the query below.
Part 3: Open Cloudflare GraphQL Explorer
- Open https://graphql.cloudflare.com/explorer.
- Grant access when prompted and review the permissions.
- Paste your API token into the API Token field and click Save.
Part 4: Run the query
Cloudflare limits eachhttpRequestsAdaptiveGroups block to a 24-hour window, and how far back you can query depends on your Cloudflare plan (Free and Pro plans typically only expose the last several days). Check how many days of history your plan provides before picking a date range. If you’d rather not pick dates by hand at all, skip ahead to Auto-generate the multi-day query — the script computes a rolling window for you.
Paste the query below into the explorer, then make these replacements:
REPLACE_WITH_ZONE_ID→ the Zone ID from Part 2.REPLACE_WITH_YOUR_DOMAIN→ your bare domain (e.g.example.com— nohttps://, no trailing slash).datetime_geq/datetime_lt→ a 24-hour window inside the range your plan allows.
Covering multiple days
Why the query gets long: Cloudflare caps each
httpRequestsAdaptiveGroups block to a single 24-hour window — there’s no “give me July 6 through 13” parameter. To cover N days, you copy-paste the entire block (including the full ~14-line userAgent_like OR list) N times, each with a unique alias and its date window shifted forward 24 hours. An 8-day pull is the same block repeated 8 times. That’s the sole reason the query balloons in length.httpRequestsAdaptiveGroups(...) block once per day. Give each block a unique alias (the label before the colon, e.g. d20260706, d20260707) and shift its date window forward by 24 hours. All blocks go inside the same zones(...) wrapper and run as a single request.
Here’s a single-day example:
Auto-generate the multi-day query (optional)
If you’re pulling more than a few days, hand-copying blocks gets tedious. The script below generates the full query for you and auto-rolls the date window — it always pulls the trailingNUM_DAYS ending at midnight UTC today, so you never edit a date. Run it weekly (or on a cron) and it just works.
Save this as generate_ai_traffic_query.py:
Set the window once with
NUM_DAYS. Leave it at 7 for the Free-plan retention cap. On a paid plan with longer retention, bump this single number — nothing else changes. Because the window is anchored to “today,” the same script pulls a fresh trailing range every time you run it, with no date edits.The user-agent list above covers the major AI crawlers and agents as of this writing. Add or remove
userAgent_like entries to track bots that aren’t listed.Part 5: Save the response as JSON
- Copy the full response from the right panel of the explorer.
- Open a plain-text editor (not a rich-text editor).
- Paste the response and save the file as
cloudflare_ai_traffic_response.jsonin your Downloads folder.
- Open TextEdit.
- Click Format → Make Plain Text.
- Paste the response.
- Save as
cloudflare_ai_traffic_response.json.
JSON data or ASCII text. If it says Rich Text Format, reopen the file in TextEdit, click Format → Make Plain Text, and save again.
Part 6: Convert the JSON to CSV
In Terminal:Ctrl + O, Enter, Ctrl + X), then run it:
Saved to ai_traffic_export.csv. The CSV will be in your Downloads folder.
Part 7: Send the CSV to The Prompting Company
Sendai_traffic_export.csv to your TPC contact, or email it to support@promptingco.com, so we can incorporate it into your AI traffic dashboard.
Troubleshooting
The query fails with a permissions error
Your API token is missing a scope. Recheck Part 1 — you need Account Analytics → Read, Zone → Read, and Zone Analytics → Read, with the zone resource scoped to your domain.file reports “Rich Text Format” instead of JSON
TextEdit defaults to rich text. Reopen the file, click Format → Make Plain Text, paste the response again, and save.
The GraphQL query returns an empty result
Your date window is likely outside the range your Cloudflare plan retains, orREPLACE_WITH_YOUR_DOMAIN doesn’t exactly match clientRequestHTTPHost for your zone (no https://, no trailing slash). If you’re using the auto-rolling script, make sure NUM_DAYS isn’t set beyond what your plan retains.
python3: command not found
Install Python 3 (e.g. brew install python3 on Mac), then re-run the script.