Idempotency
Retry FLORA API requests safely with the Idempotency-Key header and the Technique-run idempotency_key, without starting or paying for duplicate runs.
When a POST fails mid-flight, you can't tell whether FLORA received it, and a blind retry can start the same run twice and bill it twice. Idempotency keys make retries safe. FLORA has two kinds, and they behave differently:
Idempotency-Key header
idempotency_key body field
Works on
Every mutating request (POST, PUT, PATCH, DELETE)
POST /techniques/{slug}/runs only
Remembered for
2 hours
As long as the run exists
Scope
Workspace + endpoint + path parameters
Workspace
A repeat gets
409 idempotency_duplicate
The original run, with its current status
Released if the first request fails
Yes
Not applicable: a failed request creates no run
The Idempotency-Key header
Send any string you choose in the Idempotency-Key header:
curl -X POST https://app.flora.ai/api/v1/generate \
-H "Authorization: Bearer $FLORA_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: spring-launch-hero-01" \
-d '{
"type": "image",
"prompt": "A ceramic mug on a sunlit table",
"workspace_id": "ws_abc123",
"project_id": "prj_abc123"
}'How it works:
FLORA records the key for two hours, scoped to your workspace, the endpoint and its path parameters. The same key on a different endpoint, or aimed at a different project or folder, is a different request.
A second request with the same key in that window is rejected with
409 idempotency_duplicate. FLORA doesn't replay the first response, and it doesn't compare bodies: a different body with the same key is still a duplicate.If the first request fails (any non-2xx response), FLORA releases the key, so a retry with the same key runs normally.
Concurrent requests with the same key don't both run: one proceeds and the other gets
409 idempotency_duplicate.
So a 409 idempotency_duplicate means "the first one got through". Don't retry with a new key; look up what it created instead. For a generation, list the project's newest generations:
POST /generate with quote: true ignores the header, so you can refresh an estimate whenever you like.
Batch uploads
POST /assets/reserve and POST /assets/complete follow the same rules, with one addition. If every entry in the batch was rejected (input_validation_error, not_found or forbidden), nothing was written, so FLORA releases the key and you can resend the same request with it. Any other batch keeps its key, even if an entry failed with unknown_error, because that write may have landed. Retry the failed entries in a new request with a new key.
The idempotency_key body field on Technique runs
POST /techniques/{slug}/runs also accepts idempotency_key in the body. FLORA stores it with the run. Any later request in the same workspace with the same key returns that run, whatever its status, instead of starting a new one. If it has completed, the response includes its outputs.
The body isn't compared, and the key doesn't expire. Change the key whenever you want a new run.
For Technique runs, prefer the body field: a retry gives you the run back instead of a 409. If you send both, the header is checked first.
LoRA training has its own client_token, which works like the body field. See Train and use LoRA Styles.
In code
Choosing good keys
Good keys are deterministic: the same logical operation always produces the same key.
q3-thumb-{market_code}: derived from the market you're processing.import-csv-row-{row_hash}: derived from a hash of the input row.user-{user_id}-onboarding-thumbnail: derived from the user.
Bad keys change on every attempt, which defeats the point:
crypto.randomUUID()generated inside the retry loop.Date.now(), for the same reason."my-run", which collides across unrelated operations.
If you want a UUID, generate it once at the start of the logical operation and reuse it on every retry:
What idempotency keys aren't
Not deduplication of content. Two different keys with the same inputs start two runs, each billed. Keys protect against accidental retries, not intentional repeats.
Not authentication. Anyone with your API key can use any idempotency key.
Recipe: idempotent batch import
Re-running this script on the same CSV returns the existing run for every row it already started. Edit a row's headline and its key changes, so that row runs again.
Related
Errors:
409 idempotency_duplicateand what to retry.Batch from a CSV: a full batch pattern.
Last updated
Was this helpful?