claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] API Error: 400 messages: roles must alternate between "user" and "assistant", but found multiple "user" roles in a row

Open mmuschalik opened this issue 9 months ago • 3 comments

Environment

  • Platform (select one):
    • [x] AWS Bedrock
  • Claude CLI version: 0.2.113
  • Operating System: macOS
  • Terminal: zsh

Bug Description

Quite often (a lot) I see this error while the agent (claude code CLI) is running, producing responses. It will produce that response and wait for user input

Additional Context

I usually just reply with "go" until eventually I get a good response. I am in the Asia pacific zone. I use ANTHROPIC_MODEL="apac.anthropic.claude-3-5-sonnet-20240620-v1:0" and ANTHROPIC_SMALL_FAST_MODEL is the same value.

Also please look at something you must have broken recently (in latest model). When running claude -p "" it goes back to 3.7 model only available in US zone, disrespects my environment variable. It's ok when running in interactive mode, but not when running with -p.

Guys, love this tool, but on the cusp of deciding whether we use this vs something else like codex, these issues are hurting bad.

mmuschalik avatar May 19 '25 05:05 mmuschalik

Hey, sorry about that. We've been improving performance/reliability for Bedrock, and this is a regression that snuck through as we were re-building a few things. Taking a look.

bcherny avatar May 19 '25 14:05 bcherny

The issue with claude -p ignoring the model flag has been resolved in v0.2.122.

We're still looking into the roles issue - @mmuschalik there were some related changes in v0.2.124, can you see if the issue is still occurring for you? Otherwise, if you have additional information on the scenarios where you commonly see this, that would help expedite this! Thanks in advance.

ant-kurt avatar May 21 '25 02:05 ant-kurt

I've been running into this as well. I'm just using the basic claude GH action and prompting claude in issues and PRs. I'm getting good results, but the action runs are eventually running into this error and then hanging for a long while.

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: Expected content to be an assistant message, but got "user"
    at yS2 (file:///opt/hostedtoolcache/node/18.20.8/x64/lib/node_modules/@anthropic-ai/claude-code/cli.js:2342:9744)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async bE5 (file:///opt/hostedtoolcache/node/18.20.8/x64/lib/node_modules/@anthropic-ai/claude-code/cli.js:2356:8265)
Claude process timed out after 1800 seconds

jseldess avatar Jun 06 '25 19:06 jseldess

This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.

github-actions[bot] avatar Dec 03 '25 10:12 github-actions[bot]