Skip to content

Idempotency

Send Idempotency-Key: <unique string> on every POST, PATCH and DELETE. A UUID is a good key; up to 128 printable characters are allowed.

  • The same key with the same body, from the same credential, returns the first response again, including an error, without acting again.
  • The first response is kept for 30 days, and for 400 days for paid starts.
  • The same key with a different body is 409 idempotency_key_reused.
  • If the first request with that key is still running, the answer is 409 request_in_progress with Retry-After. Send the identical request again after that time.
  • If the outcome is uncertain, the answer is 409 outcome_unknown. Send the identical request again with the same key: it never runs twice.
  • A key too old to replay is 409 idempotency_key_expired. Look the result up instead, for example with GET /v1/generations.

Without a key, a request is not protected against retries: a timeout followed by a retry can start two generations. The SDKs always send one.

  1. Create the key before you send the request, and keep it with the work it belongs to.
  2. On a timeout, a network error, a 5xx or a response with Retry-After, send the identical request again with the same key.
  3. Use a new key only for a new request.

See it with a free request: the same quote request sent twice with one key returns the same quote.

replay.sh
# Sends the same quote request twice with one Idempotency-Key: the second answer is the first one replayed,
# with the same quote ID. Quotes are free, so this is a safe way to see it. Needs jq.
set -euo pipefail
API="${HL_API_BASE:-https://api.halationlab.ai/v1}"
KEY="$(uuidgen)"
BODY='{ "model": "flux.2-pro", "input": { "prompt": "A red ceramic mug" } }'
quote() {
curl -sS --fail-with-body "$API/quotes" \
-H "Authorization: Bearer $HALATIONLAB_API_KEY" \
-H "Idempotency-Key: $KEY" \
-H "Content-Type: application/json" \
-d "$BODY" | jq -r .id
}
first=$(quote)
second=$(quote)
echo "first: $first, second: $second"
[ "$first" = "$second" ]

The error-handling helper reuses one key for every attempt of a request.