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
test(gemini): align API key expectations
userf521e27371e9
diff --git a/tests/proxy_unit_tests/test_google_gemini_proxy_request.py b/tests/proxy_unit_tests/test_google_gemini_proxy_request.pyindex 90c2cac18d0..98eb731e871 100644--- a/tests/proxy_unit_tests/test_google_gemini_proxy_request.py+++ b/tests/proxy_unit_tests/test_google_gemini_proxy_request.py@@ -320,29 +320,30 @@ async def test_generationconfig_to_config_mapping(sample_request_payload):for Google GenAI compatibility in the main functions."""from litellm.google_genai.main import agenerate_content-+# Create a copy of the payload to avoid modifying the fixturetest_data = sample_request_payload.copy()-- # Test that agenerate_content can handle generationConfig parameter- # This should not raise an error about parameter handling- try:- # This will fail due to missing API key, but should not fail due to parameter handling++ with patch(+ "litellm.google_genai.main.base_llm_http_handler.generate_content_handler"+ ) as mock_generate_content_handler:+ mock_generate_content_handler.return_value = {"text": "mock response"}+await agenerate_content(model="gemini/gemini-2.5-flash",contents=test_data["contents"],- generationConfig=test_data["generationConfig"], # Pass as generationConfig- custom_llm_provider="gemini"+ generationConfig=test_data["generationConfig"],+ custom_llm_provider="gemini",)- except Exception as e:- # Should not fail due to parameter handling issues- error_msg = str(e).lower()- if "generationconfig" in error_msg or "config" in error_msg or "parameter" in error_msg:- pytest.fail(f"Parameter handling failed: {e}")- # Other errors (like API key missing) are expected- print(f"✅ Parameter handling worked (API error expected): {type(e).__name__}")-- print("✅ generationConfig to config mapping test passed")++ mock_generate_content_handler.assert_called_once()+ generate_content_config_dict = mock_generate_content_handler.call_args.kwargs[+ "generate_content_config_dict"+ ]+ assert generate_content_config_dict["temperature"] == 0+ assert generate_content_config_dict["topP"] == 1+ assert generate_content_config_dict["responseMimeType"] == "application/json"+ assert "responseJsonSchema" in generate_content_config_dict@pytest.mark.asyncio@@ -405,7 +406,7 @@ async def test_gemini_custom_api_base_proxy_integration():print(f"✅ Custom API base streaming URL test passed: {result_url_streaming}")# Test case 3: Error handling - missing API key- with pytest.raises(ValueError, match="Missing gemini_api_key"):+ with pytest.raises(ValueError, match="Missing Gemini API key"):vertex_base._check_custom_proxy(api_base=custom_api_base,custom_llm_provider="gemini",diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex.py b/tests/test_litellm/llms/vertex_ai/test_vertex.pyindex 2bd6182a331..6facd0aab8e 100644--- a/tests/test_litellm/llms/vertex_ai/test_vertex.py+++ b/tests/test_litellm/llms/vertex_ai/test_vertex.py@@ -93,6 +93,7 @@ def test_completion_pydantic_obj_2():model="gemini/gemini-2.5-flash",messages=messages,response_format=EventsList,+ api_key="test-api-key",client=client,)# print(response)@@ -285,6 +286,7 @@ def test_function_calling_with_gemini():},},],+ api_key="test-api-key",client=client,)except Exception as e:@@ -372,7 +374,10 @@ def test_multiple_function_call():with patch.object(client, "post", return_value=mock_response) as mock_post:r = litellm.completion(- messages=messages, model="gemini/gemini-1.5-flash-002", client=client+ messages=messages,+ model="gemini/gemini-1.5-flash-002",+ api_key="test-api-key",+ client=client,)assert len(r.choices) > 0@@ -478,7 +483,10 @@ def test_multiple_function_call_changed_text_pos():with patch.object(client, "post", return_value=mock_response) as mock_post:resp = litellm.completion(- messages=messages, model="gemini/gemini-1.5-flash-002", client=client+ messages=messages,+ model="gemini/gemini-1.5-flash-002",+ api_key="test-api-key",+ client=client,)assert len(resp.choices) > 0mock_post.assert_called_once()@@ -599,6 +607,7 @@ def test_function_calling_with_gemini_multiple_results():messages=messages,tools=tools,tool_choice="required",+ api_key="test-api-key",client=client,)print("Response\n", response)@@ -1182,6 +1191,7 @@ def test_logprobs():{"role": "user", "content": "What's the weather like in San Francisco?"}],logprobs=True,+ api_key="test-api-key",client=client,)print(resp)diff --git a/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py b/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.pyindex 78caf4b9778..2194cadf1b2 100644--- a/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py+++ b/tests/test_litellm/llms/vertex_ai/test_vertex_llm_base.py@@ -810,7 +810,7 @@ class TestVertexBase:if custom_llm_provider == "gemini" and api_base and gemini_api_key is None:# Test case 5: Should raise ValueError for Gemini without API key- with pytest.raises(ValueError, match="Missing gemini_api_key"):+ with pytest.raises(ValueError, match="Missing Gemini API key"):vertex_base._check_custom_proxy(api_base=api_base,custom_llm_provider=custom_llm_provider,