Skip to main content
Networks drop connections and clients time out. If you retry POST /v2/generations after a failure you could not see, the first request may have gone through, and you would pay for two generations. An idempotency key makes the retry safe.

Send a key

Generate a unique key for each generation you want, such as a UUID, and send it in the Idempotency-Key header. Keep the same key for every retry of that request.
The key is 1 to 255 printable ASCII characters. A key derived from your own ids (order-1042-hero-v1) works too, as long as it is unique to one generation.

What happens on a retry

The same request means the same model, mode, input, metadata, webhook_url and max_credits. The order of JSON keys does not matter. Concurrent requests with the same key are safe: one creates the generation and the others answer it, with Idempotent-Replayed: true. Only one is billed. In the rare case a concurrent request cannot read it yet, it gets 409 idempotency_key_in_use: retry the same request in a few seconds.

Lifetime

  • How long a key holds. For good: a key stays bound to the generation it created, even after you delete the generation.
  • Scope. Keys are scoped to your workspace: two workspaces can use the same key.

Which requests take a key

POST /v2/generations, the request that spends credits, and the two that start an agent’s turn:
  • POST /v2/sessions: a retry returns the session the key started, in its current state.
  • POST /v2/sessions/{id}/messages: a retry returns the session with the turn the key started, even while that turn runs or after it answered. Keys are per session.
For these two, Argil does not compare the requests: a key used again returns what it first started. Use a new key for each new session and each new message. Other requests do not use the header:
  • POST /v2/assets: sending the same file or URL again returns the asset you already have.
  • DELETE and PATCH: repeating them changes nothing more.
  • POST /v2/webhook_endpoints: check GET /v2/webhook_endpoints before creating one again.

Errors that are safe to retry

A request refused with a problem created nothing. Retry it with the same key after fixing the cause, or after the delay Retry-After gives. A 5xx or a dropped connection may or may not have created the generation: retry with the same key, and Argil sorts it out.