Skip to content

Idempotency (Idempotency-Key)

A write that times out leaves a question: did the server run it or not? Sending the Idempotency-Key header makes the retry safe. A second call with the same key and the same body does not run again: it returns the first call’s response.

The strict protocol below applies to POST /v1/posts and POST /v1/sites/{site}/posts (post creation), where the header is optional. Without it, creation runs as usual and nothing is stored.

Other write routes have their own idempotency, with slightly different rules:

Route Header Difference
POST /v1/team/sites required (up to 255 bytes) Missing or blank: 400 IDEMPOTENCY_KEY_REQUIRED. Over 255 bytes: 400 IDEMPOTENCY_KEY_TOO_LONG. Only the 201 is stored. See Create sites.
POST /plan/keywords and POST /plan/edges required (up to 255 bytes), otherwise 400 Same key with another body is 409 IDEMPOTENCY_KEY_REUSED (not 422). Only the 201 is stored. See Planner writes.
POST /posts/{ref}/pending/promote optional (up to 255 characters), forwarded See Revisions and pending edits.
POST /v1/import does not use the header Each row gets a key derived from its content; re-importing the same row returns the same id marked replayed.

On other routes, do not rely on the header.

  • Any non-empty text, up to 255 bytes. The value is trimmed (surrounding whitespace is ignored).
  • Use one unique identifier per write intent, such as a UUID generated before the first attempt, and reuse the same value on every retry of that intent.
  • A key over 255 bytes on POST /v1/posts is rejected with 400 (bad_request, Idempotency-Key too long (max 255 chars)).

The record is identified by: credential + POST + route + Idempotency-Key. The body is not part of the key: it becomes a stored fingerprint (SHA-256) that is compared.

  • Per credential. The same key sent by another API key does not collide and never returns someone else’s response.
  • Per route. A site key uses the route /v1/posts. A team (company) key uses /v1/sites/{site-uuid}/posts, so the same Idempotency-Key on two sites is two distinct intents.
  • By body. The body is compared as the server read it (re-serialized JSON), so differences in raw whitespace do not count.
Situation Status error.code Headers What to do
New key normal response (201 on create) Proceed. The response is stored.
Retry, same key, same body, first call finished the stored status and body Idempotency-Replayed: true Use the response. Nothing was created again.
Retry while the first is still running 409 IDEMPOTENCY_IN_PROGRESS Retry-After: 1 Wait 1 s and repeat the same call.
Same key with a different body 422 IDEMPOTENCY_KEY_REUSED Client bug: use a new key for a new body. Do not retry.
Idempotency store down 503 IDEMPOTENCY_UNAVAILABLE Retry-After: 2 Wait and retry. The request was not executed.

Literal messages:

  • a request with this Idempotency-Key is still being processed
  • this Idempotency-Key was already used with a different request body
  • idempotency store unavailable; retry the same request shortly
HTTP/1.1 409 Conflict
Retry-After: 1
Content-Type: application/json
{"error":{"code":"IDEMPOTENCY_IN_PROGRESS","message":"a request with this Idempotency-Key is still being processed","request_id":"..."}}

The 503 is deliberate: with the key sent and the store down, the API does not run unprotected. Without the header none of this applies.

Window Value Meaning
“In progress” reservation 120 s The first call reserves the key before running. If it dies without finishing, the reservation expires by itself after 120 s and the key becomes free again.
Stored response 24 h Within this window, retrying with the same body returns the stored response. After it, the key is new.

5xx and 429 responses are not stored. The key is released at once and you may retry with the same Idempotency-Key. A validation failure before execution (for example a 400 or 422 on the body) also releases the key: nothing was created.

On POST /v1/team/sites and the planner routes, only the 201 is stored.

  1. Generate the key once per intent and keep it with the attempt.
  2. On timeout, network error, 5xx or 429: retry with the same key and body, honoring Retry-After (see Rate limits).
  3. On 409 IDEMPOTENCY_IN_PROGRESS: wait 1 s and retry; do not change the key, or creation may duplicate.
  4. On 422 IDEMPOTENCY_KEY_REUSED: stop and fix; the same key value was used for something else.
  5. On Idempotency-Replayed: true: treat it as success of the original call.

Retries also spend rate quota. See API v2 for the scopes of creation.