Read API
LiveEvery /api/v1/* route runs behind scoped Bearer tokens, sliding rate limits, and an audit log in D1. Read rollups, inspect raw hits, or write goals and imports with deterministic caps and idempotency keys.
/api/v1 with a bearer read token.
Scoped tokens, rate limits, and audit trail
Tokens carry read, write, or admin scope in api_tokens (with legacy READ_TOKEN fallback only when zero active token rows exist). Every call is rate-limited by API_LIMIT and recorded in api_audit_log.
- 401 on missing, malformed, or expired Bearer tokens.
- 403 when a read token hits a write route (expected after kokumi handover).
- 429 when a caller hits the API_LIMIT cap before touching D1.
curl -sS -H "Authorization: Bearer $READ_TOKEN" "https://example.com/api/v1/counts?days=7"Bounded reads that never blow up your context window
Read routes cover daily counts, raw hits, internal links, page views, component clicks, proxied tools, unlinked geo aggregates, goals, posts, privacy config, and health. Bounded lists return truncated: true when they hit their row cap so callers know to narrow the window.
- GET /api/v1/counts?days=7 for edge[], beacon[], and beacon_by_day[] rollups.
- GET /api/v1/views caps at 5,000 rows; /api/v1/internal caps at 50,000; /api/v1/posts caps at 500.
- GET /api/v1/privacy and /api/v1/health expose live Worker config, canary status, and quota headroom.
curl -sS -H "Authorization: Bearer $READ_TOKEN" "https://example.com/api/v1/views?day=2026-12-01"Idempotent writes and unauthenticated browser beacons
Write routes (POST /api/v1/goals and POST /api/v1/import) require write scope and accept an Idempotency-Key persisted in D1 idempotency_keys. Public browser beacons (POST /api/hit, /api/engaged, /api/events) accept CORS requests without auth and return 204.
- Replaying the same Idempotency-Key on the same route returns 200 with x-idempotent-replay: true.
- Reusing an Idempotency-Key against a different route returns 409.
- Static beacon script is served directly from your Worker at GET /visit.js.