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.
How it works
Section titled “How it works”- 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_progresswithRetry-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 withGET /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.
Retry safely
Section titled “Retry safely”- Create the key before you send the request, and keep it with the work it belongs to.
- On a timeout, a network error, a
5xxor a response withRetry-After, send the identical request again with the same key. - 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.
# 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 pipefailAPI="${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.