# Idempotency and retries

## Idempotency-Key

Writes whose double execution would cost money or send a message accept an `Idempotency-Key` header (up to 255 characters; longer is a `400`, never cut).

| Situation | Answer |
|---|---|
| First call with a key | Runs. A success is stored for 24 hours, and so is a 502 `creation_status_unknown` (it may have gone); any other failure releases the key. |
| Same key, same body, after it finished | The stored answer, with `Idempotent-Replayed: true` |
| Same key, still running | `409 idempotency_conflict` + `Retry-After` |
| Same key, different body | `422 idempotency_key_reused` |
| After 24 hours | Runs as a new request |

An automation sends each step with its own key; one key never covers a whole run. Keys are scoped to your brand and the operation. On the MCP server every write tool takes an optional `idempotencyKey` argument; leave it out and one is derived from the call.

## When to retry

- Retry `408`, `429`, `5xx` and network errors. Never retry any other `4xx`: the answer will not change.
- Always wait the `Retry-After` seconds. On a `429` without it, back off exponentially.
- **Never retry a POST that timed out on your side with a new key.** It may have completed. Retry it with the SAME `Idempotency-Key`; a replay answers with the first result.
- `502 creation_status_unknown` means a create may or may not have happened at the provider. Read before you retry.
- `400 platform_not_supported` and `412 platform_scope_missing` never succeed as they are: change the channel, or reconnect the account with the missing permission.
- Send one `X-Request-Id` per logical call and reuse it on every attempt.

## How it behaves

- The key is the retry's identity: the same key and body always return the first result for 24 hours.
- A refusal (a `4xx`) releases the key, so the same key can run again once you fix the request.
- Keys belong to your brand and the operation. Another brand, or another operation, never sees them.

## If it fails

| Answer | Cause | Fix |
|---|---|---|
| `409 idempotency_conflict` | The same key is still running | Wait `Retry-After` seconds and retry with the same key. |
| `422 idempotency_key_reused` | The key was used with a different body | Use a new key for a different request. |
| `502 creation_status_unknown` | The platform may or may not have done the write | Read the resource, or wait for its webhook, before deciding. Never send it again with a new key. |
| `400` on the key | The key is longer than 255 characters | Shorten it. It is never cut for you. |
| `429` or `503` | Too many requests, or busy | Wait `Retry-After` and retry with the same key. |
