POST /api/v1/documents request without protection, you might create the document twice. An idempotency key makes the retry safe: sajn runs the request once, stores the response, and returns the stored response to every retry that uses the same key.
To make a request idempotent, send an Idempotency-Key header with a unique value:
- The header works on every method except
GET, such asPOST,PUT,PATCH, andDELETE. AGETrequest ignores it, because reading is already safe to repeat. - The key is any string of up to 255 characters. We recommend a UUID that you generate for each operation and store with it, so a retry after a crash reuses the same key. A longer key returns
400 VALIDATION_FAILED. - A stored response is kept for 24 hours. After that, the key is free, and a request with it runs again.
Send an idempotent request
The following samples create a contact with an idempotency key:Idempotent-Replayed is from a request that ran.
What a key matches
A key belongs to a workspace, so two API keys or OAuth apps that act in the same workspace share one set of idempotency keys. Generate keys that are unique across all of them, such as UUIDs. sajn compares a retry with the original by its method, its path, and its JSON body. The query string and the other headers aren’t compared.Which responses are stored
sajn stores the response that the request produced, so a retry gets the same answer even when it’s an error:2xxresponses are stored and replayed.4xxresponses from the request itself, such as404 NOT_FOUNDor409 ALREADY_EXISTS, are stored and replayed. A retry with the same key and body fails the same way, so fix the request and send it with a new key.5xxand429responses aren’t stored. sajn releases the key, so a retry with the same key runs the request again.
400 VALIDATION_FAILED for a body that doesn’t match the endpoint’s schema. You can correct the request and retry with the same key.
Every request with a key counts against your rate limits, including a replay.
When a retry replays a stored error, the requestId in its body identifies the original request, and the Sajn-Request-Id header identifies the retry. For more information, see Request IDs.
Errors
In API version
2026-09, a reused key returns the code INVALID_REQUEST, and a key in use returns ALREADY_EXISTS. For every other error code, see Errors. For a retry loop that honors Retry-After, see Retry with backoff.
