Skip to main content
Network failures, timeouts, and retries are a reality of working with any API. Idempotency keys ensure that retrying a request never creates duplicate resources or performs an action twice.

How it works

When you include an Idempotency-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

On the first request, you get the standard 201 Created response:
If you retry the exact same request, you get the cached response with the replay header:
The 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 a 409 error:
This is a safety mechanism. It prevents bugs where the same key is accidentally associated with two different operations.

Which methods support idempotency?

Generating idempotency keys

The idempotency key can be any string up to 256 characters. Here are some recommended approaches:

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

Create the idempotency key once and reuse it across all retry attempts for the same logical operation:
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.
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:
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.
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: