Hi,
I'm reporting a confusing configuration behavior with the Vertex AI/GenAI Python SDK that I encountered while building a multi-agent pipeline with Google ADK.
Issue summary
I explicitly instantiated genai.Client in my code (and sub-agents/tools), passing vertexai=True, project=..., and location=... as keyword arguments. However, for a while, the only way to get the SDK working was to set the environment variables as:
GOOGLE_CLOUD_PROJECT=...
GOOGLE_CLOUD_LOCATION=...
If I set environment variables with non-official names (like GOOGLE_PROJECT_ID/GOOGLE_LOCATION), or tried to only pass the values inside the client init (e.g. genai.Client(vertexai=True, project="my-project", location="us-central1")), I would get errors such as:
ValueError: Missing key inputs argument! To use the Google Cloud API, provide (vertexai, project & location) arguments.
- Or, if an API key env was set:
401 UNAUTHENTICATED. API keys are not supported by this API. Expected OAuth2 access token...
What's confusing is:
- After I renamed my env vars to the "GOOGLE_CLOUD_PROJECT" / "GOOGLE_CLOUD_LOCATION" format, it worked instantly (no other code changed).
- Now, after the environment "stabilized", even custom-named env vars and direct keyword arguments seem to work.
- There was a period where only setting the official env variable names would make the agent pipeline and all sub-agents function.
- Restarting the poetry shell, venv, even full system reboot previously had no effect—only the variable name seemed to solve it.
Expected behavior
Passing the project and location kwargs directly to the genai.Client constructor should always override/fallback the environment variable logic, so that bad/missing env var names do not block correct config.
Also highly nested ADK agent pipelines and local tests should behave the same if all submodules and agents use proper explicit args.
Actual behavior
- For some time, the client init ignored explicit kwarg values unless the env variable name matched
GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION.
- After changing var names and (maybe) fully resetting the environment, it now works even with explicit args or different env names.
- I'm now unable to consistently reproduce the issue, but the experience was very confusing and cost a lot of debug time.
- It seems possible that there is a "hidden cache" or SDK import-time capture of env/config, or that some deep agent/sub-agent process inits the client before env is loaded.
Minimal reproducible code / scenario
import os
from google import genai
# This did not work before:
os.environ["GOOGLE_PROJECT_ID"] = "my-project"
os.environ["GOOGLE_LOCATION"] = "us-central1"
client = genai.Client(vertexai=True, project=GOOGLE_PROJECT_ID, location=GOOGLE_LOCATION)
# or
client = genai.Client(vertexai=True, project="my-project", location="us-central1")
Error: ValueError unless GOOGLE_CLOUD_PROJECT/location set
Later, after changing only the env names to:
os.environ["GOOGLE_CLOUD_PROJECT"] = "my-project"
os.environ["GOOGLE_CLOUD_LOCATION"] = "us-central1"
...it worked, no other changes required.
Question
- Is this expected fallback behavior?
- Are there known issues/edge cases where deep sub-agents/tools/modules init
genai.Client before env is loaded, or only official env names are recognized?
- How can I avoid this confusion and ensure config always works as intended?
- Is there a bug in the ADK or SDK for this?
If I missed something obvious, please let me know!
Thank you for your time and help.
Environment
- Python: 3.11.8 (managed via poetry 2.1.2)
- OS: macOS Sequoia 15.6.1 (Apple M4 Pro, 24GB)
- google-genai: 1.33.0
- google-adk: 1.13.0
If this is just a usage error, I apologize and would appreciate any guidance. Otherwise, I hope this scenario helps improve documentation or config logic for other users. Thanks!
Hi,
I'm reporting a confusing configuration behavior with the Vertex AI/GenAI Python SDK that I encountered while building a multi-agent pipeline with Google ADK.
Issue summary
I explicitly instantiated
genai.Clientin my code (and sub-agents/tools), passingvertexai=True,project=..., andlocation=...as keyword arguments. However, for a while, the only way to get the SDK working was to set the environment variables as:If I set environment variables with non-official names (like
GOOGLE_PROJECT_ID/GOOGLE_LOCATION), or tried to only pass the values inside the client init (e.g.genai.Client(vertexai=True, project="my-project", location="us-central1")), I would get errors such as:ValueError: Missing key inputs argument! To use the Google Cloud API, provide (vertexai, project & location) arguments.401 UNAUTHENTICATED. API keys are not supported by this API. Expected OAuth2 access token...What's confusing is:
Expected behavior
Passing the
projectandlocationkwargs directly to thegenai.Clientconstructor should always override/fallback the environment variable logic, so that bad/missing env var names do not block correct config.Also highly nested ADK agent pipelines and local tests should behave the same if all submodules and agents use proper explicit args.
Actual behavior
GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION.Minimal reproducible code / scenario
Error: ValueError unless GOOGLE_CLOUD_PROJECT/location set
Later, after changing only the env names to:
...it worked, no other changes required.
Question
genai.Clientbefore env is loaded, or only official env names are recognized?If I missed something obvious, please let me know!
Thank you for your time and help.
Environment
If this is just a usage error, I apologize and would appreciate any guidance. Otherwise, I hope this scenario helps improve documentation or config logic for other users. Thanks!