Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Provider /v1/messages rejects role:"system" inside messages[] — Claude Code ≥ 2.1.154 incompatible

未關閉 適合新手
#1,085 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
75/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
api, backend

研究方向

找出 /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 role validator to include "system" (then merging/forwarding)
  • Your docs example requests only ever use user messages, 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,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CommandCodeAI/command-code 的其他 Issue

查看 CommandCodeAI/command-code 的全部 Issue

相似的 Issue

更多 Backend & API Design Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。