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

# Idempotency

> X-Idempotency-Key: required on the analysis paths, synchronous and asynchronous, and the two different 409s

`POST /v1/transactions/analyze`, `/analyze/sandbox`, `/analyze/async`, and `/analyze/async/sandbox`
require the `X-Idempotency-Key` header on every request.

```
X-Idempotency-Key: <key-you-generate>
```

* It is **required** — without a stable key you cannot retry safely.
* It must be between **16 and 128 characters**, from the url-safe alphabet (`A-Z a-z 0-9 _ : . -`).
* The client generates and controls the key: you decide which transactions are "the same"
  by retrying with the same key, and which ones are new by using a different key.

Identity does not use this header. See [POST /verifications](https://docs.fraudeg.com/en/referencia/verificaciones.md).

## The behaviors

| Case | Result |
| - | - |
| First time the key is used | The transaction is scored and persisted |
| Same key, same payload | The stored response is replayed — it is not scored again |
| Same key, different payload | `422` |
| Same key, with a request still in progress | `409` (in flight) |
| Same key, but the stored response can no longer be read | `409` (unreadable response) — retry with a **new key** |
| Header missing or with an invalid format | `400` |
| Scoring unavailable at that moment | `503` with `Retry-After` — wait that many seconds and retry with the **same** key. If the transaction managed to be saved, you get its response; if not, it is scored. If it still shows as in progress, you get the in-flight `409`: wait and try again |

> [!TIP]
>
> The "same payload → replay" case is what makes it safe to retry a request that dropped
> on a network timeout: resend it with the same key and you get the original response, with no
> risk of duplicating the transaction.

## The two `409`s

They share HTTP `409` and `error_code` `DATA_CONFLICT`. You tell them apart by **`details`** (not
by `message`, which is the code's generic prose).

### 1. Request in flight

`details` contains `A request with this X-Idempotency-Key is already in progress`.

Retry later **with the same key**. It is not an error in your payload.

### 2. Unreadable previous response

`details` contains `The response stored for this X-Idempotency-Key was produced by an earlier version of the API and can no longer be replayed`.

When Fraudeg scores a transaction, it stores the response tied to your key so it can
replay it. If that response was written under an earlier version of the contract and no longer
matches the current shape, it cannot be returned as is.

What matters:

* **The transaction was scored and is stored.** Nothing was lost.
* **It is not an error in your request.** Your payload and your key were fine.
* **It is not scored again with that key.** Reprocessing it would produce a different result
  from the one already stored — exactly what idempotency exists to prevent.

The correct action is to **retry with a new key**. That produces a clean response
consistent with the current contract.

> [!TIP]
>
> This case is rare. If your `409` handling already reads `details`, it is enough to retry once
> with a new key when the text talks about replay, and with the same key when it talks about
> in progress.

See [/analyze errors](https://docs.fraudeg.com/en/referencia/analyze.md#errors) for the full envelope.

## On the asynchronous paths

The key follows the same rule and lives in **the same space** as on the synchronous path: a key already
decided by `/analyze` is replayed by `/analyze/async`, and vice versa. The difference is where
you see the result: the `202` only accepts the request, and the result arrives as a webhook (or you
read it from [`/analysis`](https://docs.fraudeg.com/en/referencia/estado-analisis)). With the same key you always get the
same `transaction_id`.

| Case | Result |
| - | - |
| Header missing or with an invalid format | `400`, before accepting anything |
| First time the key is used | `202`; then the `completed` webhook (or `rejected` / `failed`) |
| Same key already **decided**, same payload | `202`; another `completed` webhook arrives with the stored decision. It is not scored again |
| Same key already decided, different payload | `202`; `rejected` arrives with `code` `IDEMPOTENCY_CONFLICT`. There is no `422`: in this mode the rejection travels by webhook. The stored decision does not change |
| Same key on `/analyze/async/sandbox` and on `/analyze/async` | `rejected` / `IDEMPOTENCY_CONFLICT`: sandbox and live never share a key's decision |
| `REJECTED` or `FAILED` key | Fix the cause and resend with the **same** key: it is scored normally |
| `503` on send | The request was not accepted. Wait for `Retry-After` and retry with the **same** key |

A `DECIDED` key never changes. Each `202` generates its own webhook: a resend of a
decided key gets its own `completed`.

See [Asynchronous analysis](https://docs.fraudeg.com/en/integrar/analisis-asincrono.md).

Next step: [Fields](https://docs.fraudeg.com/en/integrar/campos.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.