BerriAI/litellm · error · ValueError

Missing Gemini API key. Set the GEMINI_API_KEY or GOOGLE_API

Error message

Missing Gemini API key. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable.

What it means

Raised while building a Gemini (AI Studio) URL with a custom api_base: the request carries no Gemini API key from param, litellm.gemini_api_key, or GEMINI_API_KEY/GOOGLE_API_KEY env — the endpoint would be unauthenticated.

Source

Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:642

        3. Vertex AI with PSC endpoints - constructs full path structure
           {api_base}/v1/projects/{project}/locations/{location}/endpoints/{model}:{endpoint}
           (only when use_psc_endpoint_format=True)

        Args:
            use_psc_endpoint_format: If True, constructs PSC endpoint URL format.
                                     If False (default), uses api_base as-is and appends :{endpoint}

        ## Returns
        - (auth_header, url) - Tuple[Optional[str], str]
        """
        if api_base:
            if custom_llm_provider == "gemini":
                # For Gemini (Google AI Studio), construct the full path like other providers
                if model is None:
                    raise ValueError("Model parameter is required for Gemini custom API base URLs")
                url = f"{api_base}/models/{model}:{endpoint}"
                if gemini_api_key is None:
                    raise ValueError(
                        "Missing Gemini API key. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable."
                    )
                if gemini_api_key is not None:
                    auth_header = {"x-goog-api-key": gemini_api_key}
            else:
                # For Vertex AI
                if use_psc_endpoint_format:
                    # User explicitly specified PSC endpoint format
                    # Construct full PSC/custom endpoint URL
                    if not (vertex_project and vertex_location and model):
                        raise ValueError(
                            "vertex_project, vertex_location, and model are required when use_psc_endpoint_format=True"
                        )
                    # Strip routing prefixes (bge/, gemma/, etc.) for endpoint URL construction
                    model_for_url: Final = get_vertex_base_model_name(model=model)
                    # Format: {api_base}/v1/projects/{project}/locations/{location}/endpoints/{model}:{endpoint}
                    version: Final = vertex_api_version or "v1"
                    url = "{}/{}/projects/{}/locations/{}/endpoints/{}:{}".format(

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Set the GEMINI_API_KEY or GOOGLE_API_KEY environment variable.
  2. Alternatively pass the key explicitly via the api_key parameter.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/llms/vertex_ai/vertex_llm_base.py:642 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/0b2369f53c416271. Report an issue: GitHub.