fix(claude-code-proxy): 合并多条 system 消息为单条前置消息 / merge multiple system messages into one leading message - #2714
Merged
EKKOLearnAI merged 1 commit intoAug 24, 2026
Conversation
…ng message Claude Code 2.1.x sends its primary prompt as the top-level 'system' field and injects additional role:'system' messages mid-conversation (e.g. the ToolSearch deferred-tools notice). anthropicToOpenAiChat kept that second system message in place, which vLLM-backed OpenAI-compatible providers reject with 400 'System message must be at the beginning.' Consolidate to exactly one leading system message, mirroring the earlier codex-proxy fix (responses.ts consolidateChatSystemMessages). Verified end-to-end: captured a real Claude Code 2.1.240 /v1/messages payload, ran it through the fixed adapter, and the resulting chat/completions body now returns 200 from the vLLM Qwen3.8-27B endpoint (previously 400).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
摘要 / Summary
Claude Code 2.1.x 把主 prompt 放在顶层 system 字段,同时会把额外的 role: 'system' 消息(如 ToolSearch 延迟工具提示)注入到 messages 中间。anthropicToOpenAiChat 原样保留该消息,产生 [system, user, system] 顺序,vLLM 等强制 system 在首位的 provider 返回 400:System message must be at the beginning。
Claude Code 2.1.x places its primary prompt in the top-level system field but also injects additional role: 'system' messages mid-conversation (e.g. the ToolSearch deferred-tools notice). anthropicToOpenAiChat kept that message in place, producing [system, user, system] order — rejected by vLLM-backed providers with 400 System message must be at the beginning.
修复 / Fix
新增 consolidateAnthropicChatSystemMessages():合并所有 system 消息为单条前置消息(顶层 system 字段优先,其余按原顺序合并)。镜像 PR #2688 对 codex-proxy 的同类修复。
Adds consolidateAnthropicChatSystemMessages(), keeping exactly one leading system message (top-level field first, additional in-message systems merged in original order). Mirrors the earlier codex-proxy fix in PR #2688.
验证 / Verification
测试计划 / Test Plan