Idempotency
Retry a write safely with an Idempotency-Key header, and what a replay looks like.
A network error can hide whether a write reached the server. Send an Idempotency-Key header, and you can repeat the same request without doing the work twice. The second call gets the first answer back.
Which calls take it
Every POST, PUT, PATCH and DELETE under /api/v1 honours a non-blank Idempotency-Key, except password sign-in. These operations declare the header in the API reference, because a double run would cost money or change shared state:
POST /api/v1/billing/checkout-sessionsPUT /api/v1/billing/subscription/pricePOST /api/v1/price-alertsPOST /api/v1/referrals/me/referrerPUT /api/v1/economic-calendar/feed/filtersPOST /api/v1/economic-calendar/feed/reset
Checkout uses a durable provider key shared by retries of the same pending purchase. Other billing writes also use provider idempotency.
Send a key
Use a new random value, such as a UUID, for each action you mean to do once. Reuse it only to retry that same action.
curl -X POST "$BASE/api/v1/price-alerts" \
-H "Authorization: Bearer $TOKEN" \
-H "Idempotency-Key: 6f1c2b8e-3d4a-4e5f-9a0b-1c2d3e4f5a6b" \
-H "Content-Type: application/json" \
-d '{"symbol_id": "ed6621c0-5979-526b-8ba1-452bf82b80c0", "direction": "above", "target_price": "250.50", "channels": ["email"]}'What a retry gets
| Case | Answer |
|---|---|
| Same key, same method, path and body, first call finished | The stored answer: same status, body and headers, plus Idempotency-Replayed: true. Nothing runs again. |
| Same key, first call still running | 409 idempotent_request_in_progress. Wait, then retry. |
| Same key, same method and path, different query or body | 409 idempotency_key_reused. Use a new key for a new action. |
| Same key, different method or path | A separate record. The call runs as new. |
| Key older than 24 hours | Treated as a new key. The action runs again. |
A replayed error keeps its first body, but its correlation_id is the one of the retry.
Rules
- Scope. A key belongs to the signed-in caller. Two customers can use the same key without a clash. A call with no valid token is never stored or replayed: each retry runs as new.
- What counts as "the same request". The method, the path, the query parameters (names may be reordered; repeated values keep their order) and the exact body bytes. Send the body byte for byte the same on a retry.
- Limits. A key longer than 255 characters gets
400bad_request. A keyed body over 1 MiB gets413payload_too_large. - Answers that are not stored. These release the key, so a retry runs for real:
- a path or method the API does not serve;
- any
401or403answer; - any
5xxanswer; - any answer with a
Retry-Afterheader, such as429and503; - answers marked
Cache-Control: no-store, which carry credentials, such as OTP verify and token refresh.
- Deletion and permissions. Historical customer details are erased after account deletion; a staff replay can then return
410gone. Reusing a key after staff permissions change returns a conflict instead of replaying data from the earlier permission set. - Keep for 24 hours. Records live 24 hours. Retry within that time.
When to use it
- Always on the six operations listed above.
- On any other write you retry automatically, such as creating a watchlist.
- A
GETnever needs it. Reads are safe to repeat.
See Errors for which failures to retry.