My request fails with idempotency_key_reused
Owner, AdminLast checked 24 November 20262 min readArticle ID:
developers-key-reused-errorOn this page
A 422 idempotency_key_reused means you sent an Idempotency-Key that was already used for a different request. Use a new key for each new write.
What you see
A write answers 422 with:
{ "error": { "code": "idempotency_key_reused", "message": "This Idempotency-Key was already used for a different request." } }
Why it happens
- Your code reuses one key for different writes, for example a fixed key, or one made from something that repeats, like the customer's id.
- The retry isn't the same request. Skeduler compares the method, the URL (with its query string) and the body. The order of keys in a JSON object doesn't matter, but any changed value, or a changed order in a list, makes it a different request.
- The first try was refused with a 422 for a malformed body (for example
validation_failed), and you fixed the body but kept the key. That 422 is stored against the key like a success. A 422 the record's state caused, such as a payment on a draft invoice, isn't stored, so the same request can be sent again once you've fixed the cause.
How to fix it
- Make a new key for each new write, such as a random UUID, and store it with the write so a retry can send it again.
- When you retry, send exactly the same method, URL and body with the same key. Build the body once and reuse it, rather than building it again.
- After fixing a refused request, send it with a new key.
Keys belong to your app and are kept for 24 hours. After that, Skeduler forgets the key.
Other idempotency errors
| Status | error.code | Why | Fix |
|---|---|---|---|
| 422 | invalid_idempotency_key | The key isn't 1 to 255 printable ASCII characters, or it's missing on POST /invoices/{id}/payments, which needs one. | Send a valid Idempotency-Key header. |
| 409 | idempotency_in_progress | The first request with this key hasn't finished. A request that died part-way stops blocking the key after 10 minutes. | Wait a moment and retry the same call. |
| 409 | idempotency_replay_unavailable | The stored answer for this key can't be returned. | Retry with a new key. |
See Safe retries with idempotency keys.