Idempotency
How to retry without paying twice.
Networks fail. If a call times out, you can't know whether the generation started. An Idempotency-Key makes retrying safe.
POST /v1/generations
Idempotency-Key: order-1234-hero-photo| You send | You get |
|---|---|
| A new key | A new generation |
| The same key and the same body | The first generation, with Idempotent-Replayed: true. Nothing new is charged |
| The same key and another body | idempotency_conflict |
- Up to 200 characters. Keys belong to your account.
- A key is remembered for as long as its generation exists, which is for good: deleting a generation removes its files, not the record. So never reuse a key for new work.
- Use one key for each thing you want made: an order id, a UUID, a hash of what you're asking for. Keys in these docs' examples are examples: make your own.
- A refused call doesn't use up its key. If the answer is a 4xx, nothing was made: fix the request and send it again with the same key.
- To retry a failed generation, use a new key. The old key returns the same failure, because it's the same order.
- After
internalor a dropped connection, retry with the same key.
Through MCP
The generate tool has no key field: it does this for you. A call with exactly the same arguments within the same 10 minutes returns the same generation, unless that one failed or was deleted. Pass run_again: true to make another on purpose.