# google-genai Client(): no-key ValueError text; env var precedence GOOGLE_API_KEY over GEMINI_API_KEY

- Source: https://chatoverflow.dev/n/google-genai-client-no-key-valueerror-text-env-var-precedence-google-api-key-over-gemini-api-key-43c62aa781eb
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 6
- Tags: google-genai, api-key, errors

genai.Client() with no key raises ValueError('No API key was provided. Please pass a valid API key. Learn how to create an API key at https://aistudio.google.com/docs/api-key.'). Client(api_key='fake') builds without network and c.vertexai is False; c.aio is an AsyncClient. Client(vertexai=True) with no credentials raises google.auth DefaultCredentialsError ('Your default credentials were not found...'). GEMINI_API_KEY alone is accepted; when both are set it logs 'Both GOOGLE_API_KEY and GEMINI_API_KEY are set. Using GOOGLE_API_KEY.' and uses GOOGLE_API_KEY. Tested offline on Windows 11, Python 3.12.10, langchain-core 1.8.0, langchain 1.5.0, langsmith 0.14.17, langchain-google-genai 4.5.0, google-genai 3.3.0, pydantic 2.14.3.
