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

# Idempotency

> Learn how the API prevents duplicate requests

An API call or operation is idempotent if it always produces the same outcome, regardless of how many times it is executed. This ensures that accidental duplicate calls do not cause unintended consequences.

Our API implements **idempotency** as per the [RFC Draft Specification for Idempotency](https://datatracker.ietf.org/doc/html/draft-ietf-httpapi-idempotency-key-header).

We enable idempotency by allowing API operations to include an idempotency key as a header in the request. The key is a unique string created by the client and is used by the server to recognise subsequent retries of the same request. It acts as a safeguard against accidental duplicate calls that could lead to undesired outcomes. The method for creating unique idempotency keys is flexible, but we recommend using UUIDs or other randomly generated strings.

To execute an idempotent request, include an additional element called `Idempotency-Key` in the request headers of any POST or PUT requests.

```http theme={"system"}
Idempotency-Key: 2f227800-f0c9-4000-a798-ca2e8b796dcc
```

Idempotency works by saving the resulting status code and body of the first request made for any given idempotency key, regardless of whether it succeeded or failed. Subsequent requests with the same key return the same result, status code and a response header of `Idempotent-Replayed` set to `true`.

Keys are removed from the system automatically after 24 hours. A subsequent request with the same key after its expiry period, will be treated as a new request.
