Omniscio

OmniscioGuidesrole 'system' must precede an 'assistant' message

API Error: 400 messages.N: role 'system' must precede an 'assistant' message

The fix is usually outside Claude Code. The conversation is fine; the request the API received had an extra system message in it.

Last checked against Anthropic's documentation on November 25, 2026. By the Omniscio team. Updated .

What is the exact message?

API Error: 400 messages.6: role 'system' must precede an 'assistant' message or end the array; ...

The number after messages. is the position in the conversation's list of messages that the API objected to. Yours will not match this example.

The same refusal has a sibling wording, which Anthropic lists as use the top-level 'system' parameter for the initial system prompt. Anthropic says that wording gets the same recovery, so the steps below apply to it too.

What does it mean?

The message itself carries the rule: a system message has to precede an assistant message, or end the array. One that sits anywhere else makes the whole request a 400.

Claude Code sends some of its reminder and attachment text as system messages inside the conversation, so it can produce this position itself. It handles that: when the API refuses one's position, Claude Code retries the request once with that text sent as ordinary user messages instead.

That retry is why a persistent error points somewhere other than Claude Code. When the error does appear, the refused system message is not one Claude Code can remove. Anthropic names the usual reason: a proxy or LLM gateway between Claude Code and the API added a system message of its own.

How do I fix it?

  1. Connect without the proxy to test the source. If ANTHROPIC_BASE_URL is set, echo $ANTHROPIC_BASE_URL (or echo $env:ANTHROPIC_BASE_URL in PowerShell) shows what it points at. Start one session with that variable unset, from a terminal where you have removed it, and send the same message. An error that disappears points at the proxy. If your network requires the proxy, skip to the next step instead.
  2. Report it to whoever operates the proxy or gateway. Give them the message and the position it names.
  3. Run /clear to start a fresh conversation. This discards the current conversation. If the error returns in the new one too, the cause is on the request path rather than in the saved conversation, which points at the proxy.

On a version older than v2.1.280, updating matters too; claude --version prints yours. Before that version Claude Code did not recognize this wording, so the error also appeared when the refused system message was one Claude Code itself sent, and every later turn of that conversation failed the same way.

How do I know it is fixed?

  • Messages in that session complete instead of ending on a 400.
  • A fresh conversation through the same proxy also completes, so the success is not one lucky turn.
  • If the fix was on the gateway, the same conversation that failed before now runs, which is strong evidence the gateway was the source.

Where these answers come from

Common questions

What does messages.N mean in this error?

It is the position in the conversation's message array where the API found the problem. The number in your error will not match the example on this page, and it is the position the refused system message sat at.

Is this a bug in Claude Code?

Usually not. Claude Code does send some reminder and attachment text as system messages inside the conversation, but when the API refuses one's position it retries once with that text as ordinary user messages. Anthropic says a message that still fails is one Claude Code cannot remove, which usually means a proxy or gateway added it.

Does /clear fix it?

It can, and it is Anthropic's second recommended step. If the error returns in the fresh conversation, the cause is on the request path rather than in the saved conversation, so look at what sits between Claude Code and the API.

Why does it fail every turn and not just once?

Because whatever added the system message adds it to every request. That is the signature of a proxy or LLM gateway configured through ANTHROPIC_BASE_URL, and Anthropic's test is to connect without that proxy and see whether the error goes away.

Does updating Claude Code help?

Only if you are behind v2.1.280. Before that version Claude Code did not recognize this wording, so the error also appeared when the offending system message was one Claude Code itself sent, and every later turn of that conversation failed the same way.