claude-code - 💡(How to fix) Fix [BUG] API 400 Error - role: system deserialization failure

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

API Error: 400 Failed to deserialize the JSON body into the target type: messages[1].role: unknown variant system, expected user or assistant

Code Example

API Error: 400 Failed to deserialize the JSON body into the target type: 
messages[1].role: unknown variant `system`, expected `user` or `assistant`

---
RAW_BUFFERClick to expand / collapse

Preflight Checklist

  • I have searched existing issues and this hasn't been reported yet
  • This is a single bug report (please file separate reports for different bugs)
  • I am using the latest version of Claude Code

What's Wrong?

Description: Intermittent API 400 error affecting all projects simultaneously. The error occurred regardless of input and resolved itself after ~10-15 minutes without any local changes.

Error message:

API Error: 400 Failed to deserialize the JSON body into the target type: 
messages[1].role: unknown variant `system`, expected `user` or `assistant`

Observations:

  • Affected all projects at the same time (not project-specific)
  • The column number in the error changed between attempts (41406 → 8802), suggesting the injected system content size varied
  • No local config changes were made; issue resolved on its own
  • Likely a server-side issue where system role was being incorrectly serialized into the messages array instead of passed as a top-level parameter

Environment:

  • Claude Code version: v2.1.156
  • OS: macOS Sonoma 14.8.5

What Should Happen?

The system prompt should be passed as a top-level system parameter in the API request, not injected as a message with role: system inside the messages array. All requests should succeed without 400 errors.

Error Messages/Logs

Steps to Reproduce

Unable to reliably reproduce — the issue occurred spontaneously and resolved itself after ~15 minutes without any local changes. All projects were affected simultaneously, suggesting a server-side issue rather than a client-side bug.

  1. Open any project in Claude Code
  2. Type any message and send
  3. Observe the 400 error immediately, regardless of input content

Claude Model

Sonnet (default)

Is this a regression?

Yes, this worked in a previous version

Last Working Version

No response

Claude Code Version

2.1.156

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

No response

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix [BUG] API 400 Error - role: system deserialization failure