fix(gemini): support detail parameter for image resolution on Gemini 2.x models - #17662
Merged
Chesars merged 1 commit intoMar 4, 2026
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@Chesars can you please fix this linting error?
|
Contributor
Author
Contributor
Greptile SummaryThis PR adds support for OpenAI's
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/gemini/transformation.py | Adds _get_highest_media_resolution and _extract_max_media_resolution_from_messages helper functions, and integrates global mediaResolution into generationConfig for Gemini 2.x models. Logic is correct and handles edge cases (auto, None, file types). The "gemini-2" in model check follows existing patterns but is hardcoded (previously flagged). |
| litellm/types/llms/vertex_ai.py | Adds mediaResolution: str field to GenerationConfig TypedDict. Minimal, correct change. |
| tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py | Comprehensive test suite covering priority ordering, extraction from image_url and file types, Gemini 2.x/3.x/1.x model behavior, and edge cases. All tests are mock-based with no real network calls. |
| docs/my-website/docs/providers/gemini.md | Updated documentation to describe both per-part (Gemini 3+) and global (Gemini 2.x) media resolution behavior, with a clear version comparison table. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[User sends messages with detail param] --> B{Model version?}
B -->|"gemini-3" in model| C[Per-part: _apply_gemini_3_metadata\nsets media_resolution on each part]
B -->|"gemini-2" in model| D[_extract_max_media_resolution_from_messages]
B -->|"gemini-1.x"| E[No mediaResolution support]
D --> F{Scan all content parts}
F --> G[image_url parts]
F --> H[file parts]
G --> I[Extract detail value]
H --> I
I --> J[_get_highest_media_resolution\nCompare priorities:\nultra_high=4, high=3, medium=2, low=1]
J --> K{max_resolution found?}
K -->|Yes| L[_convert_detail_to_media_resolution_enum]
K -->|No / auto| M[No mediaResolution set]
L --> N[Set generationConfig.mediaResolution\nglobally for all parts]
Last reviewed commit: c1a8bdd
…2.x models Add global media_resolution support for Gemini 2.x models (2.0, 2.5) when using OpenAI's detail parameter on images. Previously, the detail parameter was only working for Gemini 3+ models (per-part) and was silently ignored for older Gemini models. - Add _get_highest_media_resolution() and _extract_max_media_resolution_from_messages() to extract highest detail from all images/files in a request - Update _transform_request_body() to add mediaResolution to generationConfig for Gemini 2.x models only (not 1.x which doesn't support it, not 3+ which uses per-part) - Add mediaResolution field to GenerationConfig TypedDict - Support detail extraction from both image_url and file content types - Add comprehensive unit tests and update documentation
Chesars
force-pushed
the
fix/gemini-2x-media-resolution-detail-parameter
branch
from
March 4, 2026 20:32
07d4895 to
c1a8bdd
Compare
Chesars
merged commit Mar 4, 2026
35b9ec3
into
BerriAI:litellm_oss_staging_03_04_2026
4 of 5 checks passed
fzowl
pushed a commit
to fzowl/litellm
that referenced
this pull request
Jun 24, 2026
…olution-detail-parameter fix(gemini): support detail parameter for image resolution on Gemini 2.x models
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.


Title
fix(gemini): support detail parameter for image resolution on Gemini 2.x models
Relevant issues
Fixes #17084
Pre-Submission checklist
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitType
🐛 Bug Fix
📖 Documentation
Summary
Add global
media_resolutionsupport for Gemini 2.x models (2.0, 2.5) when using OpenAI'sdetailparameter on images.Previously, the
detailparameter was only working for Gemini 3+ models (per-part) and did not work for other Gemini models.Example Request
Changes
_get_highest_media_resolution()to compare resolution levels_extract_max_media_resolution_from_messages()to extract highest detail from all images_transform_request_body()to addmediaResolutiontogenerationConfigfor Gemini 2.x modelsTests Added
✅
test_transform_request_body_gemini_2x_adds_media_resolution✅
test_extract_max_media_resolution_multiple_images_mixed✅
test_get_highest_media_resolution_high_wins