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

# Idempotency

> Retry a submission without starting the same work twice

An idempotency key identifies one request. Send it with the first attempt and
reuse it if you need to retry, so Sail can return the existing request instead
of starting another generation or batch.

## Supported endpoints

| Endpoint | Header |
| - | - |
| `POST /v1/responses` | `Idempotency-Key` |
| `POST /v1/chat/completions` | `Idempotency-Key` |
| `POST /v1/messages` | `anthropic-idempotency-key` |
| `POST /v1/batches` | `Idempotency-Key` |

For example:

```http theme={null}
Idempotency-Key: 9a8b1fc3-b9da-4b14-bb9b-98978c814b2d
```

## Using a key

* Generate a unique key, such as a UUID, for each new request.
* Keys must be at most 255 bytes. A UUID fits within this limit.
* Keep the same key, body, endpoint, and Sail API key for every retry.
* Reusing a key with a different body returns HTTP `400`.
* Keys are scoped to your organization and API key. Switching API keys does
  not reuse the original submission.

A completed result is returned again when it is
[still available](#expiration). A request without an available completion can
return HTTP `409` with `Retry-After`. Wait before retrying with the same key.
Using a new key would submit new work.

For background requests, save the response ID and poll it for completion.
See [Retrying requests](https://docs.sailresearch.com/retries.md) for retry delays, timeouts, and streaming
errors.

## Expiration

* Keys last 24 hours. After that, reusing a key starts new work, which is
  billed again.
* A result can expire 10 minutes after Sail first returns it, or 24 hours
  after the request if it is never read. Reading it again does not extend this.
* An expired result returns HTTP `404` from both `GET` and a retry with the
  same key. The retry does not start new work.

Read each result once and save it.
