concatenate multple text parts for gemini models#1466
Merged
VisargD merged 1 commit intoDec 15, 2025
Conversation
roh26it
approved these changes
Dec 11, 2025
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.
Description
When using Gemini models (especially
gemini-3-pro-image-preview) that return responses with multiple text parts, thecontentfield only contains the last text fragment instead of all text parts concatenated together.Root Cause
In the response transformation code, when iterating through multiple text parts:
Example
Response received:
{ "message": { "content": " mostly obscured by the red one and very blurred...", // ❌ Only last fragment "content_blocks": [ { "type": "thinking", "thinking": "..." }, { "type": "text", "text": "VERIFIED: A photorealistic rendering shows..." }, // ✅ First text part { "type": "text", "text": ", a blue die is on the left..." }, // ✅ Second text part { "type": "text", "text": " mostly obscured by the red one..." } // ❌ Only this ends up in content ] } }Expected
contentfield:Impact
contentfield doesn't include the first text part which contains the instruction-following prefixcontent_blocks, but OpenAI-compatible clients expect the complete text incontentgemini-3-pro-image-preview,gemini-2.0-flash-thinking-exp, and other models that split responses into multiple text partsFiles Affected
Non-streaming responses:
src/providers/google-vertex-ai/chatComplete.tsline 468src/providers/google/chatComplete.tsline 577Streaming responses:
src/providers/google-vertex-ai/chatComplete.tsline 644src/providers/google/chatComplete.tsline 704Proposed Fix
Change from overwriting to concatenating:
Workaround for Users
Until fixed, users can manually concatenate text blocks:
Requires
x-portkey-strict-open-ai-compliance: falseto receivecontent_blocks.