Skip to Content
NineTwo's

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

ClassMeaning
noFix the request, credentials, funding, or permissions. Do not retry unchanged.
same_keyRetry the same key and identical payload.
same_key_after_delayRetry the same key with backoff; honour Retry-After when present.
poll_requestRetry the same key to obtain X-Request-Id, then poll GET /v1/requests/{id}.
new_keyThe original key is terminal; a genuinely new logical request needs a new key.
operatorRequires operator/support investigation.

Common errors

HTTPCodeRetryNotes
400invalid_json, invalid_request, invalid_messages, invalid_max_completion_tokens, invalid_stream, invalid_stream_options, etc.noFix the request. invalid_stream means stream was not a boolean.
400idempotency_key_requirednoKey is missing, blank, whitespace/control characters, or too long.
400context_window_exceedednoInput tokens plus requested output exceed the dynamic context window.
401invalid_key, unauthenticated, credential_expired_or_revokednoCorrect credentials.
402insufficient_fundsnoPrepaid balance cannot cover the maximum reservation.
403scope_denied, model_not_authorized, capability_denied, etc.noCheck scope, model allowlist, entitlement, and profile.
409idempotency_conflictnoSame key, different canonical payload; no dispatch occurs.
409execution_in_progress, execution_already_processingsame_key_after_delaySame-key retry or poll the supplied X-Request-Id.
409terminal_outcomenew_keyThe original execution is terminal.
413payload_too_largenoRequest body exceeds the documented bound.
429rate_limit_exceededsame_key_after_delayHonour Retry-After.
429concurrency_limitsame_key_after_delayNo Retry-After; the reservation is retained for a same-key retry.
503inference_unavailablenew_keyDefinite pre-dispatch refusal; reservation released. Same-key retry yields terminal_outcome.
503inference_outcome_unknownpoll_requestMay have reached the GPU. Same-key retry obtains X-Request-Id; then poll.
503model_unavailable, serving_unavailable, tokenizer_unavailable, etc.same_key_after_delayAvailability failure; retry the same key with backoff.
503serving_revision_mismatchoperatorRequires 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.

On this page