{"record":{"id":"58cc830589653178","repo":"chroma-core/chroma","slug":"vertex-ai-and-api-key-are-mutually-exclusive-in-th","errorCode":null,"errorMessage":"Vertex AI and API key are mutually exclusive in the client initializer.","messagePattern":"Vertex AI and API key are mutually exclusive in the client initializer\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"chromadb/utils/embedding_functions/google_embedding_function.py","lineNumber":59,"sourceCode":"            location (str, optional): The Google Cloud location/region (required for Vertex AI).\n        \"\"\"\n        try:\n            import google.genai as genai\n        except ImportError:\n            raise ValueError(\n                \"The google-genai python package is not installed. Please install it with `pip install google-genai`\"\n            )\n\n        self.model_name = model_name\n        self.task_type = task_type\n        self.dimension = dimension\n        self.api_key_env_var = api_key_env_var\n        self.vertexai = vertexai\n        self.project = project\n        self.location = location\n        self.api_key = os.getenv(self.api_key_env_var) if self.api_key_env_var else None\n        if self.api_key and self.vertexai:\n            raise ValueError(\n                \"Vertex AI and API key are mutually exclusive in the client initializer.\"\n            )\n        if not self.api_key and not self.vertexai:\n            raise ValueError(\n                f\"The {self.api_key_env_var} environment variable must be set if vertexai is not enabled.\"\n            )\n\n        from google.genai import types\n\n        self.client = genai.Client(\n            api_key=self.api_key,\n            vertexai=vertexai,\n            project=project,\n            location=location,\n            http_options=types.HttpOptions(\n                headers={\"x-goog-api-client\": f\"chroma/{__version__}\"}\n            ),\n        )","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/chromadb/utils/embedding_functions/google_embedding_function.py#L41-L77","documentation":"Raised in GoogleGeminiEmbeddingFunction.__init__ when the environment variable named by api_key_env_var (default GEMINI_API_KEY) is set AND vertexai is truthy. The underlying genai.Client authenticates either with an API key or with Vertex AI Application Default Credentials, never both; Chroma fails fast instead of letting the SDK silently pick one auth path.","triggerScenarios":"Constructing GoogleGeminiEmbeddingFunction(vertexai=True, project=..., location=...) while GEMINI_API_KEY (or whatever var api_key_env_var points to) is present in the environment; or passing an api_key_env_var that names a variable that happens to be set in the Vertex deployment.","commonSituations":"Migrating an app from the Gemini API to Vertex AI without unsetting the old key; a globally loaded .env or shell profile exporting GEMINI_API_KEY into a production Vertex container; CI secrets injecting the key into a job that also sets vertexai=True.","solutions":["Unset the key in the environment that uses Vertex: unset GEMINI_API_KEY (or remove it from .env / compose env)","Or point api_key_env_var at a variable that is deliberately unset in that deployment","Or drop vertexai (leave it None/False) to keep plain API-key auth","If you genuinely need both auth modes, run them in separate processes/environments with distinct env var sets"],"exampleFix":"# before\n# export GEMINI_API_KEY=...  (still set in the shell)\nef = GoogleGeminiEmbeddingFunction(\n    vertexai=True, project=\"my-gcp-project\", location=\"us-central1\"\n)  # ValueError: mutually exclusive\n\n# after\n# unset GEMINI_API_KEY\nef = GoogleGeminiEmbeddingFunction(\n    vertexai=True, project=\"my-gcp-project\", location=\"us-central1\"\n)","handlingStrategy":"validation","validationCode":"import os\n\nAPI_KEY_ENV = \"GEMINI_API_KEY\"\nuse_vertex = True\n\nif use_vertex and os.getenv(API_KEY_ENV):\n    raise SystemExit(\n        f\"{API_KEY_ENV} must not be set when vertexai=True; unset it or use API-key auth\"\n    )","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep Gemini API-key and Vertex deployments in separate environments with disjoint env var sets","Audit .env files and CI secret injections for GEMINI_API_KEY before enabling vertexai=True","Add a preflight assertion combining os.getenv(api_key_env_var) and the vertexai flag"],"tags":["vertexai","gemini","api-key","mutually-exclusive","chroma","auth"],"backgroundTag":"mutually-exclusive-config-options","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}