Idempotency and recovery
Same-key semantics, 409 distinctions, X-Request-Id, and no-ID recovery.
Idempotency keys
Idempotency-Key is required on every POST /v1/chat/completions request,
including streaming requests.
- Use 1–200 printable, non-whitespace characters with no control characters.
- Scope uniqueness is organisation + project + key.
- Use one key per logical operation. Reuse it only for retries of the identical canonical payload.
- A different canonical payload with the same key returns
409 idempotency_conflictand never dispatches.
Blank, whitespace-only, control-character, or over-length keys are rejected
with 400 idempotency_key_required.
Canonical payload
Idempotency is hashed after validation and normalization:
max_completion_tokensis canonical;max_tokensis a compatibility alias. The same value under either spelling is the same canonical payload.max_completion_tokenswins when both are present; conflicting values are not rejected.- Unknown top-level fields are accepted and ignored, so they are not part of the canonical payload.
stream_optionsaccepts onlyinclude_usage; unknown properties are rejected withinvalid_stream_options.reasoning_effortis part of the canonical payload.
409 responses are not all the same
| Code | Meaning | Client action |
|---|---|---|
idempotency_conflict | Same key was reused with a different canonical payload, or by a different credential in the same project. No replay, dispatch, or charge occurred. | Reuse the original credential and payload, or use a new key for a genuinely new logical request. |
execution_in_progress | The same-key request is still executing. | Retry the same key after a delay, or poll X-Request-Id when supplied. |
execution_already_processing | Another worker owns dispatch. | Retry the same key after a delay. |
terminal_outcome | The execution reached a released/rejected terminal state. | Use a new key for a new logical request. |
execution_in_progress, execution_already_processing, and
terminal_outcome are distinct from idempotency_conflict. Never respond to
an in-progress 409 by changing the payload or minting a new key.
Durable replay and outage behavior
Replay identity is resolved before endpoint resolution, health checks, tokenization, rate limiting, or new charging:
- Strict JSON/envelope and parameter-type validation.
- Authentication/authorization without requiring current lifecycle availability and without recording usage.
- Durable replay lookup by organisation + project + idempotency key.
- Credential binding, then canonical payload verification.
- Only for new or resumable work: lifecycle availability, admission telemetry, dynamic limits, endpoint/health/tokenization, rate limit, reservation, and dispatch.
New financial requests persist a SHA-256 canonical_payload_digest.
Historical immutable rows are not backfilled; for historical settled rows the
input digest is reconstructed from immutable metering evidence and
admitted_max_output_tokens. If required evidence is missing, the request
falls back to the live path rather than guessing.
Consequences:
- A completed replay returns the stored result even during a model/serving
outage, with the same
X-Request-Idand no new financial or metering rows. - A replay of a request originally made with
stream=truereturns the stored JSONchat.completion, not an SSE stream. SSE replay is not invented. - Dynamic capability limits are enforced only for new or resumable work. Replay uses structural validation, so a previously accepted request remains replayable even if current limits differ.
Cross-credential conflict
The idempotency key is scoped to organisation + project, but it is bound to
the credential that created it. A second credential in the same project that
reuses the key—even with an identical payload—receives
409 idempotency_conflict before any serving dependency. There is no
cross-credential replay, dispatch, or charge.
Recovery headers
X-Request-Id is the gateway execution UUID. It is returned on:
- successful non-streaming responses and replays;
- streaming response headers;
409 execution_in_progressand409 execution_already_processing;- post-reservation
429 concurrency_limit; 503 inference_unavailableand503 inference_outcome_unknownwhen an execution exists;- other post-admission errors associated with an execution.
Use it with GET /v1/requests/{id}. The id must be a canonical UUID; malformed
ids return 400 invalid_id.
Recovery when no request id was received
There is deliberately no public idempotency-key lookup endpoint. Preserving the key and payload is the recovery mechanism:
- Retry the same
Idempotency-Keywith the identical canonical payload. - If the original settled, the stored completion is replayed with
200and the sameX-Request-Id. - If it is still executing, the response is
409 execution_in_progresswithX-Request-Id; pollGET /v1/requests/{id}. - If it was reserved but never dispatched (for example after a concurrency 429), the retry resumes that reservation.
- If it reached a released/rejected terminal state, the response is
terminal_outcome; only then use a new key for a new logical request.
# Same key and same payload: recover an uncertain outcome.
curl -sS "$NINETWOS_BASE_URL/chat/completions" \
-H "Authorization: Bearer $NINETWOS_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: chat-001" \
-d '{
"model": "zuv-0.5",
"messages": [{"role": "user", "content": "Summarize this ticket"}],
"max_completion_tokens": 256
}'Terminal outcomes
503 inference_unavailable is a definite pre-dispatch refusal whose
reservation was released. Retrying the same key returns terminal_outcome;
only then use a new key for a new logical request.
503 inference_outcome_unknown means the request may have reached the GPU.
Never start a new logical request. Retry the same key to recover
X-Request-Id, then poll request status.
A timeout or dropped connection does not prove failure. Never blind-restart with a new key, and never change the payload to "make the retry work".