mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-12-05 16:07:33 +00:00
Clients legally send a user text message right after tool results (step budget reminders, mid-turn steering, context-management notices). The Chat Completions -> Responses -> Anthropic chain merges that text into the same Anthropic user message as the tool_result blocks (mergeConsecutiveMessages), and convertClaudeMessagesToGeminiContents maps each Anthropic message 1:1 to one contents entry, so the final contents entry ends with functionResponse parts followed by text. Vertex rejects that shape with HTTP 400 "Requests ending with a model turn are not supported.", even though the turn is a user turn. The same happens when tool-result media is appended after the function responses for models without multimodal function responses. Split trailing non-functionResponse parts into their own trailing user turn. Part order is preserved, only the turn boundary moves; Vertex accepts the split form (verified against generateContent directly and through /v1/chat/completions).