diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index 678877c0721..818dc8d45f0 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -1380,6 +1380,8 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): _content_str = "" if "text" in part: text_content = part["text"] + if text_content is None: + continue # Check if text content is audio data URI - if so, exclude from text content if text_content.startswith("data:audio") and ";base64," in text_content: try: diff --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.py index 20e7aec377b..4e323fa2821 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 @@ -441,6 +441,25 @@ def test_vertex_ai_empty_content(): assert reasoning_content is None +def test_vertex_ai_null_text_part_is_ignored(): + from litellm.llms.vertex_ai.gemini.vertex_and_google_ai_studio_gemini import ( + VertexGeminiConfig, + ) + from litellm.types.llms.vertex_ai import HttpxPartType + + v = VertexGeminiConfig() + parts = cast( + List[HttpxPartType], + [ + {"text": None}, + {"text": "Generated image"}, + ], + ) + content, reasoning_content = v.get_assistant_content_message(parts=parts) + assert content == "Generated image" + assert reasoning_content is None + + @pytest.mark.parametrize( "usage_metadata, inclusive, expected_usage", [