Idempotency-Key makes sending it again safe: we tie the key to the first request, and every retry with the same key returns the result of that request instead of creating another.
Which requests need a key
Choose a key
- Generate one key for each order, application or allocation, such as a UUID.
- Save it with your own record before you send the request, so a crash on your side can’t lose it.
- Send the same key on every retry of that request.
- Use 1 to 255 printable ASCII characters, with no spaces. We compare keys byte for byte.
- Send the header exactly once. Without it you get
400 missing_required_field, and with two you get400 invalid_request, each withparamset toIdempotency-Key.
What a retry returns
We compare the values after we read them, so a retry with different spacing or field order is the same request.
account and symbol are compared without regard to letter case. A retry that adds, drops or changes client_reference is a different request.
A retry answers from what we hold for the key, even when that’s a refusal. A retried order that’s now rejected returns 422 order_rejected, and one that was never sent returns 503 order_not_sent, whatever the first answer was. Applications and allocations work the same way.
If the first request’s outcome was not recorded, a retry returns 200 with the order, application or allocation in sending until it resolves. A new key for an identical order is refused with 409 similar_order_unresolved, and for the same allocation with 409 similar_allocation_unresolved. See Handle an uncertain result.
We look up the key before we check the account or contact the broker, so a retry gets its answer even when the broker can’t be reached.