Skip to main content
Networks can drop in the middle of a request. Without idempotency, you cannot tell whether the request already created a job — and resending it risks a double credit deduction. POST /api/v1/generate accepts an idempotencyKey field for this case.

How to use it

1

Create one key per business intent

Not per HTTP request. If the user pressed “Generate” for order #4711, that order has one key, and every retry uses the same key.
2

Send it, and if the connection drops, repeat with the same key

Keep using the same key until you receive any JSON response.
3

Understand the replay response

If the server has already seen that key, you receive 200 OK (not 202) with the original job:
The status difference you need to handle:
A replay returns the job that already exists, without comparing its contents. If you send the same key with a different prompt or model, those changes are silently ignored and you only get the old job. If the request genuinely changed, it is a new request — use a new key.

Key naming rules

  • Minimum length 8 characters. Below that, the server ignores your value and generates its own key, so your retry is unprotected.
  • Use characters that are safe on every system: letters, digits, hyphens, underscores.
  • Combine a business id with a random part, for example order-4711-a39f2c7b. Key matching on the server is global, so an easily guessed key (for example coba-1) risks colliding with another user’s key.
  • Keys never expire. Once used, they are recorded forever — so do not use a timestamp as the key if you actually want the next request to become a new job.

Example of a safe client

The POST /api/v1/upload endpoint and GET requests do not need idempotency. Every upload produces a new asset, and GET is already side-effect free.