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

# Idempotent requests

> Send an Idempotency-Key header so that a retried create request is rejected with 409 instead of being processed twice.

A network timeout leaves you unsure whether Tilta received your request. Retrying a create request blindly can create the same buyer, order, invoice, or credit facility twice. An idempotency key lets Tilta recognise the retry: send the same key again and Tilta rejects the repeat instead of processing it a second time.

## Supported endpoints

The following endpoints accept an idempotency key:

| Endpoint | Reference |
| - | - |
| `POST /v1/buyers` | [Create a buyer](https://docs.tilta.ai/api-reference/buyers/create-buyer.md) |
| `POST /v1/orders` | [Create an order](https://docs.tilta.ai/api-reference/orders/create-order.md) |
| `POST /v1/invoices` | [Create an invoice](https://docs.tilta.ai/api-reference/invoices/create-invoice.md) |
| `POST /v1/buyers/{external_id}/facility` | [Request a credit facility](https://docs.tilta.ai/api-reference/facilities/create-facility.md) |
| `POST /v1/buyers/{external_id}/facility/increase` | [Request a facility increase](https://docs.tilta.ai/api-reference/facilities/request-increase.md) |

The header is optional. Without it, Tilta processes every request it receives.

## Sending a key

Generate a new random UUID for each operation and send it in the `Idempotency-Key` header. Keep the key with the operation so that a retry sends the same value.

```bash theme={null}
curl --request POST \
     --url 'https://api.tilta.io/v1/buyers' \
     --header 'Authorization: Bearer YOUR_API_KEY' \
     --header 'Content-Type: application/json' \
     --header 'Idempotency-Key: 3f2b8c1e-6d4a-4f0e-9b7a-2c5d8e1f4a90' \
     --data '{ ... }'
```

The key must be a UUID in the `8-4-4-4-12` hexadecimal form. Any other value is rejected with a `400` and the code `INVALID_IDEMPOTENCY_KEY`. Use a version 4 UUID from your language's standard library.

## How Tilta handles a repeated key

Each key belongs to one operation. Reusing a key for the same operation returns a `409` with the code `CONFLICT`, and Tilta doesn't process the request. Tilta keeps used keys indefinitely, so a key can't be reused later either. The same key on a different operation – for example, create a buyer and then create an order – counts as a separate key.

The `409` doesn't repeat the response of the original request.

## When a key counts as used

Tilta records a key once the request has passed authentication and validation, and before the request is processed:

* **Rejected with `401` or `400`.** The key isn't used. Fix the request and retry with the same key.
* **Accepted for processing.** The key is used, whatever the outcome. If processing then fails – for example with a `404`, a `409` for a resource that already exists, or a `500` – a retry with the same key returns a `409`.


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