Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Comprehensive Cloudflare platform skill covering Workers, D1, R2, KV, AI, Durable Objects, and security.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/analytics-engine/api.md
1# Analytics Engine API Reference23## Writing Data45### `writeDataPoint()`67Fire-and-forget (returns `void`, not Promise). Writes happen asynchronously.89```typescript10interface AnalyticsEngineDataPoint {11blobs?: string[]; // Up to 20 strings (dimensions), 16KB each12doubles?: number[]; // Up to 20 numbers (metrics)13indexes?: string[]; // 1 indexed string for high-cardinality filtering14}1516env.ANALYTICS.writeDataPoint({17blobs: ["/api/users", "GET", "200"],18doubles: [145.2, 1], // latency_ms, count19indexes: ["customer_abc123"]20});21```2223**Behaviors:** No await needed, no error thrown (check tail logs), auto-sampled at high volumes, auto-timestamped.2425**Blob vs Index:** Blob for GROUP BY (<100k unique), Index for filter-only (millions unique).2627### Full Example2829```typescript30export default {31async fetch(request: Request, env: Env): Promise<Response> {32const start = Date.now();33const url = new URL(request.url);34try {35const response = await handleRequest(request);36env.ANALYTICS.writeDataPoint({37blobs: [url.pathname, request.method, response.status.toString()],38doubles: [Date.now() - start, 1],39indexes: [request.headers.get("x-api-key") || "anonymous"]40});41return response;42} catch (error) {43env.ANALYTICS.writeDataPoint({44blobs: [url.pathname, request.method, "500"],45doubles: [Date.now() - start, 1, 0],46});47throw error;48}49}50};51```5253## SQL API (External Only)5455```bash56curl -X POST https://api.cloudflare.com/client/v4/accounts/{account_id}/analytics_engine/sql \57-H "Authorization: Bearer $TOKEN" \58-d "SELECT blob1 AS endpoint, COUNT(*) AS requests FROM dataset WHERE timestamp >= NOW() - INTERVAL '1' HOUR GROUP BY blob1"59```6061### Column References6263```sql64-- blob1..blob20, double1..double20, index1, timestamp65SELECT blob1 AS endpoint, SUM(double1) AS latency, COUNT(*) AS requests66FROM my_dataset67WHERE index1 = 'customer_123' AND timestamp >= NOW() - INTERVAL '7' DAY68GROUP BY blob169HAVING COUNT(*) > 10070ORDER BY requests DESC LIMIT 10071```7273**Aggregations:** `SUM()`, `AVG()`, `COUNT()`, `MIN()`, `MAX()`, `quantile(0.95)()`7475**Time ranges:** `NOW() - INTERVAL '1' HOUR`, `BETWEEN '2026-01-01' AND '2026-01-31'`7677### Query Examples7879```sql80-- Top endpoints81SELECT blob1, COUNT(*) AS requests, AVG(double1) AS avg_latency82FROM api_requests WHERE timestamp >= NOW() - INTERVAL '24' HOUR83GROUP BY blob1 ORDER BY requests DESC LIMIT 208485-- Error rate86SELECT blob1, COUNT(*) AS total,87SUM(CASE WHEN blob3 LIKE '5%' THEN 1 ELSE 0 END) AS errors88FROM api_requests WHERE timestamp >= NOW() - INTERVAL '1' HOUR89GROUP BY blob1 HAVING total > 509091-- P95 latency92SELECT blob1, quantile(0.95)(double1) AS p9593FROM api_requests GROUP BY blob194```9596## Response Format9798```json99{"data": [{"endpoint": "/api/users", "requests": 1523}], "rows": 2}100```101102## Limits103104| Resource | Limit |105|----------|-------|106| Blobs/Doubles per point | 20 each |107| Indexes per point | 1 |108| Blob/Index size | 16KB |109| Data retention | 90 days |110| Query timeout | 30s |111112**Critical:** High write volumes (>1M/min) trigger automatic sampling.113