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
fix vertex only refresh auth when required
Ishaan Jaff7bddbdd56e38
diff --git a/litellm/llms/vertex_ai_and_google_ai_studio/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai_and_google_ai_studio/gemini/vertex_and_google_ai_studio_gemini.pyindex 000512d9451..4fe19452609 100644--- a/litellm/llms/vertex_ai_and_google_ai_studio/gemini/vertex_and_google_ai_studio_gemini.py+++ b/litellm/llms/vertex_ai_and_google_ai_studio/gemini/vertex_and_google_ai_studio_gemini.py@@ -9,7 +9,17 @@ import typesimport uuidfrom enum import Enumfrom functools import partial-from typing import Any, Callable, Dict, List, Literal, Optional, Tuple, Union+from typing import (+ TYPE_CHECKING,+ Any,+ Callable,+ Dict,+ List,+ Literal,+ Optional,+ Tuple,+ Union,+)import httpx # type: ignoreimport requests # type: ignore@@ -68,6 +78,11 @@ from .transformation import (sync_transform_request_body,)+if TYPE_CHECKING:+ from google.auth.credentials import Credentials as GoogleCredentialsObject+else:+ GoogleCredentialsObject = Any+class VertexAIConfig:"""@@ -811,7 +826,7 @@ class VertexLLM(BaseLLM):super().__init__()self.access_token: Optional[str] = Noneself.refresh_token: Optional[str] = None- self._credentials: Optional[Any] = None+ self._credentials: Optional[GoogleCredentialsObject] = Noneself.project_id: Optional[str] = Noneself.async_handler: Optional[AsyncHTTPHandler] = None@@ -1139,7 +1154,8 @@ class VertexLLM(BaseLLM):if not self.project_id:self.project_id = project_id or cred_project_idelse:- self.refresh_auth(self._credentials)+ if self._credentials.expired or not self._credentials.token:+ self.refresh_auth(self._credentials)if not self.project_id:self.project_id = self._credentials.project_id