Developer guide: 5. Errors, pagination, rate limits, idempotency, async patterns, versioning

Problem+json errors, cursor pagination, rate limits, idempotency, async patterns and API versioning.

Embed
Preview of the card
<a href="https://lucidace.com/help/developer-guide-errors-and-limits"><img src="https://lucidace.com/help/_api/public/orgs/af34862a-c837-4478-8335-0505efe40459/spaces/2f4b888b-c4e6-488b-81bd-6e838fb12d2e/pages/85725099-088d-4436-97ef-9d798a7feca9/social-card.svg?v=3e7ae33eec8b" alt="Developer guide: 5. Errors, pagination, rate limits, idempotency, async patterns, versioning" width="600" height="315"></a>

5. Errors, pagination, rate limits, idempotency, async patterns, versioning

Errors are RFC 9457 application/problem+json on both hosts:

{"type":"https://lucidace.com/help/problems#validation","title":"Validation failed","status":422,
 "detail":"key: missing field `key`","errors":[{"field":"key","message":"missing field `key`"}],
 "instance":"/v1/projects/.../flags","request_id":"01a1c20f-56c8-760b-8ec8-f0861c97dc6a"}

Always read status and detail; errors[] appears on field-level failures. request_id (also the x-request-id header) is what to quote in a support request.

Status

type ends in

Meaning (verified behaviour)

400

validation

the request cannot be read or breaks a rule that no single field owns: unparsable JSON (Failed to parse the request body as JSON...), bad path id, bad limit/cursor, or a business-rule failure with only detail (for example public keys take no scopes). The capture host (/v1/capture, /v1/batch, /v1/s2s/batch) also uses 400 for every bad event

422

validation

well-formed JSON that does not fit the body: a missing or mistyped field, a bad timestamp, or an unknown field (for example secret in a webhook PATCH). errors[] names each field. This is the house rule on the API host; query-string errors stay 400 with errors[]

422

validation

the JSON parsed but a field is missing or has the wrong type: errors[] names every bad field

401

unauthenticated

missing or unknown key (missing or invalid credentials); a revoked or expired key says so (API key revoked, API key expired); the problem carries code: key_revoked, key_expired or key_unknown

403

forbidden

you can see the resource but lack the scope or role; the detail often names it

404

not-found

missing or inaccessible (wrong org, wrong project, session-only route with a key); also no such route for an unknown path, with did_you_mean (up to three METHOD /template routes ending the same way, e.g. POST /v1/projects names POST /v1/orgs/{org_id}/projects). The API has no /api prefix: /api/... on the API host answers a JSON 404 naming the /v1 path, never the app's HTML

405

method-not-allowed

wrong method for the route

409

conflict and specific types

a name or key already exists, or the state does not allow it: last-owner, sole-owner, running_change, plan-merge-conflict, forward-not-failed, deletion-started, missing-dependency, metric_name_taken, metric_drifted

413

payload-too-large on the capture host

batch over 1000 events, body or event too large

415

unsupported-media-type

wrong Content-Type

421

project lives in another region

429

rate-limited

rate limit or plan quota; Retry-After in seconds

5xx

internal

retry with backoff; deploys can answer 502/503 with a plain-text body

Other specific type suffixes you may see: approval-required (a change needs sign-off first), sso-required, seat-limit, org-limit, region-locked, ip-not-allowed, compliance / compliance-profile, share-password-required, report-cap-reached, ai-provider-required, audit-sink-required, replay-deleted, replay-erased, sensitive-key-destroyed, relationship_rejected, relationship_no_overlap, signup-restricted, captcha-failed. Branch on status and type, not on detail text. Treat the field-level split between 400 and 422 as informational: handle both as "fix the request".

Errors you can reproduce cheaply to test your client:

lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/flags" -d '{bad'              # 400 broken JSON
lc -X POST "$LUCIDA_API/v1/projects/$PROJECT_ID/flags" -d '{}'                # 422, errors[] names "key"
lc "$LUCIDA_API/v1/projects/$PROJECT_ID/events?limit=abc"                    # 400, errors[] names "limit"
lc "$LUCIDA_API/v1/projects/00000000-0000-0000-0000-000000000000/events"      # 404
curl -sS "$LUCIDA_API/v1/projects/$PROJECT_ID/events"                          # 401 no key

Pagination is cursor based on every list: ?limit=&cursor= returns {"data":[...],"next_cursor":"..."}. Pass next_cursor back as cursor; null means the last page. Cursors are opaque; never build them. Share lists (insights, dashboards, notebooks, replays, replay playlists, heatmaps, web), GET {p}/replay-playlists, GET {p}/namespaces and GET {p}/holdouts follow the same shape. events also returns newer_cursor and older_cursor. Check the shape once for any list not named here.

CUR=""; while :; do
  P=$(lc "$LUCIDA_API/v1/projects/$PROJECT_ID/event-definitions?limit=100${CUR:+&cursor=$CUR}")
  echo "$P" | jq -r '.data[].name'
  CUR=$(echo "$P" | jq -r '.next_cursor // empty'); [ -z "$CUR" ] && break
done

Rate limits (details in Rate limits). Every limited route answers an empty bucket with 429 and Retry-After (whole seconds); wait at least that long, then back off with jitter. Responses carry RateLimit-Limit (burst), RateLimit-Remaining and RateLimit-Reset: slow down as Remaining nears 0 instead of waiting for a 429. On the capture host with a public key the headers describe the tighter of the per-IP and the per-project bucket, because that is the one that throttles you first.

Family

Default

capture host events

1000/s per project, burst 2000 (a batch of N costs N); public keys also 100/s per client IP

flag evaluation

100/s per project, burst 200

management API

50 requests/s, burst 100, per key (or session, or IP)

query (POST {p}/query, SQL)

API keys 120 per minute per project; a key query reads at most 10 GiB

MCP

5/s, burst 20

sign-in, sign-up, reset, MFA, invites

per IP, email or user, fixed windows

Plan quotas (events per month) are separate and also answer 429, with a quota message. Self-hosted limits are set by the operator (LC_RATE, LC_API_RATE, LC_MCP_RATE).

Idempotency.

  • Events: delivery is at-least-once and never exactly-once. Give every event a UUID uuid and retry with the same one; a repeat is dropped. Retry only on network errors, 408, 429, 500, 502, 503, 504; never on other 4xx.

  • Backoff for capture: 1, 2, 4, 8, 16 s then 30 s steps, each randomised to 50 to 100 percent; honour Retry-After (cap 60 s). For a deploy, keep trying for about 10 minutes or keep events in your own outbox.

  • Management API: there is no generic Idempotency-Key header. For creates, look the resource up first (flag keys, metric names and similar are unique and answer 409). Key names are not unique, so list keys before minting to avoid duplicates. PUT and PATCH are safe to repeat; POST actions (start, rotate, run) are not.

Async (202) patterns. These calls return 202 and finish later; do not assume the change is visible in the same second.

Call

What you get

How to finish

POST {p}/query (and /query/forecast, /impact, /personas, /survival, POST {p}/sql)

202 {query_id, status} when slower than ~5 s

poll GET {p}/query/{query_id} until status is done; DELETE cancels. For the /query/* variants, repeat the same call after it finished (result is cached)

PATCH {p}/persons/{id}/properties, PATCH {p}/groups/{type_index}/{key}

202 {event_uuid, distinct_id} (PATCH {p}/persons/{id} returns the merged person)

applied through the pipeline; re-read after a few seconds

DELETE {p}/persons/{id}, POST .../persons/bulk_delete

202 with request ids

poll GET {p}/deletion-requests until done

POST {p}/persons/{id}/export

202 export id

poll GET {p}/dsar-exports/{id}, then /download

POST {p}/cohorts/{id}/recalculate, POST {p}/connectors/{id}/sync, POST {p}/export-schedules/{id}/run, POST {p}/health-scores/{id}/run

202

read the resource's state / last_* fields

Event capture

200 {"status":1}

queryable after seconds; replays and rollups after minutes

Config writes (PUT {p}/settings/*, PUT {p}/identity/rules, transformations)

200

gateway and worker caches refresh within 30 to 60 s

Versioning. Lucida-Version: YYYY-MM-DD pins the management API (section 1). Within /v1, changes are additive: ignore fields and enum values you do not know. A breaking change ships only behind a new version date; deprecated routes send Deprecation and Sunset headers and stay for at least six months. Nothing is deprecated today.

Timestamps are RFC 3339 with Z in responses. Some ClickHouse-backed rows (groups, identity graph) show YYYY-MM-DD HH:MM:SS.mmm text; parse both.

Updated