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

# Idempotency

> Retry a create safely with an Idempotency-Key

Network retries happen (a request times out, a function re-runs), and a blind retry of a create makes a second agent, or spends a second chat credit. An **`Idempotency-Key`** makes a retry replay the first response instead.

## Use it

Send any unique string on any `POST` under `/v1`; every one honours it (creates, publish and unpublish, knowledge adds, topic merges, asset uploads, the JSON chat turn):

```bash theme={null}
curl -X POST $WDY/agents \
  -H "Authorization: Bearer $WDY_KEY" \
  -H "Idempotency-Key: a1b2c3-create-support" \
  -H "Content-Type: application/json" \
  -d '{ "name": "Support" }'
```

Retry with the SAME key and the SAME body, and you get the first response back, unchanged, with:

```http theme={null}
Idempotent-Replayed: true
```

No second agent is created, and no second credit is spent.

## The rules

| Situation                                 | Result                                                         |
| ----------------------------------------- | -------------------------------------------------------------- |
| Same key, same body                       | The first response is replayed (`Idempotent-Replayed: true`).  |
| Same key, **different** body              | `422` `wondeya.idempotency.conflict`: a key names one request. |
| Same key while the first is still running | `409`.                                                         |
| The first request failed                  | Not stored; retry the same key freely.                         |

A key is scoped to your API key and kept for 24 hours. It is honoured in the JSON chat mode; a streamed (SSE) turn cannot be replayed, so the key is ignored there.
