diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py index f15c6393cb2..706e76932e8 100644 --- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py +++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_handler.py @@ -141,7 +141,7 @@ class GoogleBatchEmbeddings(VertexLLM): vertex_location=None, vertex_credentials=None, aembedding: bool | None = False, - timeout=300, + timeout: float | httpx.Timeout | None = 300, client=None, extra_headers: dict | None = None, drop_params: bool = False, diff --git a/litellm/main.py b/litellm/main.py index f30d93361e5..cd5de318c1f 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -7169,6 +7169,7 @@ def embedding( custom_llm_provider="gemini", api_key=gemini_api_key, api_base=api_base, + timeout=timeout, client=client, extra_headers=headers, drop_params=drop_unsupported_params, @@ -7222,6 +7223,7 @@ def embedding( custom_llm_provider="vertex_ai", api_key=None, api_base=api_base, + timeout=timeout, client=client, extra_headers=headers, drop_params=drop_unsupported_params, diff --git a/tests/unit/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_handler.py b/tests/unit/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_handler.py index 231bc25a7f0..12c8a7e0b13 100644 --- a/tests/unit/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_handler.py +++ b/tests/unit/llms/vertex_ai/gemini_embeddings/test_batch_embed_content_handler.py @@ -88,3 +88,86 @@ async def test_async_resolve_file_references_fetches_the_file_metadata_for_both_ async_handler=AsyncHTTPHandler(transport=httpx.MockTransport(_files_api_metadata)), ) assert resolved == {reference: {"mime_type": "video/mp4", "uri": FILES_URI}} + + +@pytest.mark.parametrize("sync_mode", [True, False]) +@pytest.mark.asyncio +async def test_gemini_embedding_forwards_timeout_to_batch_handler( + monkeypatch: pytest.MonkeyPatch, + sync_mode: bool, +) -> None: + """Regression for #47300: main.embedding must pass timeout into GoogleBatchEmbeddings.""" + captured: dict[str, object] = {} + + def _fake_batch_embeddings(**kwargs: object) -> litellm.EmbeddingResponse: + captured.clear() + captured.update(kwargs) + response = litellm.EmbeddingResponse() + response.data = [{"embedding": [0.1, 0.2], "index": 0, "object": "embedding"}] + return response + + monkeypatch.setattr(litellm.main.google_batch_embeddings, "batch_embeddings", _fake_batch_embeddings) + + if sync_mode: + litellm.embedding( + model="gemini/gemini-embedding-001", + input=["hello"], + api_key="gemini-test-key", + timeout=45, + ) + else: + await litellm.aembedding( + model="gemini/gemini-embedding-001", + input=["hello"], + api_key="gemini-test-key", + timeout=45, + ) + + assert "timeout" in captured + assert captured["timeout"] == 45 + + +@pytest.mark.parametrize("sync_mode", [True, False]) +@pytest.mark.asyncio +async def test_vertex_ai_embed_content_forwards_timeout_to_batch_handler( + monkeypatch: pytest.MonkeyPatch, + sync_mode: bool, +) -> None: + """Regression for #47300: vertex_ai uses_embed_content path must pass timeout.""" + captured: dict[str, object] = {} + + def _fake_batch_embeddings(**kwargs: object) -> litellm.EmbeddingResponse: + captured.clear() + captured.update(kwargs) + response = litellm.EmbeddingResponse() + response.data = [{"embedding": [0.1, 0.2], "index": 0, "object": "embedding"}] + return response + + monkeypatch.setattr(litellm.main.google_batch_embeddings, "batch_embeddings", _fake_batch_embeddings) + # Force the uses_embed_content branch without depending on live model-cost JSON. + monkeypatch.setattr( + litellm.main, + "get_model_info", + lambda **_kwargs: {"uses_embed_content": True}, + ) + + if sync_mode: + litellm.embedding( + model="vertex_ai/gemini-embedding-2", + input=["hello"], + timeout=45, + vertex_project="test-project", + vertex_location="us-central1", + ) + else: + await litellm.aembedding( + model="vertex_ai/gemini-embedding-2", + input=["hello"], + timeout=45, + vertex_project="test-project", + vertex_location="us-central1", + ) + + assert "timeout" in captured + assert captured["timeout"] == 45 + assert captured.get("custom_llm_provider") == "vertex_ai"