Skip to main content
413Not retryable

OpenAI 413 Payload Too Large

Request body exceeds size limits — context window overflow reports as 400, so a 413 is usually raw bytes (images, files) rather than tokens.

Most likely causes

  1. 1.Base64 images inflating the JSON body past the HTTP limit
  2. 2.Huge tool outputs echoed into the conversation

Fix checklist

  • Upload files via the Files API instead of inlining
  • Downscale/compress images before encoding
  • Trim tool results to the relevant excerpt

Retry guidance

Not retryable as-is — shrink the body first.

// 413 is NOT retryable — surface it and fix the request/config.
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 === 413) {
  const body = await res.json();
  // Do not retry: log the provider's message — it names the exact problem.
  throw new Error(`OpenAI 413: ${JSON.stringify(body.error ?? body)}`);
}

Provider status page: status.openai.com