Skip to main content
409Retryable

OpenAI 409 Conflict

The request conflicts with resource state — usually concurrent modification of the same resource (assistants, files, fine-tune jobs).

Most likely causes

  1. 1.Two writers mutating the same resource simultaneously
  2. 2.Cancelling a job that already finished

Fix checklist

  • Serialize writes to a given resource
  • Re-fetch resource state before mutating

Retry guidance

Safe to retry once after re-reading current state; blind retries can re-conflict.

// Retry 409 with exponential backoff + full jitter.
async function callWithBackoff(payload: unknown, maxAttempts = 5) {
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
    const res = await fetch("https://api.openai.com/v1/chat/completions", {
      method: "POST",
      headers: {
        "content-type": "application/json",
        Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
      },
      body: JSON.stringify(payload),
    });
    if (res.status !== 409) return res;
    // Honor Retry-After when present; otherwise exponential backoff, capped at 32s.
    const retryAfter = Number(res.headers.get("retry-after"));
    const base = Number.isFinite(retryAfter) && retryAfter > 0
      ? retryAfter * 1000
      : Math.min(1000 * 2 ** attempt, 32_000);
    await new Promise((r) => setTimeout(r, base * (0.5 + Math.random() * 0.5)));
  }
  throw new Error("OpenAI 409: still failing after backoff — check https://status.openai.com");
}

Provider status page: status.openai.com