Idempotency

Retry safely with the Idempotency-Key header: a request is served at most once.

Networks fail. To retry a request safely, send the same Idempotency-Key header with each attempt: the request is served at most once.

request
curl "$KEYDAN_API_BASE/v1/chat/completions" \
  -H "Authorization: Bearer $KEYDAN_API_KEY" \
  -H "Idempotency-Key: 5d6f2c1e-8a47-4b8e-9f61-0c2d7e3a9b10" \
  -H "Content-Type: application/json" \
  -d '{"model": "kd-balanced", "messages": [{"role": "user", "content": "Hello"}]}'
  • The key is 1 to 255 visible ASCII characters; a UUID per logical request is ideal.
  • A key is remembered for 10 minutes.
  • A retry must resend the same request: the same endpoint, headers and body.

What a retry gets

Idempotent replays
When you retry…You get
while the first attempt is still running409 idempotency_in_progress with retry-after: 1
after a JSON answer was servedthe same answer again, with idempotent-replayed: true and the original x-request-id; nothing is charged twice
after a streamed (or very large) answer409 idempotency_not_replayable: send a new request with a new key
after an error (any 4xx or 5xx)a fresh attempt: errors are not stored
with the same key but a different request422 idempotency_key_reused
after 10 minutesa fresh attempt

When two identical requests arrive at once, exactly one is served; the other gets 409 idempotency_in_progress.