The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Supports setting media_resolution and fps parameters on each video file, when using Gemini video understanding. (#19273)
Kris Xia56bf6001e9c4
diff --git a/docs/my-website/docs/providers/gemini.md b/docs/my-website/docs/providers/gemini.mdindex 32dea2069b7..11866e68d15 100644--- a/docs/my-website/docs/providers/gemini.md+++ b/docs/my-website/docs/providers/gemini.md@@ -1547,16 +1547,21 @@ LiteLLM Supports the following image types passed in `url`- Images with direct links - https://storage.googleapis.com/github-repo/img/gemini/intro/landmark3.jpg- Image in local storage - ./localimage.jpeg-## Image Resolution Control (Gemini 3+)+## Media Resolution Control (Images & Videos)-For Gemini 3+ models, LiteLLM supports per-part media resolution control using OpenAI's `detail` parameter. This allows you to specify different resolution levels for individual images in your request.+For Gemini 3+ models, LiteLLM supports per-part media resolution control using OpenAI's `detail` parameter. This allows you to specify different resolution levels for individual images and videos in your request, whether using `image_url` or `file` content types.**Supported `detail` values:**- `"low"` - Maps to `media_resolution: "low"` (280 tokens for images, 70 tokens per frame for videos)+- `"medium"` - Maps to `media_resolution: "medium"`- `"high"` - Maps to `media_resolution: "high"` (1120 tokens for images)+- `"ultra_high"` - Maps to `media_resolution: "ultra_high"`- `"auto"` or `None` - Model decides optimal resolution (no `media_resolution` set)-**Usage Example:**+**Usage Examples:**++<Tabs>+<TabItem value="images" label="Images">```pythonfrom litellm import completion@@ -1593,10 +1598,193 @@ response = completion()```+</TabItem>+<TabItem value="videos" label="Videos with Files">++```python+from litellm import completion++messages = [+ {+ "role": "user",+ "content": [+ {+ "type": "text",+ "text": "Analyze this video"+ },+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "detail": "high" # High resolution for detailed video analysis+ }+ }+ ]+ }+]++response = completion(+ model="gemini/gemini-3-pro-preview",+ messages=messages,+)+```++</TabItem>+</Tabs>+:::info-**Per-Part Resolution:** Each image in your request can have its own `detail` setting, allowing mixed-resolution requests (e.g., a high-res chart alongside a low-res icon). This feature is only available for Gemini 3+ models.+**Per-Part Resolution:** Each image or video in your request can have its own `detail` setting, allowing mixed-resolution requests (e.g., a high-res chart alongside a low-res icon). This feature works with both `image_url` and `file` content types, and is only available for Gemini 3+ models.:::+## Video Metadata Control++For Gemini 3+ models, LiteLLM supports fine-grained video processing control through the `video_metadata` field. This allows you to specify frame extraction rates and time ranges for video analysis.++**Supported `video_metadata` parameters:**++| Parameter | Type | Description | Example |+|-----------|------|-------------|---------|+| `fps` | Number | Frame extraction rate (frames per second) | `5` |+| `start_offset` | String | Start time for video clip processing | `"10s"` |+| `end_offset` | String | End time for video clip processing | `"60s"` |++:::note+**Field Name Conversion:** LiteLLM automatically converts snake_case field names to camelCase for the Gemini API:+- `start_offset` → `startOffset`+- `end_offset` → `endOffset`+- `fps` remains unchanged+:::++:::warning+- **Gemini 3+ Only:** This feature is only available for Gemini 3.0 and newer models+- **Video Files Recommended:** While `video_metadata` is designed for video files, error handling for other media types is delegated to the Vertex AI API+- **File Formats Supported:** Works with `gs://`, `https://`, and base64-encoded video files+:::++**Usage Examples:**++<Tabs>+<TabItem value="basic" label="Basic Video Metadata">++```python+from litellm import completion++response = completion(+ model="gemini/gemini-3-pro-preview",+ messages=[+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video clip"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "video_metadata": {+ "fps": 5, # Extract 5 frames per second+ "start_offset": "10s", # Start from 10 seconds+ "end_offset": "60s" # End at 60 seconds+ }+ }+ }+ ]+ }+ ]+)++print(response.choices[0].message.content)+```++</TabItem>+<TabItem value="combined" label="Combined with Detail">++```python+from litellm import completion++response = completion(+ model="gemini/gemini-3-pro-preview",+ messages=[+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Provide detailed analysis of this video segment"},+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/presentation.mp4",+ "format": "video/mp4",+ "detail": "high", # High resolution for detailed analysis+ "video_metadata": {+ "fps": 10, # Extract 10 frames per second+ "start_offset": "30s", # Start from 30 seconds+ "end_offset": "90s" # End at 90 seconds+ }+ }+ }+ ]+ }+ ]+)++print(response.choices[0].message.content)+```++</TabItem>+<TabItem value="proxy" label="PROXY">++1. Setup config.yaml++```yaml+model_list:+ - model_name: gemini-3-pro+ litellm_params:+ model: gemini/gemini-3-pro-preview+ api_key: os.environ/GEMINI_API_KEY+```++2. Start proxy++```bash+litellm --config /path/to/config.yaml+```++3. Make request++```bash+curl http://0.0.0.0:4000/v1/chat/completions \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer <YOUR-LITELLM-KEY>" \+ -d '{+ "model": "gemini-3-pro",+ "messages": [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video clip"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "detail": "high",+ "video_metadata": {+ "fps": 5,+ "start_offset": "10s",+ "end_offset": "60s"+ }+ }+ }+ ]+ }+ ]+ }'+```++</TabItem>+</Tabs>+## Sample Usage```pythonimport osdiff --git a/docs/my-website/docs/providers/vertex.md b/docs/my-website/docs/providers/vertex.mdindex be2bf86ab10..c47d7d914a8 100644--- a/docs/my-website/docs/providers/vertex.md+++ b/docs/my-website/docs/providers/vertex.md@@ -1957,6 +1957,244 @@ assert isinstance(```+## Media Resolution Control (Images & Videos)++For Gemini 3+ models, LiteLLM supports per-part media resolution control using OpenAI's `detail` parameter. This allows you to specify different resolution levels for individual images and videos in your request, whether using `image_url` or `file` content types.++**Supported `detail` values:**+- `"low"` - Maps to `media_resolution: "low"` (280 tokens for images, 70 tokens per frame for videos)+- `"medium"` - Maps to `media_resolution: "medium"`+- `"high"` - Maps to `media_resolution: "high"` (1120 tokens for images)+- `"ultra_high"` - Maps to `media_resolution: "ultra_high"`+- `"auto"` or `None` - Model decides optimal resolution (no `media_resolution` set)++**Usage Examples:**++<Tabs>+<TabItem value="images" label="Images">++```python+from litellm import completion++messages = [+ {+ "role": "user",+ "content": [+ {+ "type": "image_url",+ "image_url": {+ "url": "https://example.com/chart.png",+ "detail": "high" # High resolution for detailed chart analysis+ }+ },+ {+ "type": "text",+ "text": "Analyze this chart"+ },+ {+ "type": "image_url",+ "image_url": {+ "url": "https://example.com/icon.png",+ "detail": "low" # Low resolution for simple icon+ }+ }+ ]+ }+]++response = completion(+ model="vertex_ai/gemini-3-pro-preview",+ messages=messages,+)+```++</TabItem>+<TabItem value="videos" label="Videos with Files">++```python+from litellm import completion++messages = [+ {+ "role": "user",+ "content": [+ {+ "type": "text",+ "text": "Analyze this video"+ },+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "detail": "high" # High resolution for detailed video analysis+ }+ }+ ]+ }+]++response = completion(+ model="vertex_ai/gemini-3-pro-preview",+ messages=messages,+)+```++</TabItem>+</Tabs>++:::info+**Per-Part Resolution:** Each image or video in your request can have its own `detail` setting, allowing mixed-resolution requests (e.g., a high-res chart alongside a low-res icon). This feature works with both `image_url` and `file` content types, and is only available for Gemini 3+ models.+:::++## Video Metadata Control++For Gemini 3+ models, LiteLLM supports fine-grained video processing control through the `video_metadata` field. This allows you to specify frame extraction rates and time ranges for video analysis.++**Supported `video_metadata` parameters:**++| Parameter | Type | Description | Example |+|-----------|------|-------------|---------|+| `fps` | Number | Frame extraction rate (frames per second) | `5` |+| `start_offset` | String | Start time for video clip processing | `"10s"` |+| `end_offset` | String | End time for video clip processing | `"60s"` |++:::note+**Field Name Conversion:** LiteLLM automatically converts snake_case field names to camelCase for the Gemini API:+- `start_offset` → `startOffset`+- `end_offset` → `endOffset`+- `fps` remains unchanged+:::++:::warning+- **Gemini 3+ Only:** This feature is only available for Gemini 3.0 and newer models+- **Video Files Recommended:** While `video_metadata` is designed for video files, error handling for other media types is delegated to the Vertex AI API+- **File Formats Supported:** Works with `gs://`, `https://`, and base64-encoded video files+:::++**Usage Examples:**++<Tabs>+<TabItem value="basic" label="Basic Video Metadata">++```python+from litellm import completion++response = completion(+ model="vertex_ai/gemini-3-pro-preview",+ messages=[+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video clip"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "video_metadata": {+ "fps": 5, # Extract 5 frames per second+ "start_offset": "10s", # Start from 10 seconds+ "end_offset": "60s" # End at 60 seconds+ }+ }+ }+ ]+ }+ ]+)++print(response.choices[0].message.content)+```++</TabItem>+<TabItem value="combined" label="Combined with Detail">++```python+from litellm import completion++response = completion(+ model="vertex_ai/gemini-3-pro-preview",+ messages=[+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Provide detailed analysis of this video segment"},+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/presentation.mp4",+ "format": "video/mp4",+ "detail": "high", # High resolution for detailed analysis+ "video_metadata": {+ "fps": 10, # Extract 10 frames per second+ "start_offset": "30s", # Start from 30 seconds+ "end_offset": "90s" # End at 90 seconds+ }+ }+ }+ ]+ }+ ]+)++print(response.choices[0].message.content)+```++</TabItem>+<TabItem value="proxy" label="PROXY">++1. Setup config.yaml++```yaml+model_list:+ - model_name: gemini-3-pro+ litellm_params:+ model: vertex_ai/gemini-3-pro-preview+ vertex_project: your-project+ vertex_location: us-central1+```++2. Start proxy++```bash+litellm --config /path/to/config.yaml+```++3. Make request++```bash+curl http://0.0.0.0:4000/v1/chat/completions \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer <YOUR-LITELLM-KEY>" \+ -d '{+ "model": "gemini-3-pro",+ "messages": [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video clip"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://my-bucket/video.mp4",+ "format": "video/mp4",+ "detail": "high",+ "video_metadata": {+ "fps": 5,+ "start_offset": "10s",+ "end_offset": "60s"+ }+ }+ }+ ]+ }+ ]+ }'+```++</TabItem>+</Tabs>## Usage - PDF / Videos / Audio etc. Filesdiff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.pyindex 8f1338db92e..96e0963a920 100644--- a/litellm/llms/vertex_ai/gemini/transformation.py+++ b/litellm/llms/vertex_ai/gemini/transformation.py@@ -72,17 +72,64 @@ def _convert_detail_to_media_resolution_enum(return {"level": "MEDIA_RESOLUTION_MEDIUM"}elif detail == "high":return {"level": "MEDIA_RESOLUTION_HIGH"}+ elif detail == "ultra_high":+ return {"level": "MEDIA_RESOLUTION_ULTRA_HIGH"}return None-def _process_gemini_image(- image_url: str,+def _apply_gemini_3_metadata(+ part: PartType,+ model: Optional[str],+ media_resolution_enum: Optional[Dict[str, str]],+ video_metadata: Optional[Dict[str, Any]],+) -> PartType:+ """+ Apply the unique media_resolution and video_metadata parameters of Gemini 3++ """+ if model is None:+ return part++ from .vertex_and_google_ai_studio_gemini import VertexGeminiConfig++ if not VertexGeminiConfig._is_gemini_3_or_newer(model):+ return part++ part_dict = dict(part)++ if media_resolution_enum is not None:+ part_dict["media_resolution"] = media_resolution_enum++ if video_metadata is not None:+ gemini_video_metadata = {}+ if "fps" in video_metadata:+ gemini_video_metadata["fps"] = video_metadata["fps"]+ if "start_offset" in video_metadata:+ gemini_video_metadata["startOffset"] = video_metadata["start_offset"]+ if "end_offset" in video_metadata:+ gemini_video_metadata["endOffset"] = video_metadata["end_offset"]+ if gemini_video_metadata:+ part_dict["video_metadata"] = gemini_video_metadata++ return cast(PartType, part_dict)+++def _process_gemini_media(+ image_url: str,format: Optional[str] = None,media_resolution_enum: Optional[Dict[str, str]] = None,model: Optional[str] = None,+ video_metadata: Optional[Dict[str, Any]] = None,) -> PartType:"""- Given an image URL, return the appropriate PartType for Gemini+ Given a media URL (image, audio, or video), return the appropriate PartType for Gemini+ By the way, actually video_metadata can only be used with videos; it cannot be used with images, audio, or files. However, I haven't made any special handling because vertex returns a parameter error.++ Args:+ image_url: The URL or base64 string of the media (image, audio, or video)+ format: The MIME type of the media+ media_resolution_enum: Media resolution level (for Gemini 3+)+ model: The model name (to check version compatibility)+ video_metadata: Video-specific metadata (fps, start_offset, end_offset)"""try:@@ -104,14 +151,9 @@ def _process_gemini_image(mime_type = formatfile_data = FileDataType(mime_type=mime_type, file_uri=image_url)part: PartType = {"file_data": file_data}-- if media_resolution_enum is not None and model is not None:- from .vertex_and_google_ai_studio_gemini import VertexGeminiConfig- if VertexGeminiConfig._is_gemini_3_or_newer(model):- part_dict = dict(part)- part_dict["media_resolution"] = media_resolution_enum- return cast(PartType, part_dict)- return part+ return _apply_gemini_3_metadata(+ part, model, media_resolution_enum, video_metadata+ )elif ("https://" in image_urland (image_type := format or _get_image_mime_type_from_url(image_url))@@ -119,27 +161,16 @@ def _process_gemini_image():file_data = FileDataType(mime_type=image_type, file_uri=image_url)part = {"file_data": file_data}-- if media_resolution_enum is not None and model is not None:- from .vertex_and_google_ai_studio_gemini import VertexGeminiConfig- if VertexGeminiConfig._is_gemini_3_or_newer(model):- part_dict = dict(part)- part_dict["media_resolution"] = media_resolution_enum- return cast(PartType, part_dict)- return part+ return _apply_gemini_3_metadata(+ part, model, media_resolution_enum, video_metadata+ )elif "http://" in image_url or "https://" in image_url or "base64" in image_url:image = convert_to_anthropic_image_obj(image_url, format=format)_blob: BlobType = {"data": image["data"], "mime_type": image["media_type"]}-part = {"inline_data": cast(BlobType, _blob)}-- if media_resolution_enum is not None and model is not None:- from .vertex_and_google_ai_studio_gemini import VertexGeminiConfig- if VertexGeminiConfig._is_gemini_3_or_newer(model):- part_dict = dict(part)- part_dict["media_resolution"] = media_resolution_enum- return cast(PartType, part_dict)- return part+ return _apply_gemini_3_metadata(+ part, model, media_resolution_enum, video_metadata+ )raise Exception("Invalid image received - {}".format(image_url))except Exception as e:raise e@@ -253,8 +284,8 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915media_resolution_enum = _convert_detail_to_media_resolution_enum(detail)else:image_url = img_element["image_url"]- _part = _process_gemini_image(- image_url=image_url,+ _part = _process_gemini_media(+ image_url=image_url,format=format,media_resolution_enum=media_resolution_enum,model=model,@@ -279,7 +310,7 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915)))- _part = _process_gemini_image(+ _part = _process_gemini_media(image_url=openai_image_str,format=audio_format_modified,model=model,@@ -290,16 +321,24 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915file_id = file_element["file"].get("file_id")format = file_element["file"].get("format")file_data = file_element["file"].get("file_data")+ detail = file_element["file"].get("detail")+ video_metadata = file_element["file"].get("video_metadata")passed_file = file_id or file_dataif passed_file is None:raise Exception("Unknown file type. Please pass in a file_id or file_data")++ # Convert detail to media_resolution_enum+ media_resolution_enum = _convert_detail_to_media_resolution_enum(detail)+try:- _part = _process_gemini_image(- image_url=passed_file,+ _part = _process_gemini_media(+ image_url=passed_file,format=format,model=model,+ media_resolution_enum=media_resolution_enum,+ video_metadata=video_metadata,)_parts.append(_part)except Exception:diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.pyindex 467c57c33d5..84185b6eec0 100644--- a/litellm/types/llms/openai.py+++ b/litellm/types/llms/openai.py@@ -654,6 +654,8 @@ class ChatCompletionFileObjectFile(TypedDict, total=False):file_id: strfilename: strformat: str+ detail: str # For video/image resolution control (low, medium, high, ultra_high)+ video_metadata: Dict[str, Any] # For video-specific metadata (fps, start_offset, end_offset)class ChatCompletionFileObject(TypedDict):diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.pyindex 70e6e9452e5..ebda37bb633 100644--- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py+++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_ai_gemini_transformation.py@@ -735,13 +735,13 @@ def test_file_data_field_order():Related issue: Gemini API returns 400 INVALID_ARGUMENT when fields are in wrong order."""import json- from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_image+ from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_media# Test with HTTPS URL and explicit format (audio file)file_url = "https://generativelanguage.googleapis.com/v1beta/files/test123"format = "audio/mpeg"- result = _process_gemini_image(image_url=file_url, format=format)+ result = _process_gemini_media(image_url=file_url, format=format)# Verify the result has file_dataassert "file_data" in result@@ -770,12 +770,12 @@ def test_file_data_field_order():def test_file_data_field_order_gcs_urls():"""Test that GCS URLs also maintain correct field order."""import json- from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_image+ from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_media# Test with GCS URLgcs_url = "gs://bucket/audio.mp3"- result = _process_gemini_image(image_url=gcs_url)+ result = _process_gemini_media(image_url=gcs_url)# Verify the result has file_dataassert "file_data" in resultdiff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.pyindex f44e8640105..810769023bd 100644--- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py+++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py@@ -2653,3 +2653,273 @@ def test_gemini_image_gen_usage_metadata_prompt_vs_completion_separation():# candidatesTokenCount (1290) - image_tokens (1290) = 0assert result.completion_tokens_details.text_tokens == 0, \"Completion text tokens should be 0 (image-only response)"+++def test_file_object_detail_parameter():+ """Test that detail parameter works for type: file objects (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _gemini_convert_messages_with_history,+ )++ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "What's in this video?"},+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/video.mp4",+ "format": "video/mp4",+ "detail": "low"+ }+ }+ ]+ }+ ]++ contents = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ # Verify media_resolution is set for file objects+ assert len(contents) == 1+ assert len(contents[0]["parts"]) == 2 # text + file++ # Find the file part+ file_part = None+ for part in contents[0]["parts"]:+ if "file_data" in part:+ file_part = part+ break++ assert file_part is not None, "File part should exist"+ assert "media_resolution" in file_part, "media_resolution should be set for file objects"+ assert file_part["media_resolution"] == {"level": "MEDIA_RESOLUTION_LOW"}+++def test_video_metadata_fps():+ """Test fps parameter in video_metadata (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _gemini_convert_messages_with_history,+ )++ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://bucket/video.mp4",+ "format": "video/mp4",+ "video_metadata": {"fps": 5}+ }+ }+ ]+ }+ ]++ contents = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ # Find the file part+ file_part = None+ for part in contents[0]["parts"]:+ if "file_data" in part:+ file_part = part+ break++ assert file_part is not None+ assert "video_metadata" in file_part, "video_metadata should be present"+ assert file_part["video_metadata"]["fps"] == 5+++def test_video_metadata_complete():+ """Test all video_metadata fields: fps, start_offset, end_offset (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _gemini_convert_messages_with_history,+ )++ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze this video clip"},+ {+ "type": "file",+ "file": {+ "file_id": "gs://bucket/video.mp4",+ "format": "video/mp4",+ "video_metadata": {+ "start_offset": "10s",+ "end_offset": "60s",+ "fps": 5+ }+ }+ }+ ]+ }+ ]++ contents = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ # Find the file part+ file_part = None+ for part in contents[0]["parts"]:+ if "file_data" in part:+ file_part = part+ break++ assert file_part is not None+ assert "video_metadata" in file_part++ # Verify field name conversion: snake_case -> camelCase+ vm = file_part["video_metadata"]+ assert vm["startOffset"] == "10s", "start_offset should be converted to startOffset"+ assert vm["endOffset"] == "60s", "end_offset should be converted to endOffset"+ assert vm["fps"] == 5, "fps should remain unchanged"+++def test_detail_and_video_metadata_combined():+ """Test using both detail and video_metadata together (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _gemini_convert_messages_with_history,+ )++ messages = [+ {+ "role": "user",+ "content": [+ {"type": "text", "text": "Analyze video"},+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/video.mp4",+ "format": "video/mp4",+ "detail": "high",+ "video_metadata": {"fps": 10}+ }+ }+ ]+ }+ ]++ contents = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ # Find the file part+ file_part = None+ for part in contents[0]["parts"]:+ if "file_data" in part:+ file_part = part+ break++ assert file_part is not None+ assert "media_resolution" in file_part+ assert file_part["media_resolution"] == {"level": "MEDIA_RESOLUTION_HIGH"}+ assert "video_metadata" in file_part+ assert file_part["video_metadata"]["fps"] == 10+++def test_new_detail_levels():+ """Test new detail levels: medium and ultra_high (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _convert_detail_to_media_resolution_enum,+ _gemini_convert_messages_with_history,+ )++ # Test mapping function+ assert _convert_detail_to_media_resolution_enum("low") == {"level": "MEDIA_RESOLUTION_LOW"}+ assert _convert_detail_to_media_resolution_enum("medium") == {"level": "MEDIA_RESOLUTION_MEDIUM"}+ assert _convert_detail_to_media_resolution_enum("high") == {"level": "MEDIA_RESOLUTION_HIGH"}+ assert _convert_detail_to_media_resolution_enum("ultra_high") == {"level": "MEDIA_RESOLUTION_ULTRA_HIGH"}++ # Test with actual message transformation+ messages = [+ {+ "role": "user",+ "content": [+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/video.mp4",+ "format": "video/mp4",+ "detail": "medium"+ }+ }+ ]+ }+ ]++ contents = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ file_part = None+ for part in contents[0]["parts"]:+ if "file_data" in part:+ file_part = part+ break++ assert file_part is not None+ assert file_part["media_resolution"] == {"level": "MEDIA_RESOLUTION_MEDIUM"}+++def test_video_metadata_only_for_gemini_3():+ """Test that video_metadata is only applied for Gemini 3+ models (Issue #19026)"""+ from litellm.llms.vertex_ai.gemini.transformation import (+ _gemini_convert_messages_with_history,+ )++ messages = [+ {+ "role": "user",+ "content": [+ {+ "type": "file",+ "file": {+ "file_id": "https://example.com/video.mp4",+ "format": "video/mp4",+ "detail": "high",+ "video_metadata": {"fps": 5}+ }+ }+ ]+ }+ ]++ # Test with Gemini 1.5 (should not have video_metadata or media_resolution)+ contents_1_5 = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-1.5-pro"+ )++ file_part_1_5 = None+ for part in contents_1_5[0]["parts"]:+ if "file_data" in part:+ file_part_1_5 = part+ break++ assert file_part_1_5 is not None+ assert "media_resolution" not in file_part_1_5, "Gemini 1.5 should not have media_resolution"+ assert "video_metadata" not in file_part_1_5, "Gemini 1.5 should not have video_metadata"++ # Test with Gemini 3 (should have both)+ contents_3 = _gemini_convert_messages_with_history(+ messages=messages, model="gemini-3-pro-preview"+ )++ file_part_3 = None+ for part in contents_3[0]["parts"]:+ if "file_data" in part:+ file_part_3 = part+ break++ assert file_part_3 is not None+ assert "media_resolution" in file_part_3, "Gemini 3 should have media_resolution"+ assert "video_metadata" in file_part_3, "Gemini 3 should have video_metadata"diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex.py b/tests/test_litellm/llms/vertex_ai/test_vertex.pyindex 39ed09f81be..fdba86af4a7 100644--- a/tests/test_litellm/llms/vertex_ai/test_vertex.py+++ b/tests/test_litellm/llms/vertex_ai/test_vertex.py@@ -19,7 +19,7 @@ import pytestimport litellmfrom litellm import get_optional_params-from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_image+from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_mediafrom litellm.types.llms.vertex_ai import BlobType@@ -1191,46 +1191,46 @@ def test_logprobs():assert resp.choices[0].logprobs is not None-def test_process_gemini_image():- """Test the _process_gemini_image function for different image sources"""- from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_image+def test_process_gemini_media():+ """Test the _process_gemini_media function for different image sources"""+ from litellm.llms.vertex_ai.gemini.transformation import _process_gemini_mediafrom litellm.types.llms.vertex_ai import FileDataType# Test GCS URI- gcs_result = _process_gemini_image("gs://bucket/image.png")+ gcs_result = _process_gemini_media("gs://bucket/image.png")assert gcs_result["file_data"] == FileDataType(mime_type="image/png", file_uri="gs://bucket/image.png")# Test gs url with format specified- gcs_result = _process_gemini_image("gs://bucket/image", format="image/jpeg")+ gcs_result = _process_gemini_media("gs://bucket/image", format="image/jpeg")assert gcs_result["file_data"] == FileDataType(mime_type="image/jpeg", file_uri="gs://bucket/image")# Test HTTPS JPG URL- https_result = _process_gemini_image("https://example.com/image.jpg")+ https_result = _process_gemini_media("https://example.com/image.jpg")print("https_result JPG", https_result)assert https_result["file_data"] == FileDataType(mime_type="image/jpeg", file_uri="https://example.com/image.jpg")# Test HTTPS PNG URL- https_result = _process_gemini_image("https://example.com/image.png")+ https_result = _process_gemini_media("https://example.com/image.png")print("https_result PNG", https_result)assert https_result["file_data"] == FileDataType(mime_type="image/png", file_uri="https://example.com/image.png")# Test HTTPS VIDEO URL- https_result = _process_gemini_image("https://cloud-samples-data/video/animals.mp4")+ https_result = _process_gemini_media("https://cloud-samples-data/video/animals.mp4")print("https_result PNG", https_result)assert https_result["file_data"] == FileDataType(mime_type="video/mp4", file_uri="https://cloud-samples-data/video/animals.mp4")# Test HTTPS PDF URL- https_result = _process_gemini_image("https://cloud-samples-data/pdf/animals.pdf")+ https_result = _process_gemini_media("https://cloud-samples-data/pdf/animals.pdf")print("https_result PDF", https_result)assert https_result["file_data"] == FileDataType(mime_type="application/pdf",@@ -1239,7 +1239,7 @@ def test_process_gemini_image():# Test base64 imagebase64_image = "data:image/jpeg;base64,/9j/4AAQSkZJRg..."- base64_result = _process_gemini_image(base64_image)+ base64_result = _process_gemini_media(base64_image)print("base64_result", base64_result)assert base64_result["inline_data"]["mime_type"] == "image/jpeg"assert base64_result["inline_data"]["data"] == "/9j/4AAQSkZJRg..."@@ -1368,11 +1368,11 @@ def mock_blob():"http://subdomain.domain.com/path/to/image.png",],)-def test_process_gemini_image_http_url(+def test_process_gemini_media_http_url(http_url: str, mock_convert_url_to_base64: Mock, mock_blob: Mock) -> None:"""- Test that _process_gemini_image correctly handles HTTP URLs.+ Test that _process_gemini_media correctly handles HTTP URLs.Args:http_url: Test HTTP URL@@ -1384,7 +1384,7 @@ def test_process_gemini_image_http_url(expected_image_data = "data:image/jpeg;base64,/9j/4AAQSkZJRg..."mock_convert_url_to_base64.return_value = expected_image_data# Act- result = _process_gemini_image(http_url)+ result = _process_gemini_media(http_url)# assert result["file_data"]["file_uri"] == http_url