@@ -558,6 +558,7 @@ def __init__(
558558 "artifact_service_builder" : artifact_service_builder ,
559559 "memory_service_builder" : memory_service_builder ,
560560 "instrumentor_builder" : instrumentor_builder ,
561+ "express_mode_api_key" : initializer .global_config .api_key ,
561562 }
562563
563564 async def _init_session (
@@ -701,9 +702,18 @@ def set_up(self):
701702
702703 os .environ ["GOOGLE_GENAI_USE_VERTEXAI" ] = "1"
703704 project = self ._tmpl_attrs .get ("project" )
704- os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
705+ if project :
706+ os .environ ["GOOGLE_CLOUD_PROJECT" ] = project
705707 location = self ._tmpl_attrs .get ("location" )
706- os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
708+ if location :
709+ os .environ ["GOOGLE_CLOUD_LOCATION" ] = location
710+ express_mode_api_key = self ._tmpl_attrs .get ("express_mode_api_key" )
711+ if express_mode_api_key and not project :
712+ os .environ ["GOOGLE_API_KEY" ] = express_mode_api_key
713+ # Clear location and project env vars if express mode api key is provided.
714+ os .environ .pop ("GOOGLE_CLOUD_LOCATION" , None )
715+ os .environ .pop ("GOOGLE_CLOUD_PROJECT" , None )
716+ location = None
707717
708718 # Disable content capture in custom ADK spans unless user enabled
709719 # tracing explicitly with the old flag
@@ -750,6 +760,8 @@ def set_up(self):
750760 VertexAiSessionService ,
751761 )
752762
763+ # If the express mode api key is set, it will be read from the
764+ # environment variable when initializing the session service.
753765 self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
754766 project = project ,
755767 location = location ,
@@ -760,6 +772,8 @@ def set_up(self):
760772 VertexAiSessionService ,
761773 )
762774
775+ # If the express mode api key is set, it will be read from the
776+ # environment variable when initializing the session service.
763777 self ._tmpl_attrs ["session_service" ] = VertexAiSessionService (
764778 project = project ,
765779 location = location ,
@@ -780,6 +794,8 @@ def set_up(self):
780794 VertexAiMemoryBankService ,
781795 )
782796
797+ # If the express mode api key is set, it will be read from the
798+ # environment variable when initializing the memory service.
783799 self ._tmpl_attrs ["memory_service" ] = VertexAiMemoryBankService (
784800 project = project ,
785801 location = location ,
0 commit comments