> ## Documentation Index
> Fetch the complete documentation index at: https://exchanger-api.iexexchanger.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Retry a write without duplicating it

> Recover an operation after a timeout with Idempotency-Key. Learn how long keys are retained and which operations store durable receipts.

If the connection drops while your client creates an order, the exchange may have accepted it. Check the operation's state first. To retry, send the same `Idempotency-Key` and the same request with a fresh signature.

## Send a request with an operation key

1. Generate a UUID or another unique key 8 to 191 characters long. Use ASCII letters, digits, or the characters `.`, `_`, `:`, and `-`.
2. Before sending, save the key, HTTP method, path, query parameters, and original body. Keep the same bytes for JSON retries. For a supported multipart upload, resend a single `file` with the same bytes, client file name, and MIME type. The multipart boundary can change.
3. Send `Idempotency-Key` as a header and include it in the [canonical signing string](https://exchanger-api.iexexchanger.com/en/start/authentication.md). Keep a stable `X-Correlation-Id` if you want to trace attempts for the same operation.

Run the example against a test exchange. Save a checked order payload as `order.json` and use the [HTTP request signing script](https://exchanger-api.iexexchanger.com/en/start/quickstart.md). Substitute the key you saved for that order.

```bash theme={null}
node request.mjs POST '/api/v3/private/exchange/orders' \
  --json order.json \
  --idempotency-key 'create-order-7c441477-adb9-49c9-822f-8d5f2552809d'
```

To retry, run the same command with the same file and key. Sign with a new `X-Api-Nonce` and current `X-Api-Timestamp` even when the body is unchanged. When you rotate an API key within the same integration, keep the operation's `Idempotency-Key`. Its scope is the account and integration. If you recreate the integration, look up the original operation by its saved ID first.

## How long the API keeps a key

The default retention period for ordinary receipts is 24 hours. The exchange configures this period. After it ends, reusing a temporary key can start a new operation. Check the saved order, receipt, payout, or subscription ID before retrying outside that window.

| Operation | What a replay can return |
| - | - |
| `POST /api/v3/private/exchange/orders` | If an order was created with a key, the API keeps a durable receipt. A replay returns `201` with the original creation result and metadata for the new request. |
| `POST /api/v3/private/exchange/orders/{order}/receipts` | If a receipt was uploaded with a key, the API keeps a durable reference to the receipt. A replay returns `201` with current metadata for the same receipt. If the receipt was deleted or the order no longer belongs to the caller, the replay returns `404` and the key stays reserved. |
| `POST /api/v3/private/partner/payouts` | The key is required. Once the HTTP response expires, the API can return the existing payout with `200` and `result.replayed: true`. A replay of the saved response can retain the original `201`. |
| Other private writes | Keep a separate key for confirmation, cancellation, upload commit, subscription creation, and subscription secret rotation. Check each operation in the [API reference](https://exchanger-api.iexexchanger.com/en/api.md). |

## Handle the retry response

| What you received | What to do |
| - | - |
| `Idempotency-Replayed: true` | Use the returned result. Send a separate GET to read the resource's current state. |
| `409 idempotency_in_progress` | The first attempt is still running. For order creation, wait for `Retry-After`. For other operations, check `error.details.locked_until` when present. Retry with the original key and a new HMAC signature. |
| `409 idempotency_conflict` | The key belongs to different input or a result that the server cannot serve for this request. Find the original operation. Create a new key for a new write. |
| `422 invalid_idempotency_key` | Correct the key format. For a partner payout, make sure you supplied the header. |
| Timeout, connection failure, or `5xx` | Treat the outcome as unknown. If you have the resource ID, check its current state. If you still need to retry, keep the original key and request and sign it again. |
| `429` or `503` | Follow the [error and limit rules](https://exchanger-api.iexexchanger.com/en/guides/reliability/errors.md) to choose when to retry. Keep the same key. |

A temporary receipt can hold a completed `4xx` response. Before resubmitting corrected input, check the resource and assign a separate key to the corrected operation. If the quota is exhausted, the API can still return an existing successful receipt after checking the signature, access, and parameters. Rate limits still apply.

> [!NOTE]
>
> The incoming [webhook event ID](https://exchanger-api.iexexchanger.com/en/guides/reliability/webhooks.md) deduplicates notifications. Store it separately from the outgoing HTTP request key.

> [accordion] Prompt for recovering a write
>
> ```text theme={null}
> Add recovery for an Exchanger API timeout on [METHOD_AND_PATH] in a [STACK] client. Check the operation reference for Idempotency-Key support, whether the header is required, and how long the result is retained. Use direct HTTP. If safe replay is unconfirmed, implement reconciliation or an operator handoff.
>
> Persist the operation key and original request before the first send. Treat a lost response as an unknown outcome. Read the resource when its ID is available. For supported retries preserve the method, path, parameters, body and key. Sign each attempt with a current timestamp and fresh nonce. Wait on idempotency_in_progress and stop on idempotency_conflict. Bound the retry count. After an ordinary receipt expires, the same key can start a new operation.
>
> Use a local HTTP fixture and test secret. Simulate the server committing a write and losing its first response. Show that the test observes one business operation, the same key on replay, different nonces and valid signatures. Include a conflicting request and an expired receipt with an unknown outcome. Run the checks without production credentials or live operations.
>
> Documentation
> https://exchanger-api.iexexchanger.com/en/guides/reliability/idempotency
> https://exchanger-api.iexexchanger.com/en/start/authentication
> https://exchanger-api.iexexchanger.com/en/guides/reliability/errors
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.