API Error: 400 Invalid input at messages.1.role (Claude Code)
Claude Code sent a role system message inside messages, and the provider only accepts user and assistant there. Claude Code retries by itself only if it recognizes the rejection.
Summary
- Claude Code sends some reminder and attachment text as role system entries in messages for Opus 4.8 and newer models and for unknown model IDs.
- Anthropic's API accepts them; some third-party Anthropic-format endpoints, such as Command Code's, reject the role.
- Claude Code retries without those entries when the error wording is one it recognizes; Invalid input at messages.N.role is not reported as one.
- CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS does not stop these messages, so the fix is on the provider or gateway side.
On this page
A system message where the provider expects user or assistant
API Error: 400 Invalid input at messages.1.role
messages.1 is the second entry in the request's messages array, and role is the field the provider refused. On Anthropic's own API that entry is valid. Mid-conversation system messages are a documented Messages API feature with no beta header: you append {"role": "system", ...} where a new instruction starts to apply, so the cached prefix before it stays intact. They work on Claude Opus 4.8, Opus 5, Opus 5.5, Sonnet 5.5, Haiku 5.5 and the Fable and Mythos 5 models, not on Claude Sonnet 5.
Claude Code uses the feature. Its gateway compatibility guide says it sends some reminder and attachment text as role: "system" entries in messages for Claude Opus 4.8, models released after it, and model IDs it does not recognize. An endpoint that copies the Anthropic format but only allows user and assistant in that array returns this 400.
The reported case: Command Code
The public reports are all about Command Code's Anthropic-format endpoint:
- command-code issue #1085 (open): the provider's
/v1/messagesrejects arole: "system"message placed after the first user message. The reporter dates the incompatibility to Claude Code 2.1.154 and tested 2.1.308. A request with the system message at index 0 fails the same way, asmessages.0.role. - cc-switch issue #8103 (open): the same 400 with
claude-opus-5-5through CC Switch 4.0.7 and Claude Code 2.1.296, reproduced with a direct request without CC Switch. The CC Switch maintainer confirmed it and is weighing a fallback in CC Switch's routing.
If another provider gives you the same wording, a role check like this is the first thing to rule out; send the provider the request shape above.
Why Claude Code does not recover by itself
Claude Code has a fallback for exactly this. When the upstream rejects a role: "system" entry inside messages, it retries once without those entries and carries their text in user messages, and keeps that shape until /clear or the next compaction. The guide's example wording is Unexpected role "system", and it notes that this retry logic matches on the upstream's error text. Invalid input at messages.1.role does not name the system role, and in the reports above the request failed instead of retrying.
The cc-switch reporter got Claude Code's fallback to run by putting a local proxy in front that rewrites the 400's message to start with capability_rejected: mid_conv_system;. The guide documents capability_rejected: tokens as the way a gateway keeps Claude Code's recovery working when it wraps upstream errors. That is a workaround for people who run their own proxy, not a setting in Claude Code.
What you can do
- Use a provider or gateway that accepts
role: "system"inmessages, or one that forwards the upstream's own error text unchanged. - If you run the gateway, either accept the entries (merge them into the top-level
systemor pass them through) or answer with a message Claude Code recognizes. - If the model behind your alias is older than Claude Opus 4.8, a
modelOverridesentry that maps the alias to that model stops Claude Code sending these entries. CLAUDE_CODE_DISABLE_EXPERIMENTAL_BETAS=1does not help here. Mid-conversation system messages use no beta header, and the cc-switch reporter found the same validator still failing with it set.
An empty system message with an effort setting fails differently, as system content must contain at least one block. For a desktop tool that writes the base URL, key and model into Claude Code and Codex for you, see our LLM API config GUI guide; other 400s are on the Claude Code API Error 400 page.
Sources and checks
- Mid-conversation system messages and tool changes (Claude API)
- Claude Code gateway compatibility guide
- CommandCodeAI/command-code #1085: Provider /v1/messages rejects role system inside messages[], Claude Code 2.1.154 and later incompatible
- farion1231/cc-switch #8103: Command Code + Claude Code: mid-conversation system role returns 400