chroma-core/chroma · error · ValueError

Vertex AI and API key are mutually exclusive in the client…

Error message

Vertex AI and API key are mutually exclusive in the client initializer.

What it means

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.

Solutions

  1. Unset the key in the environment that uses Vertex: unset GEMINI_API_KEY (or remove it from .env / compose env)
  2. Or point api_key_env_var at a variable that is deliberately unset in that deployment
  3. Or drop vertexai (leave it None/False) to keep plain API-key auth
  4. If you genuinely need both auth modes, run them in separate processes/environments with distinct env var sets

Example fix

# before
# export GEMINI_API_KEY=...  (still set in the shell)
ef = GoogleGeminiEmbeddingFunction(
    vertexai=True, project="my-gcp-project", location="us-central1"
)  # ValueError: mutually exclusive

# after
# unset GEMINI_API_KEY
ef = GoogleGeminiEmbeddingFunction(
    vertexai=True, project="my-gcp-project", location="us-central1"
)
Defensive patterns

Strategy: validation

Validate before calling

import os

API_KEY_ENV = "GEMINI_API_KEY"
use_vertex = True

if use_vertex and os.getenv(API_KEY_ENV):
    raise SystemExit(
        f"{API_KEY_ENV} must not be set when vertexai=True; unset it or use API-key auth"
    )

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16). Data as JSON: /api/errors/58cc830589653178. Report an issue: GitHub.

Appendix: source

Thrown at chromadb/utils/embedding_functions/google_embedding_function.py:59

            location (str, optional): The Google Cloud location/region (required for Vertex AI).
        """
        try:
            import google.genai as genai
        except ImportError:
            raise ValueError(
                "The google-genai python package is not installed. Please install it with `pip install google-genai`"
            )

        self.model_name = model_name
        self.task_type = task_type
        self.dimension = dimension
        self.api_key_env_var = api_key_env_var
        self.vertexai = vertexai
        self.project = project
        self.location = location
        self.api_key = os.getenv(self.api_key_env_var) if self.api_key_env_var else None
        if self.api_key and self.vertexai:
            raise ValueError(
                "Vertex AI and API key are mutually exclusive in the client initializer."
            )
        if not self.api_key and not self.vertexai:
            raise ValueError(
                f"The {self.api_key_env_var} environment variable must be set if vertexai is not enabled."
            )

        from google.genai import types

        self.client = genai.Client(
            api_key=self.api_key,
            vertexai=vertexai,
            project=project,
            location=location,
            http_options=types.HttpOptions(
                headers={"x-goog-api-client": f"chroma/{__version__}"}
            ),
        )

View on GitHub (pinned to aecdd12c8a)