Errors and retries
Coded error envelope, retry classes, and recovery-aware backoff.
Coded error envelope
Every public error uses one machine-readable envelope:
{
"error": {
"code": "execution_in_progress",
"message": "This idempotent request is already executing."
}
}code is stable and safe to branch on. message is human-readable and may
change. Some validation errors may include a details object.
Structural validation runs before replay and never coerces invalid types:
top-level JSON must be an object (invalid_request), message entries must be
objects (invalid_messages), stream must be boolean (invalid_stream), and
other documented parameters use their specific invalid_* codes.
Retry classes
| Class | Meaning |
|---|---|
no | Fix the request, credentials, funding, or permissions. Do not retry unchanged. |
same_key | Retry the same key and identical payload. |
same_key_after_delay | Retry the same key with backoff; honour Retry-After when present. |
poll_request | Retry the same key to obtain X-Request-Id, then poll GET /v1/requests/{id}. |
new_key | The original key is terminal; a genuinely new logical request needs a new key. |
operator | Requires operator/support investigation. |
Common errors
| HTTP | Code | Retry | Notes |
|---|---|---|---|
| 400 | invalid_json, invalid_request, invalid_messages, invalid_max_completion_tokens, invalid_stream, invalid_stream_options, etc. | no | Fix the request. invalid_stream means stream was not a boolean. |
| 400 | idempotency_key_required | no | Key is missing, blank, whitespace/control characters, or too long. |
| 400 | context_window_exceeded | no | Input tokens plus requested output exceed the dynamic context window. |
| 401 | invalid_key, unauthenticated, credential_expired_or_revoked | no | Correct credentials. |
| 402 | insufficient_funds | no | Prepaid balance cannot cover the maximum reservation. |
| 403 | scope_denied, model_not_authorized, capability_denied, etc. | no | Check scope, model allowlist, entitlement, and profile. |
| 409 | idempotency_conflict | no | Same key, different canonical payload; no dispatch occurs. |
| 409 | execution_in_progress, execution_already_processing | same_key_after_delay | Same-key retry or poll the supplied X-Request-Id. |
| 409 | terminal_outcome | new_key | The original execution is terminal. |
| 413 | payload_too_large | no | Request body exceeds the documented bound. |
| 429 | rate_limit_exceeded | same_key_after_delay | Honour Retry-After. |
| 429 | concurrency_limit | same_key_after_delay | No Retry-After; the reservation is retained for a same-key retry. |
| 503 | inference_unavailable | new_key | Definite pre-dispatch refusal; reservation released. Same-key retry yields terminal_outcome. |
| 503 | inference_outcome_unknown | poll_request | May have reached the GPU. Same-key retry obtains X-Request-Id; then poll. |
| 503 | model_unavailable, serving_unavailable, tokenizer_unavailable, etc. | same_key_after_delay | Availability failure; retry the same key with backoff. |
| 503 | serving_revision_mismatch | operator | Requires investigation. |
Replay before serving dependencies
A completed replay is resolved from durable identity before endpoint
resolution, health checks, tokenization, rate limiting, or new charging. A
retry can therefore return the stored 200 result during a model/serving
outage when durable replay evidence exists. It creates no new financial or
metering rows.
A replay of a completed streaming request returns stored JSON
chat.completion, not SSE. Historical rows without durable replay evidence
may fall back to the live path.
Recovery-aware retry
const retryableCodes = new Set([
'execution_in_progress',
'execution_already_processing',
'rate_limit_exceeded',
'rate_limited',
'concurrency_limit',
'model_unavailable',
'serving_unavailable',
'tokenizer_unavailable',
'reservation_unconfirmed',
'completed_evidence_unavailable',
'service_unavailable',
]);
async function withRetry(fn, { attempts = 5, baseMs = 250 } = {}) {
for (let attempt = 0; attempt < attempts; attempt++) {
const response = await fn();
if (response.ok) return response;
const body = await response.json().catch(() => null);
const code = body?.error?.code;
if (code === 'inference_outcome_unknown') {
// Retry the same key to obtain X-Request-Id, then poll request status.
throw new Error(`Recover via same-key retry and request lookup: ${code}`);
}
if (!retryableCodes.has(code) || attempt === attempts - 1) {
throw new Error(`${response.status} ${code ?? 'unknown_error'}`);
}
const retryAfter = Number(response.headers.get('retry-after'));
const delay = Number.isFinite(retryAfter) && retryAfter > 0
? retryAfter * 1000
: Math.min(baseMs * 2 ** attempt, 10_000) +
Math.floor(Math.random() * baseMs);
await new Promise((resolve) => setTimeout(resolve, delay));
}
}The retry example above reuses one idempotency key and one payload across all retries.
Never retry idempotency_conflict by changing the payload under the same
key, and never respond to inference_outcome_unknown with a new key. See
Idempotency and recovery.