HTTP API
All requests need authentication via an API key (X-API-Key header) or a dashboard JWT (Authorization: Bearer).
The SDK uses the API key path. The key looks like ck_<8 hex>_<random> and is created in the dashboard.
Authentication headers
| Header | Required for | Description |
|---|---|---|
X-API-Key | SDK | The tenant's key, e.g. ck_8b8da955_a1b2c3d4e5f6 |
X-Tenant-Domain | SDK (optional) | The hostname the SDK is running on — needed to test a production key from localhost. The backend rejects requests from domains not on the tenant's allowlist. |
Authorization | Dashboard | JWT from the dashboard login flow. |
Endpoints
POST /v1/events
Ingest a batch of events from the SDK.
curl -X POST https://api.nochurn.dev/v1/events \
-H "Content-Type: application/json" \
-H "X-API-Key: ck_..." \
-d '{"events": [...]}'
Request body:
{
"events": [
{
"eventId": "evt_abc123",
"userId": "user_xyz",
"sessionId": "sess_abc",
"type": "click",
"properties": { "element": "button.primary" },
"occurredAt": "2026-01-15T10:30:00.000Z"
}
]
}
events[].eventId— unique per event (SDK generatesevt_<8 hex><random>)events[].userId— the user's id (passed toNoChurn.init()or generated)events[].sessionId— the session (generated once per page load)events[].type— event type. Any string is accepted; the scoring rules only look at the ones they know (click,scroll,form_submit,pageview,billing_visit,js_error,session_start,session_end)events[].properties— arbitrary key/valueevents[].occurredAt— either an ISO timestamp or epoch ms
Batch limit: up to 20 events per request by default (the SDK batches automatically).
Response (200):
{
"ok": true,
"received": 20,
"deduped": 0,
"userId": "user_xyz",
"tenantId": "linux-managed"
}
received— events that were accepteddeduped— events that were skipped because they were already persisted (the SDK deduplicates automatically)rejected— (only present when some events failed validation) an array with the index and the validation error, so you know exactly which events were dropped and why
Errors:
401— invalid API key format (does not start withck_)403— the domain inX-Tenant-Domainis not on the tenant's allowlist
POST /v1/users/identify
Register (or claim) a user. The SDK calls this automatically when you pass a userId to NoChurn.init() or call identify().
curl -X POST https://api.nochurn.dev/v1/users/identify \
-H "Content-Type: application/json" \
-H "X-API-Key: ck_..." \
-d '{
"userId": "user_abc123",
"previousUserId": "anon_xyz",
"email": "[email protected]",
"preregistration": false
}'
Request body:
| Field | Required | Description |
|---|---|---|
userId | yes | The user id the SDK is using. |
previousUserId | no | The anonymous id the SDK generated before signup — events collected under that id are claimed by this user. |
email | no | The user's email address. |
preregistration | no | true if the SDK is creating a pre‑registration (the SDK saw an anonymous visitor before they signed up). |
Response (200):
{
"ok": true,
"userId": "user_abc123",
"domain": "app.your-company.com",
"registeredAt": "2026-01-15T10:35:00.000Z"
}
GET /v1/users/:userId/score
Get a user's current churn score.
curl https://api.nochurn.dev/v1/users/user_abc123/score \
-H "X-API-Key: ck_..."
Response (200):
{
"userId": "user_abc123",
"score": 72,
"tier": "high",
"signals": {
"activity_drop_d7": true,
"activity_drop_d3": true,
"billing_page_time": true,
"js_errors": false,
"login_decay": false
},
"computedAt": "2026-01-15T11:00:00.000Z"
}
score— 0–100, the sum of all signals that firedtier—low(0–39),medium(40–59),high(60–79),critical(80–100)signals— the five signals and whether each contributed to the scorecomputedAt— when the score was last computed (ornullif it has never been computed)
If the score has never been computed, it is computed on demand — the response includes the freshly computed score.
DELETE /v1/users/:userId
Delete a user and all their events. This is the GDPR/LGPD right to erasure.
curl -X DELETE https://api.nochurn.dev/v1/users/user_abc123 \
-H "X-API-Key: ck_..."
Response (200):
{
"ok": true,
"userId": "user_abc123"
}
The request deletes:
- The user's row in the
userstable - All events the user emitted
- The user's score (if any)
GET /health
Health check — used by Cloudflare Workers' automatic health monitoring. No authentication required.
curl https://api.nochurn.dev/health
Response (200):
{
"status": "ok",
"db": "ok",
"version": "0.1.0",
"time": "2026-01-15T11:00:00.000Z"
}
status—okordegraded(the database probe failed)db—okorerror
Error format
All errors return a JSON body:
{
"code": "VALIDATION_ERROR",
"message": "...",
"details": { ... }
}
| Code | HTTP status | Meaning |
|---|---|---|
VALIDATION_ERROR | 400 | The request body does not match the schema. |
AUTHENTICATION_ERROR | 401 | Invalid API key. |
AUTHORIZATION_ERROR | 403 | Domain not on the tenant's allowlist (SDK-only). |
NOT_FOUND | 404 | User not found. |
RATE_LIMIT_ERROR | 429 | Too many requests (not currently enforced — see below). |
INTERNAL_ERROR | 500 | Unhandled server error. |
Rate limiting (not enforced)
The configuration has RATE_LIMIT_PER_MINUTE but there is no middleware that enforces it yet. The SDK batches automatically (20 events per request), which already limits the request rate in practice. A future release will add proper throttling.