v2.1.154+ breaks third-party API compatibility - system role injected mid-conversation
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Last working version:2.1.153
OS: Ubuntu 24 (Linux)
API used: DeepSeek API (third-party OpenAI-compatible endpoint)
Error
API Error: 400 Failed to deserialize the JSON body into the target type:
messages[1].role: unknown variant system, expected user or assistant
What happened
After updating to v2.1.154+, Claude Code started injecting a message
with role: "system" into the middle of the messages[] array.
Third-party APIs that follow strict OpenAI spec only accept
"user" or "assistant" roles in message turns. This makes
Claude Code completely unusable with third-party API providers.
Workaround
Downgraded to v2.1.153 - works fine.
What Should Happen?
claude code should work correctly with third-party openAI-compatible api's (such as deepseek) the same way it did in v2.1.153 and earlier. the messages array sent to the api should only contain "user" and
"assistant" roles in the conversation turns, with any system level instructions placed at the beginning as a proper system prompt not injected as a mid conversation message with role: "system".
this was working correctly before v2.1.154.
Error Messages/Logs
Steps to Reproduce
- Install Claude Code v2.1.154 or higher
- Configure a third-party OpenAI-compatible API endpoint (e.g. DeepSeek)
in Claude Code settings
- Launch Claude Code: $ claude
- Give any simple prompt, e.g. "write a hello world python script"
- Observe the API error immediately
Error received:
"400 Failed to deserialize the JSON body into the target type:
messages[1].role: unknown variant system, expected user or assistant"
Note: Downgrading to v2.1.153 resolves the issue immediately with
no other changes. The same API key and endpoint configuration
works perfectly on v2.1.153.
Claude Model
None
Is this a regression?
Yes, this worked in a previous version
Last Working Version
_No response_
Claude Code Version
2.1.154, 2.1.156
Platform
Anthropic API
Operating System
Ubuntu/Debian Linux
Terminal/Shell
VS Code integrated terminal
Additional Information
_No response_
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗