Skip to main content
413Not retryable

Anthropic 413 Request Too Large

The request body exceeds Anthropic's size limit — too many tokens or megabytes in a single call.

Most likely causes

  1. 1.Accumulated agent history pushed input past the 200k context window
  2. 2.Large base64 images or PDFs inlined into the request
  3. 3.Oversized tool results echoed back verbatim each turn

Fix checklist

  • Count tokens before sending (the count_tokens endpoint is free)
  • Compact or summarize old turns instead of resending full history
  • Truncate tool results to what the model actually needs
  • Downscale images before base64-encoding

Retry guidance

Not retryable as-is — shrink the payload, then resend.

// 413 is NOT retryable — surface it and fix the request/config.
const res = await fetch("https://api.anthropic.com/v1/messages", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "x-api-key": process.env.ANTHROPIC_API_KEY!,
      "anthropic-version": "2023-06-01",
  },
  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(`Anthropic 413: ${JSON.stringify(body.error ?? body)}`);
}

Provider status page: status.anthropic.com