Skip to content

Claude Code 2.1.333 – Anthropic API message-role compatibility issue #1187

Backlog

Description

@sudhanshumathurlearn

Summary

'm integrating Claude Code 2.1.333 with CommandCode using the Anthropic-compatible endpoint:

https://api.commandcode.ai/provider/v1/messages

Model: deepseek/deepseek-v4.1-flash

Basic API requests containing user messages work successfully.

However, requests containing a system role inside the messages array return:

400 Invalid discriminator value. Expected 'user' | 'assistant' at messages.1.role

I independently reproduced this error using curl, without Claude Code or any middleware.

I also disabled all Caveman hooks, but Claude Code continues to encounter the same error.

It appears the gateway strictly validates message roles and rejects system messages inside the conversation history.

Could you confirm:

Does the Anthropic-compatible endpoint support the message format emitted by Claude Code 2.1.333?

Can the gateway normalize mid-conversation system messages into the top-level system instruction?

Is there a Claude Code compatibility mode or recommended workaround?

This is preventing Claude Code from working with DeepSeek through CommandCode.

Expected Behavior

The Anthropic-compatible /v1/messages endpoint should support requests generated by Claude Code 2.1.333, including requests containing system-level instructions.

The gateway should correctly handle system instructions according to the Anthropic Messages API specification:

  • System-level instructions should be accepted through the top-level system field.
  • If Claude Code sends system-role messages within the messages array, the gateway should either normalize them into the appropriate system instruction representation or provide a compatible request-handling mechanism.
  • Valid user and assistant messages, tool-use interactions, and conversation history should be preserved without data loss or changes in message ordering.

Expected result: Claude Code should be able to communicate successfully with CommandCode using supported models such as deepseek/deepseek-v4.1-flash, without encountering a 400 Invalid discriminator value error.

Actual Behavior

'm integrating Claude Code 2.1.333 with CommandCode using the Anthropic-compatible endpoint:

https://api.commandcode.ai/provider/v1/messages

Model: deepseek/deepseek-v4.1-flash

Basic API requests containing user messages work successfully.

However, requests containing a system role inside the messages array return:

400 Invalid discriminator value. Expected 'user' | 'assistant' at messages.1.role

I independently reproduced this error using curl, without Claude Code or any middleware.

I also disabled all Caveman hooks, but Claude Code continues to encounter the same error.

It appears the gateway strictly validates message roles and rejects system messages inside the conversation history.

Could you confirm:

Does the Anthropic-compatible endpoint support the message format emitted by Claude Code 2.1.333?

Can the gateway normalize mid-conversation system messages into the top-level system instruction?

Is there a Claude Code compatibility mode or recommended workaround?

This is preventing Claude Code from working with DeepSeek through CommandCode.

Steps to reproduce the issue

  1. Install and launch Claude Code version 2.1.333.

  2. Configure Claude Code to use CommandCode's Anthropic-compatible API endpoint:

    ANTHROPIC_BASE_URL=https://api.commandcode.ai/provider

  3. Configure a valid CommandCode API key:

    ANTHROPIC_API_KEY=<YOUR_API_KEY>

  4. Configure the model:

    ANTHROPIC_MODEL=deepseek/deepseek-v4.1-flash

  5. Set the default Opus, Sonnet, and Haiku model environment variables to deepseek/deepseek-v4.1-flash.

  6. Disable Caveman hooks to eliminate potential third-party middleware interference.

  7. Start a fresh Claude Code session.

  8. Send a simple prompt, for example: Hello, reply with OK.

  9. Observe that Claude Code returns the following error:

    API Error: 400 Invalid discriminator value. Expected 'user' | 'assistant' at messages.1.role

Additional verification:

  1. Send a basic request directly to CommandCode using curl with a single user message. The request succeeds.
  2. Send a request containing a system role inside the messages array. The API returns the same HTTP 400 discriminator error.

This reproduces the issue independently of Claude Code and Caveman hooks.

Command Code Version

1.93.6

Operating System

macOS

Terminal/IDE

Mac Os native Terminal

Shell

No response

Session file (optional)

No response

Fix prompt (optional)

No response

Additional context

No response

Activity

  1. sudhanshumathurlearn commented on Dec 1, 2026

    @sudhanshumathurlearn
    Author

    Workaround

    Adding the following environment variable to Claude Code's settings.json resolves the issue:

    "CLAUDE_CODE_MODEL_CAPABILITIES": "*=-mid_conv_system"

    This disables the mid_conv_system capability for all configured models, preventing Claude Code from sending mid-conversation system messages that the CommandCode Anthropic-compatible endpoint rejects.

    With this configuration, Claude Code can communicate with CommandCode using deepseek/deepseek-v4.1-flash without encountering the 400 discriminator error.

    This appears to be a compatibility workaround rather than a permanent gateway-side fix.

  2. dan-sec commented on Dec 2, 2026

    @dan-sec

    Same problem with claude code version 2.1.334 in ubuntu.
    Workaroud works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions