How idempotency works
Idempotency is opt-in. To enable it, include anIdempotency-Key header on a write request:
Example
Idempotency-Key header are not deduplicated. Each one is processed independently.
Idempotency applies to write operations (
POST and DELETE). Read operations (GET) are already safe to retry, so they ignore the header. When a stored response is replayed, the API includes an Idempotency-Replayed: true response header so you can tell a replay apart from a freshly executed request.Creating an idempotency key
The key is a string that uniquely identifies a single logical operation. It must meet these requirements:
A random UUID v4 works, but it forces you to generate the key up front and store it alongside the order so you can reuse the exact same value on a retry.
A simpler approach is to derive the key deterministically from data you already have, such as the order ID combined with the request payload. Because the same inputs always produce the same key, a retry recomputes the identical key without you having to store anything:
Idempotency-Key header. If the request fails and you retry, recompute the key from the same order and payload, and the API recognises it as the same operation.
How repeated requests are handled
Keys are scoped per client and expire automatically 24 hours after first use. After that, the same key can be used again for a new operation.
A request that fails validation is not stored against the key. You can correct the payload and retry with the same key.
Conflicts and errors
If you receive a409 Conflict, the original request is still being processed. Wait for the number of seconds given in the Retry-After response header, then retry with the same key:
Example response
422 Unprocessable Entity means the key has already been used for a request with a different payload which is considered wrong. Either reuse the original payload, or generate a new key for the new operation.