Skip to content
Kokumi
03 API reference

API reference

Already have:
Scoperead | write | admin (401 missing, 403 scope, 429 limit)
Done gatecurl -sS -H "Authorization: Bearer $READ_TOKEN" https://example.com/api/v1/health

Every /api/v1/* endpoint requires a Bearer token checked against scoped tokens in api_tokens (with legacy READ_TOKEN fallback only when zero active token rows exist), rate-limited via API_LIMIT, and logged to api_audit_log.

Scoped authentication and rate limits#

Tokens carry one of three hierarchical scopes: read, write, or admin. Missing or invalid tokens return 401, insufficient scope returns 403, and throttled callers return 429.

sh
READ
Vars
$READ_TOKENexample.com
curl -sS -H "Authorization: Bearer $READ_TOKEN" https://example.com/api/v1/counts?days=7
ExpectHTTP 200JSON with from, edge[], and beacon[]

Read routes (TokenScope::Read)#

Bounded list endpoints return truncated: true whenever their query cap is reached (5,000 rows on views, 50,000 rows on internal, and 500 rows on posts).

Write routes (TokenScope::Write)#

Write endpoints accept Idempotency-Key headers persisted in D1 idempotency_keys. Replays return 200 with x-idempotent-replay: true; reusing the same key on a different route returns 409.

Auth, scope, and replay status codes#

Public beacon routes#

POST /api/hit, /api/engaged, and /api/events accept unauthenticated browser beacons with CORS headers and respond 204. Static beacon script lives at GET /visit.js.

Related