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

# Idempotency

> Retry order creation safely with an Idempotency-Key.

Network errors and timeouts can leave you unsure whether an order was created. Send an `Idempotency-Key` header with `POST /orders`, and retry with the same key and body. AGS creates the order at most once.

```
Idempotency-Key: 9f8c2b1e-order-1042
```

Use a unique value for each order, such as a UUID or your own order ID, up to 255 characters. Keys are separate for each app and customer.

## Responses

| Situation | Response |
| - | - |
| First request with the key | `201` with the new order |
| Retry with the same key and body | `200` with the original order, and the header `Idempotent-Replayed: true` |
| Same key with a different body | `422` with `idempotency_key_reused` |
| Retry while the first request is still running | `409` with `idempotency_key_in_use`. Wait a moment and retry |

The body comparison ignores key order and whitespace, so a retry only needs the same values.

## Rejected orders

If an order is rejected, with `validation_failed` or `order_rejected`, the key isn't used up. Fix the request and retry with the same key.

If a request fails on our side before the order is created, the key is released, so a retry with it creates the order. If our server stops mid-request, the key is released after a minute.

> [!NOTE]
>
> Without an `Idempotency-Key`, every request creates a new order.


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