Python genai.Client authentication failure

This code used to work but now suddenly breaks:

    client = genai.Client(api_key=appconfig.GEMINI_API_KEY)
    model_id = "gemini-2.0-flash"
    google_search_tool = Tool(
        google_search = GoogleSearch()
    )

Error:

Error: ClientError("401 UNAUTHENTICATED. {'error': {'code': 401, 'message': 'API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication', 'status': 'UNAUTHENTICATED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'CREDENTIALS_MISSING', 'domain': 'googleapis.com', 'metadata': {'method': 'google.cloud.aiplatform.v1beta1.PredictionService.GenerateContent', 'service': 'aiplatform.googleapis.com'}}]}}")

What happens?

Hey @khteh , Just wondering which platform you’re running the code on. Did you try checking in colab or your local IDE to see if the same issue persists?

Remove GOOGLE_GENAI_USE_VERTEXAI=true solves the problem.

1 Like