Skip to content

Commit 4ffe8fb

Browse files
yeesiancopybara-github
authored andcommitted
fix: api client initialization logic to be mutually exclusive between ExpressMode and GCP projects
Otherwise we get errors of the form: `Project/location and API key are mutually exclusive in the client initializer` (https://github.com/googleapis/python-genai/blob/1ccad7b70ae1068cb5f3e866ad7ca4d42aa55e1e/google/genai/_api_client.py#L590-L591). Co-authored-by: Yeesian Ng <ysian@google.com> PiperOrigin-RevId: 890588927
1 parent cdb3ff4 commit 4ffe8fb

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/google/adk/memory/vertex_ai_memory_bank_service.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,9 @@ def _get_api_client(self) -> vertexai.AsyncClient:
397397
"""
398398
import vertexai
399399

400-
return vertexai.Client(
401-
project=self._project,
402-
location=self._location,
403-
api_key=self._express_mode_api_key,
404-
).aio
400+
if self._express_mode_api_key:
401+
return vertexai.Client(api_key=self._express_mode_api_key).aio
402+
return vertexai.Client(project=self._project, location=self._location).aio
405403

406404

407405
def _should_filter_out_event(content: types.Content) -> bool:

src/google/adk/sessions/vertex_ai_session_service.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,15 @@ def _get_api_client(self) -> vertexai.AsyncClient:
376376
"""
377377
import vertexai
378378

379+
if self._express_mode_api_key:
380+
return vertexai.Client(
381+
http_options=self._api_client_http_options_override(),
382+
api_key=self._express_mode_api_key,
383+
).aio
379384
return vertexai.Client(
380385
project=self._project,
381386
location=self._location,
382387
http_options=self._api_client_http_options_override(),
383-
api_key=self._express_mode_api_key,
384388
).aio
385389

386390

0 commit comments

Comments
 (0)