# Idempotency and retries

> How to make a request safe to send twice, and how to retry without making a mess.

Type: Guide. Updated 2 December 2026. Page: https://www.colossium.cloud/docs/idempotency

## The problem

Networks fail in the middle. You send a request, the connection drops, and you do not know whether it arrived. If you send it again and it had arrived, you have asked for two databases. Idempotency removes the doubt: you attach a key, and sending the same key again returns the original instead of making a second one.

## The Idempotency-Key header

`POST /requests` requires an `Idempotency-Key` header of 8 to 120 characters.

| Case | What happens |
| --- | --- |
| A new key | `201 Created`, and the request is made. |
| A key already used in your organisation | `200 OK` with the **original** request and the header `Idempotent-Replayed: true`. Nothing new is made. |
| A missing or too short key | `400 idempotency_key_required`. |

> **Important.** The key identifies the **intent**, not the body. If you reuse a key with a different body, you get the first request back, not an error and not a new request. Use a new key for a new intent.

Keys are unique across your whole organisation, not per token, and they last as long as the request does.

## Choosing a key

Build the key from what identifies the intent, so a retry or a rerun produces the same key:

- A pipeline run and the thing it makes: `gha-8231904552-orders-db`.
- A release and a service: `release-2026-12-02-orders-db`.
- A tool's arguments: `provision-orders-databases.create-orders-db`.

A random key (a UUID) is also fine when you want every call to be a separate intent, but then a retry after a crash is a new request unless you saved the key before sending.

> **Data protection.** A key is stored, shown in the console and written to logs. **Never build it from personal data**: no names, email addresses, account numbers or anything that identifies a person.

## What to retry

| Response | Retry? | How |
| --- | --- | --- |
| Network error or timeout | Yes, if it is a GET or a POST with a key | Back off, then send the same request again. |
| `429 rate_limited` | Yes | Wait for `Retry-After`. |
| `500`, `502`, `503`, `504` | Yes, if it is a GET or a POST with a key | Back off. |
| `400`, `401`, `403`, `404`, `409` | No | The request will not work as sent. Fix it. |
| A POST without a key (`/projects`) | No | Check what exists with a GET, then decide. |

Use **exponential backoff with jitter**: wait a random time up to 0.5 s, then 1 s, 2 s, 4 s, capped at 30 s, giving up after about four tries. Jitter stops many clients retrying in step. When a `Retry-After` header is present, wait at least that long. The reference clients do all of this.

> **The one rule.** Never retry a POST that has no idempotency key after a timeout. You do not know whether it was made.
