# Idempotency

Networks fail. To retry a paid call safely, send an `Idempotency-Key` header:

```
Idempotency-Key: 7c9e6679-7425-40de-944b-e07fc1f90ae7
```

Supported on every billable POST: `/speech-to-sign`, `/speech-to-sign/realtime`,
`/speech-to-sign/studio`, `/speech-to-sign/gloss`, `/speech-to-speech` and
`/avatars` (`/speech-to-sign/avatars`). Optional but strongly recommended.

## Rules

| Situation | Result |
|---|---|
| No header | The request runs normally. |
| First use of a key | Runs normally. A **2xx** response is stored for **24 hours**. Any other status frees the key, so you can retry with it. |
| Same key, same endpoint, same body, within 24 h | The stored response is returned with `Idempotent-Replayed: true`. Nothing runs, **nothing is charged**. |
| Same key while the first request is still running | `409 idempotency_in_progress`. Retry in a second or two. |
| Same key with another endpoint or a different body | `422 idempotency_key_reused`. |
| Invalid key (not 1–255 printable ASCII characters) | `400 invalid_idempotency_key`. |

Keys are scoped to your account: two accounts can use the same key without clashing.

## What counts as "the same body"

- JSON bodies are compared as **canonical JSON**: object keys are sorted at every
  level, so `{"a":1,"b":2}` and `{"b":2,"a":1}` are the same request. Values, array
  order and types must match.
- Multipart uploads (`POST /avatars`, and `audio`, `video` and `photo` files on
  `POST /v1/jobs`) include the **SHA-256 of each uploaded file** in the fingerprint, so a
  different file with the same key is `422 idempotency_key_reused`.

## Tips

- Use a fresh UUID per logical operation and keep it for every retry of that operation.
- Replayed responses still contain the original `usage`; the wallet is not charged again.
- Clip URLs in a replayed realtime response are the original ones; check `expires_at`.
