Idempotency, Revisions and Pagination
Idempotency-Key on every write
Every POST and PATCH (except the signed events endpoint) needs an Idempotency-Key header, 1 to 255 characters, unique per logical write and the same on every retry of it.
curl -X POST https://replybrain.com/v1/cases \
-H "Authorization: Bearer $REPLYBRAIN_API_KEY" \
-H "Idempotency-Key: open-case:ada:2026-11-12" \
-H "Content-Type: application/json" \
-d '{"requester":{"email":"[email protected]"},"message":{"body_text":"I was charged twice."}}'
- The same key with the same request, at any time later: the recorded resource as it is now, with
Idempotent-Replayed: true. The write is not repeated. - The same key with a different request:
409 idempotency_conflict. - No key:
400 invalid_request.
ReplyBrain keeps each (organization, key) record for the life of the organization.
202 Accepted
Some writes answer 202: a context query, a run, a cancelled run, an action dispatch or reconcile, and the events endpoint. It means recorded, never sent or done. Poll the Location header's resource, or read the event stream.
ETag and If-Match
Cases, needs and commitments carry an ETag. A PATCH must send it back:
curl -X PATCH https://replybrain.com/v1/cases/$CASE_ID \
-H "Authorization: Bearer $REPLYBRAIN_API_KEY" \
-H "Idempotency-Key: rename:$CASE_ID:1" \
-H "If-Match: \"3f1c…\"" \
-H "Content-Type: application/json" \
-d '{"case":{"title":"Double charge"}}'
No If-Match: 428 precondition_required. A different one: 412 stale_revision with details.current_etag. Read again, then decide.
Approving an action is bound the same way, by its action_revision and arguments_digest in the body.
Pagination
Lists (/cases, /cases/{id}/messages, /capabilities, /waits) answer:
{ "data": [ … ], "next_cursor": "eyJfcmFpbHMi…" }
limit: 1 to 100, default 50.- Pass
next_cursorback ascursor.nullmeans the last page. - Order is stable (by creation; messages by when they happened). A cursor is bound to the key and the route and lasts one hour; after that,
410 cursor_expired: start again without one.
The event stream
GET /v1/events is different: its cursor parameter is after, limit defaults to 100, and next_cursor is always present, because the stream does not end. Read until a page is empty, store the cursor, and come back later with after=<cursor>. Deduplicate by event id.
| Query | Starts at |
|---|---|
| (none) | The start of the retained stream. |
from=now |
Only what happens from now on. |
after=<cursor> |
Right after the page that gave the cursor. |
run_id=<id> |
Only that run, its plans and their actions. |
An event cursor lasts seven days. An expired one answers 410 cursor_expired with details.snapshot_cursor, taken at that moment: read the current state of what you track, then resume from the snapshot cursor, deduplicating by id. Nothing that happened in between is lost.
{ "id": "…", "type": "need.identified", "occurred_at": "2026-11-12T09:30:04Z",
"object": { "type": "…", "id": "…" }, "revision": 1, "causation_id": "…", "correlation_id": "…", "data": { } }