Provider API: /v1/messages rejects mid-conversation role:"system" messages (400 Invalid input at messages.N.role)
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- bash
调研方向
Start at the POST /provider/v1/messages request validation and reproduce the supplied curl cases, comparing a mid-conversation system role with the accepted top-level system forms. Done means compliant system entries return a normal completion, or intentionally unsupported input produces a distinct documented error instead of the generic role validation failure.
由索引模型根据 Issue 内容生成。
描述
Summary
POST https://api.commandcode.ai/provider/v1/messages rejects the tested, documented
mid-conversation system message on claude-opus-5-5 with HTTP 400:
{"type":"error","error":{"type":"invalid_request_error","message":"Invalid input at messages.1.role"}}
Anthropic documents mid-conversation system messages for Claude Opus 5.5 and Opus 5 without a
beta header. The minimal request here has messages:[user,system]: the system message immediately
follows a user message and is the last item, which meets the documented placement rules. A
same-key, same-model, same-endpoint request with the instruction in the top-level system field
succeeds. Captured Claude Code requests using the tested Opus models also contain this role;
the tested CLI turns failed with the same 400. This report does not claim the feature is
available on every Claude model (Anthropic explicitly excludes Sonnet 5), nor that every Claude
Code turn necessarily sends such a message.
Expected Behavior
For a model on which Anthropic documents this capability, /provider/v1/messages should accept a
mid-conversation role:"system" message at a valid position as described at
https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages.
If the Provider API intentionally does not implement it, please document the model/feature limitation
explicitly and return an actionable error. Moving a mid-conversation system instruction to the
top-level system field is not generally semantics-preserving: it changes the instruction's
position in the conversation and can affect prompt-cache behavior.
Actual Behavior
The tested user → system[last] request returns HTTP 400:
{"type":"error","error":{"type":"invalid_request_error","message":"Invalid input at messages.1.role"}}
Steps to reproduce the issue
- Use a valid Command Code Provider API key in the local environment variable
CMDCODE_KEY.
Run these requests against the same endpoint, model (claude-opus-5-5), and key. The
system text is identical; its placement differs. The second request is a validation
control, not an equivalent multi-turn workaround.
BASE=https://api.commandcode.ai/provider/v1/messages
H=(-H "Authorization: Bearer $CMDCODE_KEY" -H 'content-type: application/json')
# (a) Documented user -> system[last] placement: HTTP 400.
curl -sS -w '\nHTTP %{http_code}\n' "${H[@]}" -X POST "$BASE" \
-d '{"model":"claude-opus-5-5","max_tokens":16,
"messages":[{"role":"user","content":"hi"},
{"role":"system","content":"ctx"}]}'
# -> 400 Invalid input at messages.1.role
# (b) Same key/model/endpoint; top-level system control: HTTP 200.
curl -sS -w '\nHTTP %{http_code}\n' "${H[@]}" -X POST "$BASE" \
-d '{"model":"claude-opus-5-5","max_tokens":16,
"system":"ctx","messages":[{"role":"user","content":"hi"}]}'
# -> 200
# (c) Same key/model/endpoint; top-level block-array system control: HTTP 200.
curl -sS -w '\nHTTP %{http_code}\n' "${H[@]}" -X POST "$BASE" \
-d '{"model":"claude-opus-5-5","max_tokens":16,
"system":[{"type":"text","text":"ctx"}],
"messages":[{"role":"user","content":"hi"}]}'
# -> 200
- The documented
user → system[last]position fails with both string and tested text-block
array content. This report does not claim thatsystemis valid at every array index or
that every possible request field has been independently audited. Adding or removing the
testedanthropic-beta: context-1m-2025-08-07header did not change the 400; this
mid-conversation system capability itself does not require a beta header. - Separately, captured Claude Code 2.1.274/2.1.278 requests used the same
user → system[last]
role sequence and encounteredInvalid input at messages.1.roleon the tested Opus turns.
The captured CLI sample usedclaude-opus-5; the controlled HTTP requests above used
claude-opus-5-5. These are two related observations, not one same-model CLI experiment.
Tested /messages request shape (claude-opus-5-5, same credential) |
Observed HTTP |
|---|---|
| User message only | 200 |
| User followed by system at index 1, last in array | 400 |
Top-level system as string |
200 |
Top-level system as text-block array |
200 |
| Valid-position user + system, with tested beta header | 400 |
| Valid-position user + system, without tested beta header | 400 |
Command Code Version
N/A — reporting against the Provider API directly (gateway, server-side).
Operating System
Linux
Terminal/IDE
server-side / n/a
Shell
bash
Session file (optional)
No response
Fix prompt (optional)
POST /provider/v1/messages currently returns 400 Invalid input at messages.1.role for a
claude-opus-5-5 request containing a mid-conversation role:"system" item immediately after
user and last in the messages array. Anthropic documents this exact placement for Opus 5.5
without a beta header. With the same key/model/endpoint, a top-level system control returns
200. Make /messages accept the documented valid placement for supported models, or clearly
publish this capability limitation and provide an actionable error. Verify the original shape
and a real Claude Code tool/streaming turn; do not assume accepting an arbitrary index or
hoisting a mid-conversation instruction preserves the same semantics.
Additional context
- Environment: Ubuntu 24.04, kernel 6.8.0-139, x86_64. Captured client versions: Claude Code
2.1.274 and 2.1.278. Raw HTTP controls used Opus 5.5; the captured CLI example used Opus 5.
The two CLI versions emitted the testedmessages[1].role="system"shape; this does not
establish identical behavior for all future versions or every turn. - Endpoint:
https://api.commandcode.ai/provider/v1/messages; API-key auth. The raw HTTP
user-only request returns 200, excluding a bad key or a wrong URL for that control. No key
value is included here. - Anthropic's feature guide lists Opus 5.5 / Opus 5 but explicitly excludes Sonnet 5. The
generic Messages API reference still has older prose saying there is no inputsystem
role, while its role enum and the dedicated feature guide include it; this report follows
the dedicated feature's model and placement rules. - Scope correction: earlier wording in this issue generalized to “all models”, “every turn”,
and “any index” and suggested hoisting the message to top-levelsystemas a client fix.
Those claims are withdrawn. The measured HTTP statuses and valid-position reproduction
remain as recorded; the controlled HTTP and CLI models are identified separately above.
- 主要语言
- 没有语言数据
- 星标
- 4k
- 派生
- 357
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
CommandCodeAI/command-code 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
CommandCodeAI/command-code#933 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
CommandCodeAI/command-code#855 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
CommandCodeAI/command-code#841 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
CommandCodeAI/command-code#655 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
CommandCodeAI/command-code#608 ·
查看 CommandCodeAI/command-code 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
web-infra-dev/rsbuild#8608 ·
维护者通常 1 天内回复
-
google_chat: format_message leaks GCn placeholders when inline code is inside bold/header/link text未关闭comp/plugins P3 sweeper:risk-message-delivery type/bug
难度 2/5 1-3 小时 新手友好度 78/100
NousResearch/hermes-agent#128985 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
vector-store
难度 2/5 1-3 小时 新手友好度 86/100
维护者通常 1 天内回复