# Idempotency

Networks fail. A client that times out does not know whether its request arrived. `Idempotency-Key` lets it retry safely:
the retry gets the first answer back instead of making a second post.

## REST

Send the header on every `POST`, `PATCH` and `DELETE`:

```http
Idempotency-Key: 6f1d1c1e-2b0b-4c3e-9a55-0d6a3f0e8a11
```

- 1 to 255 printable ASCII characters without spaces (a UUID is ideal). Anything else is 400 `invalid_idempotency_key`.
- Kept for 24 hours, per workspace and key.
- The same key with the same request replays the first answer, status and body, with the header
  `Idempotent-Replayed: true`.
- The same key with a different request is 422 `idempotency_key_reused`.
- The same key while the first request is still running is 409 `idempotency_key_in_progress`. Wait a moment and retry.
- A request that failed with a server error (5xx) is not remembered, so a retry runs again.

Without the header a request still runs, but a retry is not protected. Use a new key for each intended action and
reuse it only to retry that action.

## MCP

MCP has no headers a tool can set, so every write tool takes a required `idempotency_key` argument. It works the same way
(same 24 hours, same rules, same table). Use a new UUID for each intended action.

## Webhook secrets

Replaying `POST /webhooks` returns the webhook with `secret: null`: the signing secret is shown only in the first answer
and is never stored in the replay. If you lost the secret, delete the webhook and create it again.

Likewise a replay of `POST /media/uploads` returns the upload with `upload_url: null`: the URL is a credential and is not
kept. If you lost the answer, create a new upload.

See [Webhooks](https://postaki.io/docs/webhooks/).
