Repository navigation
fix(moonshot): preserve image_url blocks in multimodal messages - #21595
Merged
Chesars merged 1 commit intoFeb 27, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Moonshot's _transform_messages unconditionally flattened content arrays to plain text, dropping image_url blocks. Vision models like kimi-k2.5 accept the standard OpenAI content array format. Now checks for image_url blocks before flattening — if any message contains images the content array is preserved intact. Fixes BerriAI#20862
Chesars
force-pushed
the
fix/moonshot-preserve-image-url-content
branch
from
February 19, 2026 19:44
a780b8f to
c5cec60
Compare
Contributor
Greptile SummaryThis PR fixes a bug where Moonshot's Key changes:
The fix is minimal, focused, and maintains backward compatibility for text-only requests while enabling vision capabilities. Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/llms/moonshot/chat/transformation.py | Adds image_url detection logic to preserve content arrays for vision models while maintaining text-only flattening for other models |
| tests/test_litellm/llms/moonshot/test_moonshot_chat_transformation.py | Adds two comprehensive tests for image_url preservation and text-only flattening behavior |
| docs/my-website/docs/providers/moonshot.md | Adds clear documentation section for vision support with usage example |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User calls litellm.completion] --> B[MoonshotChatConfig._transform_messages]
B --> C{Check all messages for image_url}
C -->|Has image_url| D[Skip flattening]
C -->|No image_url| E[Call handle_messages_with_content_list_to_str_conversion]
D --> F[Content array preserved]
E --> G[Content flattened to string]
F --> H[Send to Moonshot Vision API]
G --> I[Send to Moonshot Text API]
H --> J[Image reaches API successfully]
I --> K[Text-only request processed]
Last reviewed commit: c5cec60
Chesars
merged commit Feb 27, 2026
1552775
into
BerriAI:litellm_oss_staging_02_27_2026
9 of 21 checks passed
3 of 6 tasks
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…mage-url-content fix(moonshot): preserve image_url blocks in multimodal messages
This branch was successfully deployed
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.
Relevant issues
Fixes #20862
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirementmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewType
🐛 Bug Fix
📖 Documentation
Changes
Moonshot's
_transform_messagesunconditionally flattened content arrays to plain strings viahandle_messages_with_content_list_to_str_conversion(), dropping all non-text content blocks (image_url,input_audio,video_url,file, etc.). Multimodal models likekimi-k2.5accept the standard OpenAI content array format.Fix: Before flattening, check if any message contains a non-text content part (
type != "text"). If so, skip flattening and preserve the content array. If all parts are text-only, flatten as before (required by Moonshot text models). This covers the full OpenAI content spec, not just images.Example request
Before fix: the content array was flattened to the string
"What is in this image?"— theimage_urlblock was dropped.After fix: the content array is preserved as-is, and the multimodal payload reaches the Moonshot API.
Files changed
litellm/llms/moonshot/chat/transformation.py— Skip flattening when any content part hastype != "text"tests/test_litellm/llms/moonshot/test_moonshot_chat_transformation.py— 3 new tests: image_url preserved, input_audio preserved, text-only flatteneddocs/my-website/docs/providers/moonshot.md— Add "Image / Vision Support" section with usage example