[GH-ISSUE #1369] [BUG] Anthropic endpoint: system field as content block array causes 'unknown variant system' error with Claude Code v2.1.154+ #909

Closed
opened 2026-10-26 21:32:06 +00:00 by bsakaguchi · 0 comments
Owner

Originally created by @james-huangzhen on GitHub (May 29, 2026).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-V3/issues/1369

Description

When using Claude Code v2.1.154+ with DeepSeek's /anthropic endpoint (https://api.deepseek.com/anthropic), requests fail with HTTP 400:

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

Root Cause

Claude Code v2.1.154 changed the system field from a plain string to an array of text content blocks with cache_control — both are valid per the Anthropic Messages API specification:

Before v2.1.154 (string format):

{
  "system": "You are a Claude agent...",
  "messages": [...]
}

After v2.1.154 (content block array format):

{
  "system": [
    {
      "type": "text",
      "text": "You are a Claude agent...",
      "cache_control": {"type": "ephemeral"}
    },
    {
      "type": "text",
      "text": "# System
- All text you output..."
    }
  ],
  "messages": [...]
}

DeepSeek's /anthropic endpoint appears to only handle system as a string. When it receives the array format, the internal format conversion (Anthropic → OpenAI) incorrectly places the text content blocks into the messages array as role: "system" entries, which then fails validation.

Steps to Reproduce

  1. Set environment variables:
    export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic
    export ANTHROPIC_AUTH_TOKEN=<deepseek-api-key>
    export ANTHROPIC_MODEL=deepseek-v4-pro
    
  2. Install Claude Code v2.1.154+: npm install -g @anthropic-ai/claude-code
  3. Run claude and send any message
  4. Observe the 400 error

Evidence

  • DeepSeek's own Anthropic API guide only demonstrates system as a plain string — the array/content-block format is never mentioned or tested
  • cache_control is documented as "Ignored" in the compatibility table, suggesting incomplete Anthropic API implementation
  • Related issues: #967 (parallel tool use format mismatch), #1269 (cache_control ignored)
  • Claude Code's prompt caching optimization relies on the array format per Anthropic's official recommendation

Expected Behavior

The /anthropic endpoint should accept system as both a string AND an array of text content blocks (with or without cache_control), consistent with the Anthropic Messages API specification.

Workaround

Downgrade Claude Code to v2.1.153: npm install -g @anthropic-ai/claude-code@2.1.153

Environment

  • DeepSeek API endpoint: https://api.deepseek.com/anthropic
  • Claude Code version: v2.1.154+
  • Model: deepseek-v4-pro
Originally created by @james-huangzhen on GitHub (May 29, 2026). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-V3/issues/1369 ## Description When using Claude Code v2.1.154+ with DeepSeek's `/anthropic` endpoint (`https://api.deepseek.com/anthropic`), requests fail with HTTP 400: ``` API Error: 400 Failed to deserialize the JSON body into the target type: messages[1].role: unknown variant `system`, expected `user` or `assistant` ``` ## Root Cause Claude Code v2.1.154 changed the `system` field from a plain string to an **array of text content blocks** with `cache_control` — both are valid per the [Anthropic Messages API specification](https://docs.anthropic.com/en/api/messages): **Before v2.1.154 (string format):** ```json { "system": "You are a Claude agent...", "messages": [...] } ``` **After v2.1.154 (content block array format):** ```json { "system": [ { "type": "text", "text": "You are a Claude agent...", "cache_control": {"type": "ephemeral"} }, { "type": "text", "text": "# System - All text you output..." } ], "messages": [...] } ``` DeepSeek's `/anthropic` endpoint appears to only handle `system` as a string. When it receives the array format, the internal format conversion (Anthropic → OpenAI) incorrectly places the text content blocks into the `messages` array as `role: "system"` entries, which then fails validation. ## Steps to Reproduce 1. Set environment variables: ```bash export ANTHROPIC_BASE_URL=https://api.deepseek.com/anthropic export ANTHROPIC_AUTH_TOKEN=<deepseek-api-key> export ANTHROPIC_MODEL=deepseek-v4-pro ``` 2. Install Claude Code v2.1.154+: `npm install -g @anthropic-ai/claude-code` 3. Run `claude` and send any message 4. Observe the 400 error ## Evidence - DeepSeek's own [Anthropic API guide](https://api-docs.deepseek.com/guides/anthropic_api) only demonstrates `system` as a plain string — the array/content-block format is never mentioned or tested - `cache_control` is documented as "Ignored" in the compatibility table, suggesting incomplete Anthropic API implementation - Related issues: #967 (parallel tool use format mismatch), #1269 (cache_control ignored) - Claude Code's prompt caching optimization relies on the array format per Anthropic's official recommendation ## Expected Behavior The `/anthropic` endpoint should accept `system` as both a string AND an array of text content blocks (with or without `cache_control`), consistent with the Anthropic Messages API specification. ## Workaround Downgrade Claude Code to v2.1.153: `npm install -g @anthropic-ai/claude-code@2.1.153` ## Environment - DeepSeek API endpoint: `https://api.deepseek.com/anthropic` - Claude Code version: v2.1.154+ - Model: `deepseek-v4-pro`
bsakaguchi 2026-10-26 21:32:06 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-V3#909
No description provided.