How it works
When you include anIdempotency-Key header on a POST or PATCH request, the API remembers the response for that key. If you send the same request again with the same key and body, the API returns the cached response instead of processing the request again.
1
First request
The API processes the request normally, creates the resource, and caches the response. The response is associated with the idempotency key and the SHA-256 hash of the request body.
2
Retry with same key + same body
The API detects the duplicate key, verifies the body hash matches, and returns the cached response immediately with an
Idempotent-Replayed: true header. No new resource is created.3
Retry with same key + different body
The API detects the duplicate key but the body hash does not match. It returns a
409 Conflict error with code idempotency_conflict. This prevents accidental misuse of keys.Cache TTL
Idempotency keys are cached for 24 hours from the first request. After 24 hours, the key expires and can be reused.Only successful responses (HTTP 2xx) are cached. If the original request failed with a 4xx or 5xx error, the key is not consumed and you can retry with the same key.
Using idempotency keys
With curl
201 Created response:
id is identical — no duplicate was created.
With JavaScript / TypeScript
With Python
Conflict responses
If you reuse an idempotency key with a different request body, the API returns a409 error:
Which methods support idempotency?
Generating idempotency keys
The idempotency key can be any string up to 256 characters. Here are some recommended approaches:- UUID (recommended)
- Deterministic key
- Request hash
Idempotency key scoping
Idempotency keys are scoped to your organization. Two different organizations can use the same key string without conflict. Within your organization, each key can only be used once per 24-hour window.Best practices
Generate the key before the first attempt
Generate the key before the first attempt
Create the idempotency key once and reuse it across all retry attempts for the same logical operation:
Do not reuse keys across different operations
Do not reuse keys across different operations
Each logical operation should have its own idempotency key. Reusing a key from a previous (different) operation will result in either a cached response from the old operation or a
409 conflict.Handle 409 conflicts gracefully
Handle 409 conflicts gracefully
If you receive an
idempotency_conflict error, it means the key was already used with a different request body. Generate a new key and retry:Check the Idempotent-Replayed header
Check the Idempotent-Replayed header
When the
Idempotent-Replayed: true header is present, the response is a cached replay. This can be useful for logging and debugging to distinguish between fresh and replayed responses.Use deterministic keys for exactly-once semantics
Use deterministic keys for exactly-once semantics
If your system processes events from a queue (e.g., Kafka, SQS, BullMQ), derive the idempotency key from the event ID or message ID. This ensures that processing the same event twice never creates duplicate resources:
HypeDuel