diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.py index 41cead57739..1217c444c24 100644 --- a/litellm/llms/vertex_ai/gemini/transformation.py +++ b/litellm/llms/vertex_ai/gemini/transformation.py @@ -5,6 +5,7 @@ Why separate file? Make it easy to see how transformation works """ import json import os +import re from typing import TYPE_CHECKING, Dict, List, Literal, Optional, Tuple, Union, cast import httpx @@ -208,7 +209,7 @@ def _process_gemini_media( return _apply_gemini_3_metadata( part, model, media_resolution_enum, video_metadata ) - elif "https://generativelanguage.googleapis.com/v1beta/files/" in image_url: + elif re.search(r"https://generativelanguage\.googleapis\.com/v[^/]+/files/", image_url): # Gemini Files API URI — mime type is already known by the API, # no need to resolve it from the URL (which would cause a 403). file_data = FileDataType(file_uri=image_url) diff --git a/litellm/types/llms/vertex_ai.py b/litellm/types/llms/vertex_ai.py index c49fc96a65b..c46b0d82d0e 100644 --- a/litellm/types/llms/vertex_ai.py +++ b/litellm/types/llms/vertex_ai.py @@ -17,9 +17,9 @@ class FunctionCall(TypedDict): args: Optional[dict] -class FileDataType(TypedDict): +class FileDataType(TypedDict, total=False): mime_type: str - file_uri: str # the cloud storage uri of storing this file + file_uri: Required[str] # the cloud storage uri of storing this file class BlobType(TypedDict, total=False): diff --git a/tests/test_litellm/llms/bedrock/files/expected_bedrock_batch_completions.jsonl b/tests/test_litellm/llms/bedrock/files/expected_bedrock_batch_completions.jsonl index c58963bb1de..8bb35ba95d7 100644 --- a/tests/test_litellm/llms/bedrock/files/expected_bedrock_batch_completions.jsonl +++ b/tests/test_litellm/llms/bedrock/files/expected_bedrock_batch_completions.jsonl @@ -1,2 +1,2 @@ -{"recordId": "request-1", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "Hello world!"}]}], "max_tokens": 10, "system": [{"type": "text", "text": "You are a helpful assistant."}], "anthropic_version": "bedrock-2023-05-31"}} -{"recordId": "request-2", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "Hello world!"}]}], "max_tokens": 10, "system": [{"type": "text", "text": "You are an unhelpful assistant."}], "anthropic_version": "bedrock-2023-05-31"}} +{"recordId": "request-1", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "Hello world!"}]}], "max_tokens": 10, "system": [{"type": "text", "text": "You are a helpful assistant."}], "anthropic_version": "bedrock-2023-05-31", "anthropic_beta": []}} +{"recordId": "request-2", "modelInput": {"messages": [{"role": "user", "content": [{"type": "text", "text": "Hello world!"}]}], "max_tokens": 10, "system": [{"type": "text", "text": "You are an unhelpful assistant."}], "anthropic_version": "bedrock-2023-05-31", "anthropic_beta": []}} 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.py index 1f3841b6738..130d9c8e260 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 @@ -1849,3 +1849,5 @@ def test_process_gemini_media_files_api_uri_with_explicit_format(): assert "file_data" in part assert part["file_data"]["file_uri"] == gemini_file_uri + # The Files API already knows the mime type; explicit format must NOT be forwarded. + assert part["file_data"].get("mime_type") is None