Repository navigation
test(google): add google-genai SDK proxy integration tests #29781
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mateo-berri
merged 12 commits into
litellm_internal_staging
from
litellm_google_genai_proxy_sdk_tests
Jun 5, 2026
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7127c9d
test(google): add google-genai SDK proxy integration tests for Gemini…
Sameerlite d923542
fix(test): address Greptile review for google-genai proxy SDK tests
Sameerlite 2a5c1d8
fix(test): only load Vertex credentials when keys exist for proxy SDK…
Sameerlite d5e5f09
chore(test): scope google-genai pin to unified_google_tests only
Sameerlite b40f99b
test(google): tie litellm reload skip to proxy fixture dependency
mateo-berri f44ae32
fix(test): stop DatabaseURLSettings tests leaking DATABASE_URL into o…
mateo-berri 65b35c9
test(google): drop redundant per-test vertex credential setup
mateo-berri 4db9871
test(google): declare model_config contract on proxy SDK ABC
mateo-berri 3029d1c
test(google): narrow streaming error catch to Exception
mateo-berri 6a19edf
test(google): initialize proxy on the same loop that serves it
mateo-berri 585a2e8
test(google): drop redundant google-genai requirements pin
mateo-berri 5ac01ac
chore: revert incidental uv.lock exclude-newer bump
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
tests/unified_google_tests/base_google_genai_proxy_sdk_test.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| from abc import ABC, abstractmethod | ||
| from typing import Any, Dict, List, Optional | ||
|
|
||
| import pytest | ||
|
|
||
| try: | ||
| from google import genai | ||
| from google.genai import types | ||
|
|
||
| GOOGLE_GENAI_SDK_AVAILABLE = True | ||
| except ImportError: | ||
| GOOGLE_GENAI_SDK_AVAILABLE = False | ||
|
|
||
| MASTER_KEY = "sk-1234" | ||
| PROMPT = "Reply with only the single word: pong" | ||
|
|
||
|
|
||
| def has_vertex_credentials() -> bool: | ||
| credentials_file = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", "") | ||
| if credentials_file and os.path.isfile(credentials_file): | ||
| return True | ||
| return bool( | ||
| os.environ.get("VERTEX_AI_PRIVATE_KEY", "") | ||
| and os.environ.get("VERTEX_AI_PRIVATE_KEY_ID", "") | ||
| ) | ||
|
|
||
|
|
||
| def _make_client(proxy_url: str) -> "genai.Client": | ||
| return genai.Client( | ||
| api_key=MASTER_KEY, | ||
| http_options={"base_url": proxy_url}, | ||
| ) | ||
|
|
||
|
|
||
| def _generation_config() -> "types.GenerateContentConfig": | ||
| return types.GenerateContentConfig( | ||
| temperature=0, | ||
| top_p=0.95, | ||
| top_k=20, | ||
| ) | ||
|
|
||
|
|
||
| def _collect_stream_text(chunks: List["types.GenerateContentResponse"]) -> str: | ||
| return "".join(chunk.text for chunk in chunks if chunk.text) | ||
|
|
||
|
|
||
| class BaseGoogleGenAIProxySDKTest(ABC): | ||
| @property | ||
| @abstractmethod | ||
| def proxy_model_name(self) -> str: ... | ||
|
|
||
| @property | ||
| @abstractmethod | ||
| def model_config(self) -> Dict[str, Any]: ... | ||
|
|
||
| def _skip_reason_if_credentials_missing(self) -> Optional[str]: | ||
| model = self.model_config.get("model", "") | ||
| if model.startswith("gemini/"): | ||
| if not os.getenv("GEMINI_API_KEY"): | ||
| return "GEMINI_API_KEY not set — skipping Gemini proxy SDK tests" | ||
| return None | ||
|
|
||
| if "vertex_ai" in model: | ||
| if has_vertex_credentials(): | ||
| return None | ||
| return "Vertex AI credentials not set — skipping Vertex AI proxy SDK tests" | ||
|
|
||
| return f"Unsupported model for proxy SDK tests: {model}" | ||
|
|
||
| def _require_proxy_sdk(self) -> None: | ||
| if not GOOGLE_GENAI_SDK_AVAILABLE: | ||
| pytest.skip("google-genai SDK not installed") | ||
| reason = self._skip_reason_if_credentials_missing() | ||
| if reason: | ||
| pytest.skip(reason) | ||
|
|
||
| def test_proxy_genai_sdk_non_streaming(self, google_genai_proxy_url: str) -> None: | ||
| self._require_proxy_sdk() | ||
|
|
||
| client = _make_client(google_genai_proxy_url) | ||
| response = client.models.generate_content( | ||
| model=self.proxy_model_name, | ||
| contents=types.Part.from_text(text=PROMPT), | ||
| config=_generation_config(), | ||
| ) | ||
|
|
||
| assert response is not None | ||
| assert response.text is not None | ||
| assert len(response.text.strip()) > 0 | ||
|
|
||
| def test_proxy_genai_sdk_streaming_completes_without_errors( | ||
| self, google_genai_proxy_url: str | ||
| ) -> None: | ||
| self._require_proxy_sdk() | ||
|
|
||
| client = _make_client(google_genai_proxy_url) | ||
| stream = client.models.generate_content_stream( | ||
| model=self.proxy_model_name, | ||
| contents=types.Part.from_text(text=PROMPT), | ||
| config=_generation_config(), | ||
| ) | ||
|
|
||
| chunks: List[types.GenerateContentResponse] = [] | ||
| stream_error: Optional[Exception] = None | ||
|
|
||
| try: | ||
| for chunk in stream: | ||
| chunks.append(chunk) | ||
| except Exception as exc: | ||
| stream_error = exc | ||
|
|
||
| assert ( | ||
| stream_error is None | ||
| ), f"Streaming raised {type(stream_error).__name__}: {stream_error}" | ||
| assert len(chunks) > 0, "Expected at least one streaming chunk" | ||
| assert _collect_stream_text(chunks).strip(), "Expected non-empty streamed text" | ||
|
|
||
| def test_proxy_genai_sdk_streaming_dict_style( | ||
| self, google_genai_proxy_url: str | ||
| ) -> None: | ||
| self._require_proxy_sdk() | ||
|
|
||
| client = _make_client(google_genai_proxy_url) | ||
| stream = client.models.generate_content_stream( | ||
| model=self.proxy_model_name, | ||
| contents={"text": PROMPT}, | ||
| config={ | ||
| "temperature": 0, | ||
| "top_p": 0.95, | ||
| "top_k": 20, | ||
| }, | ||
| ) | ||
|
|
||
| chunks = list(stream) | ||
| assert len(chunks) > 0 | ||
| assert _collect_stream_text(chunks).strip() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
tests/unified_google_tests/google_genai_proxy_test_config.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| model_list: | ||
| - model_name: gemini-2.5-flash-lite | ||
| litellm_params: | ||
| model: gemini/gemini-2.5-flash-lite | ||
| api_key: os.environ/GEMINI_API_KEY | ||
|
|
||
| - model_name: vertex-gemini-2.5-flash-lite | ||
| litellm_params: | ||
| model: vertex_ai/gemini-2.5-flash-lite | ||
|
|
||
| general_settings: | ||
| master_key: sk-1234 | ||
| store_model_in_db: false | ||
|
|
||
| litellm_settings: | ||
| drop_params: true |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.