Skip to main content
400Not retryable

Anthropic 400 Invalid Request

The request body failed validation before the model ever ran — a malformed field, a missing required parameter, or values outside documented limits.

Most likely causes

  1. 1.max_tokens missing or exceeding the model's max output
  2. 2.messages array malformed: empty content, wrong role order, or non-alternating roles
  3. 3.Unknown or misspelled parameter (e.g. OpenAI-style `functions` instead of `tools`)
  4. 4.Tool input_schema is not valid JSON Schema

Fix checklist

  • Read the error message field — Anthropic names the exact offending parameter
  • Validate messages alternate user/assistant and the first message is from user
  • Set max_tokens explicitly; it is required on the Messages API
  • Diff your request against the Messages API reference, not OpenAI's

Retry guidance

Do not retry — the same request will fail identically. Fix the payload first.

// 400 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 === 400) {
  const body = await res.json();
  // Do not retry: log the provider's message — it names the exact problem.
  throw new Error(`Anthropic 400: ${JSON.stringify(body.error ?? body)}`);
}

Provider status page: status.anthropic.com