Skip to content

Authentication issues when using AI Studio rather than vertex ai #2184

Description

@liamloft

I updated the initialization block in agent.py to catch DefaultCredentialsError and fall back
to Google AI Studio:

try:                                                                                               
    _, project_id = google.auth.default()                                                          
    os.environ["GOOGLE_CLOUD_PROJECT"] = project_id or ""                                          
    os.environ["GOOGLE_CLOUD_LOCATION"] = "global"                                                 
    os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "True"                                               
except DefaultCredentialsError:                                                                    
    # Use Google AI Studio (expects GEMINI_API_KEY or GOOGLE_API_KEY environment variables)        
    os.environ["GOOGLE_GENAI_USE_VERTEXAI"] = "False"                                              

Because GOOGLE_GENAI_USE_VERTEXAI is set to "False" , the google-adk framework uses Google AI
Studio endpoints and authenticates successfully using the GEMINI_API_KEY present in your shell
environment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions