Skip to main content
A request can time out after we have acted on it. An 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 get 400 invalid_request, each with param set to Idempotency-Key.
Keys never expire, and each belongs to one request for good. Your keys are separate from other partners’. Orders, applications and allocations also keep their keys apart: the same key on an order and on an allocation names two different requests.

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.

When to use a new key

Whether you can reuse a key depends on whether we stored the request.
After a timeout or a 5xx, never retry with a new key unless the error code tells you to. A new key is a new request, and for an order that means a second order at the exchange.