Skip to content

Commit 6a7db83

Browse files
committed
Don't pass api_key when explicitly using vertex AI
1 parent 31dbd98 commit 6a7db83

File tree

1 file changed

+5
-1
lines changed
  • pydantic_ai_slim/pydantic_ai/providers

1 file changed

+5
-1
lines changed

pydantic_ai_slim/pydantic_ai/providers/google.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def __init__(
103103
# NOTE: We are keeping GEMINI_API_KEY for backwards compatibility.
104104
api_key = api_key or os.getenv('GOOGLE_API_KEY') or os.getenv('GEMINI_API_KEY')
105105

106+
vertex_ai_args_used = bool(location or project or credentials)
106107
if vertexai is None:
107-
vertexai = bool(location or project or credentials)
108+
vertexai = vertex_ai_args_used
108109

109110
http_client = http_client or cached_async_http_client(
110111
provider='google-vertex' if vertexai else 'google-gla'
@@ -124,6 +125,9 @@ def __init__(
124125
)
125126
self._client = Client(vertexai=False, api_key=api_key, http_options=http_options)
126127
else:
128+
if vertex_ai_args_used:
129+
api_key = None
130+
127131
if api_key is None:
128132
project = project or os.getenv('GOOGLE_CLOUD_PROJECT')
129133
# From https://github.com/pydantic/pydantic-ai/pull/2031/files#r2169682149:

0 commit comments

Comments
 (0)