Merge pull request #14744 from eycjur/fixed_API_key_passing_with_gemini

Fix API key passing for Gemini token counting endpoints
This commit is contained in:
Krish Dholakia 2025-09-20 09:45:18 -07:00 committed by GitHub
commit d187343d29
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -121,7 +121,8 @@ class GoogleGenAIConfig(BaseGoogleGenAIGenerateContentConfig, VertexLLM):
default_headers = {
"Content-Type": "application/json",
}
gemini_api_key = self._get_google_ai_studio_api_key(dict(litellm_params or {}))
# Use the passed api_key first, then fall back to litellm_params and environment
gemini_api_key = api_key or self._get_google_ai_studio_api_key(dict(litellm_params or {}))
if gemini_api_key is not None:
default_headers[self.XGOOGLE_API_KEY] = gemini_api_key
if headers is not None: