Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatible
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
找出 /v1/messages 的請求驗證器及其針對 messages[].role 的模型;issue 指出角色限制是故障點。先閱讀驗證器及其請求測試,接著檢查通過驗證的訊息如何轉送至上游。當 user 回合之後的 system 角色訊息通過驗證,且現有的 user 和 assistant 案例仍正常運作時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatible
Summary
The Provider Anthropic Messages endpoint validates messages[].role against only user/assistant and returns:
{"type":"error","error":{"type":"invalid_request_error","message":"Invalid input at messages.1.role"}}
This breaks vanilla Claude Code ≥ 2.1.154, which sends a system-role message inside messages[] (a still-open regression: anthropics/claude-code#63469). Your own command-code CLI sends the legacy shape and works — vanilla Claude Code against api.commandcode.ai/provider does not.
Repro (curl, max_tokens 2 — both uncharged/zero-cost)
Works (control, legacy shape):
curl https://api.commandcode.ai/provider/v1/messages \
-H "Authorization: Bearer $CMD_PROVIDER_API_KEY" \
-H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
-d '{"model":"claude-haiku-5-5","max_tokens":2,"messages":[{"role":"user","content":"hi"}]}'
# → HTTP 200, normal completion
Fails with 400 Invalid input at messages.0.role (system-role message):
curl https://api.commandcode.ai/provider/v1/messages \
-H "Authorization: Bearer $CMD_PROVIDER_API_KEY" \
-H "anthropic-version: 2023-06-01" -H "content-type: application/json" \
-d '{"model":"claude-haiku-5-5","max_tokens":2,"messages":[{"role":"system","content":"You reply tersely."},{"role":"user","content":"hi"}]}'
Verified 2026-10-29: identical 400 on every Claude model in the catalog — claude-opus-5-5, claude-opus-5, claude-sonnet-5-5, claude-sonnet-4-6, claude-fable-5-1, claude-haiku-5-5 (so it's central validation, not per-upstream). The failure fires before upstream routing model-level plan checks fire earlier; the schema gate is the blocker.
Why this is valid per Anthropic's own API
Working with Messages API → System role in messages documents mid-conversation system messages on Opus 5/5.5, Sonnet 5/5.5, Haiku 5.5, Fable/Mythos 5.x, Opus 4.8 — legal after a user turn (only messages[0] is excluded, and Claude Code ≥ 2.1.154 places it after the first user message). First-party api.anthropic.com accepts this since Claude Code 2.1.154 onward.
References
- anthropics/claude-code#63469 — regression thread: Claude Code started sending
messages[].role="system"in 2.1.154; still unfixed upstream (closed stale 2026-08); broke DeepSeek/GLM/Kimi-compatible gateways for 5 months - free-claude-code#611 — a third-party Anthropic-compatible server fixed exactly this by widening its
rolevalidator to include"system"(then merging/forwarding) - Your docs example requests only ever use
usermessages, so the docs and validator are consistent today — but Claude Code (the highest-volume /v1/messages client) is not
Suggested fix
In the /v1/messages request validator, allow "system" alongside user|assistant for messages[].role (≈10 lines in the pydantic model: role: Literal["user","assistant","system"]), then either forward as-is to system-role-aware upstreams (Anthropic's newer API accepts it on the 5.x families) or pre-merge system-role messages into the top-level system param for legacy upstreams. The free-claude-code fix is the minimal version and has been in production for 5 months.
Environment: macOS, Claude Code 2.1.308 (Homebrew cask), Provider plan key. happy to provide more traces (request captured verbatim via local listener: anthropic-beta headers list included).
- 主要語言
- 沒有語言資料
- 星號
- 4.2k
- 分支
- 372
- 平均合併
- 4 天 15 小時
- 30 天內合併 PR
- 9
環境準備
這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
CommandCodeAI/command-code 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 65/100
CommandCodeAI/command-code#1088 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
CommandCodeAI/command-code#1082 · 1 則留言 · 2 個 reaction ·
維護者通常 2 天內回覆
-
Feature request: auto-reconnect remote control (/rc) after restart可能已有人在做 @aliarain 於 8 天前認領。 未關閉p2
難度 2/5 1-3 小時 新手友好度 85/100
CommandCodeAI/command-code#992 · 1 則留言 · 已指派 1 人 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
CommandCodeAI/command-code#933 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 68/100
CommandCodeAI/command-code#855 ·
維護者通常 2 天內回覆
查看 CommandCodeAI/command-code 的全部 Issue
相似的 Issue
-
難度 2/5 1-3 小時 新手友好度 90/100
pollen-robotics/reachy_mini#1527 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 66/100
維護者通常 1 天內回覆
-
inflate: total_in uses plain += on c_ulong (32-bit on Windows), panics in debug for streams > 4 GiB未關閉
難度 1/5 1 小時以內 新手友好度 85/100
trifectatechfoundation/zlib-rs#570 · 1 則留言 ·
-
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
gbourgeat/ddd-ts-kit#680 ·
維護者通常 1 天內回覆