Skip to main content

Idempotency

Networks retry, workers restart, and HTTP clients time out after the server has already stored the event. POST /api/v0/events/ gives you two independent tools against duplicates:

  • an envelope id, which makes the event itself unique, and
  • an idempotency key, which makes the response replayable for a day.

Event ids are unique per team and trail​

The pair (team, trail, id) is unique. Sending an envelope whose id already exists on that trail never writes a second row, and the response carries the event that is already stored. The same id on a different trail is a different event. When you omit id, the server assigns a ULID, so every request is a new event by definition.

Idempotency keys​

Send the key in a request header:

Idempotency-Key: retry-2026-09-29-0001

or, for one event inside a batch, in the envelope itself:

{"event": "invoice.voided", "trail": "billing", "organization_id": "org_acme", "idempotency_key": "retry-2026-09-29-0001"}
RuleDetail
Maximum length255 characters (IDEMPOTENCY_KEY_MAX_LENGTH)
A header longer than 255400 with code invalid_envelope, field idempotency_key
An envelope key longer than 255Truncated to 255, never rejected
ScopeOne key per team and trail — the same key on another trail is a different key
PrecedenceAn envelope's own idempotency_key beats the request header for that event, so an SDK can retry one buffered item without replaying the rest of the batch
Batch behaviourThe header applies to every event in the batch that does not carry its own key — send it only with a single event
Never send this header with a multi-event batch

A key is scoped to (team, trail), so the first keyless event on that trail claims it and every later keyless event on the same trail comes back duplicate carrying the first event's id. Those events are not written, and the batch still counts them as accepted, so the response says accepted: N while one row was stored. Give each event inside a batch its own id (or its own envelope idempotency_key) instead.

The replay window​

The first request that uses a key stores an idempotency record alongside the event. For the next 24 hours (IDEMPOTENCY_TTL), any request presenting the same key on the same trail gets the stored event back instead of a second write — 200 OK for a single event, and a duplicate status for that item in a batch. A duplicate counts as accepted in the batch totals.

After 24 hours the record is spent, the key is free again, and a retry takes the normal write path. If the event a key pointed at has since been deleted by a retention policy, the key is treated as unused and the retry writes a new event.

Retry-safe example​

Emit one event with both a producer-set id and an Idempotency-Key. If the client times out after the server stored the event, send the identical request again.

curl -X POST https://api.santati.io/api/v0/events/ \
-H "Authorization: Api-Key $SANTATI_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: retry-2026-09-29-0001" \
-d '{
"id": "01J9Z6K3M4QX8RT2VN5B7HCWDA",
"event": "invoice.voided",
"trail": "billing",
"created_at": "2026-09-29T14:03:11.482Z",
"organization_id": "org_acme_logistics",
"actor": {"type": "user", "id": "usr_123"}
}'
{
"id": "01J9Z6K3M4QX8RT2VN5B7HCWDA",
"trail": "billing",
"event": "invoice.voided",
"created_at": "2026-09-29T14:03:11.482000Z",
"received_at": "2026-09-29T14:03:11.913000Z",
"organization_id": "org_acme_logistics",
"actor": {"type": "user", "id": "usr_123", "name": "", "metadata": {}},
"targets": [],
"metadata": {},
"data": {},
"context": {},
"hash": "",
"schema_version": null
}

That response was the first one, a 201 Created. Re-running the same command within 24 hours returns 200 OK with that same stored event — the same id and the same received_at — and writes nothing.

Choosing between them​

Envelope idIdempotency key
Uniqueness windowPermanent24 hours
Retry result, single eventThe stored event is returned; no second row200 OK with the stored event
Retry result, batch itemAccepted with the stored event's idduplicate status
Use it forIdentifying the event itself, so a re-send can never duplicate itMarking one delivery attempt, including SDK-level buffered retries

Send both when you can. The id protects the data; the key makes the retry cheap to interpret.