> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Retry requests safely with idempotency keys

> Send an Idempotency-Key header so a retried Elastly API request returns the first result instead of acting twice, and handle each idempotency error.

A network failure can leave you unsure whether a request reached Elastly. An idempotency key lets you send the same request again without acting twice: the API runs the first request and returns its stored response to every retry. This page covers which endpoints take a key, how keys are matched and the errors they return.

## Send a key

Send an `Idempotency-Key` header with a value you generate, such as a UUID. The value is 1 to 255 printable ASCII characters with no spaces. Any other value is refused with `400` and `invalid_idempotency_key`.

```bash theme={null}
curl -X POST https://api.elastly.ai/v1/price \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: 5f0c9a52-3d1e-4b7a-8c6f-2e9d0a1b4c73" \
  -d '{"buyer":{"kind":"customer","customerId":"3c1e9b7a-52d4-4f0e-8a6b-9d2c7e1f0a34"},"currency":"USD","lines":[{"sku":"AX-2201","quantity":"40"}]}'
```

Use a new key for each new request and the same key for each retry of that request.

## Which endpoints take a key

| Endpoints | Idempotency key |
| - | - |
| Price one line, price a quote, report outcomes | Optional |
| Create or update catalog items, customers and documents | Required |
| Create a bulk import, start a bulk import | Required |
| Every read, and the file upload of a bulk import | Not used |

A request to an endpoint that requires a key and sends none is refused with `400` and `idempotency_key_required`.

## How a retry is answered

A key belongs to the API key that sent it and to one endpoint. The API also records the request body and the API version with it.

| Retry | Result |
| - | - |
| Same key, same body, first request finished | The stored response, with the header `Idempotent-Replayed: true` |
| Same key, same body, first request still running | `409` with `idempotency_request_in_progress`. Wait and retry |
| Same key, different body or version | `422` with `idempotency_key_reused`. Use a new key for a different request |

The API keeps a key and its stored response for at least 30 days. After that, the same key starts a new request.

## Retry with backoff

Retry a request that failed with a network error, `409` with `idempotency_request_in_progress`, `429` or `503`. Wait between attempts and honour the `Retry-After` header when the response carries one. See [Rate limits](/docs/developers/rate-limits.md) and [Errors](/docs/developers/errors.md).


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