@@ -521,6 +521,7 @@ def __init__(
521521 If not provided, a default instrumentor builder will be used.
522522 This parameter is ignored if `enable_tracing` is False.
523523 """
524+ import os
524525 from google .cloud .aiplatform import initializer
525526
526527 adk_version = get_adk_version ()
@@ -558,6 +559,7 @@ def __init__(
558559 "artifact_service_builder" : artifact_service_builder ,
559560 "memory_service_builder" : memory_service_builder ,
560561 "instrumentor_builder" : instrumentor_builder ,
562+ "express_mode_api_key" : initializer .global_config .api_key ,
561563 }
562564
563565 async def _init_session (
@@ -701,9 +703,18 @@ def set_up(self):
701703
702704 os .environ ["GOOGLE_GENAI_USE_VERTEXAI" ] = "1"
703705 project = self ._tmpl_attrs .get ("project" )
704- os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
706+ if project :
707+ os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
705708 location = self ._tmpl_attrs .get ("location" )
706- os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
709+ if location :
710+ os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
711+ express_mode_api_key = self ._tmpl_attrs .get ("express_mode_api_key" )
712+ if express_mode_api_key and not project :
713+ os .environ ["GOOGLE_API_KEY" ] = express_mode_api_key
714+ # Clear location and project env vars if express mode api key is provided.
715+ os .environ .pop ("GOOGLE_CLOUD_LOCATION" , None )
716+ os .environ .pop ("GOOGLE_CLOUD_PROJECT" , None )
717+ location = None
707718
708719 # Disable content capture in custom ADK spans unless user enabled
709720 # tracing explicitly with the old flag
@@ -750,6 +761,8 @@ def set_up(self):
750761 VertexAiSessionService ,
751762 )
752763
764+ # If the express mode api key is set, it will be read from the
765+ # environment variable when initializing the session service.
753766 self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
754767 project = project ,
755768 location = location ,
@@ -760,6 +773,8 @@ def set_up(self):
760773 VertexAiSessionService ,
761774 )
762775
776+ # If the express mode api key is set, it will be read from the
777+ # environment variable when initializing the session service.
763778 self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
764779 project = project ,
765780 location = location ,
@@ -780,6 +795,8 @@ def set_up(self):
780795 VertexAiMemoryBankService ,
781796 )
782797
798+ # If the express mode api key is set, it will be read from the
799+ # environment variable when initializing the memory service.
783800 self ._tmpl_attrs ["memory_service" ] = VertexAiMemoryBankService (
784801 project = project ,
785802 location = location ,
0 commit comments