BerriAI/litellm · error · ValueError

GEMINI_API_BASE is not set

Error message

GEMINI_API_BASE is not set

What it means

Raised in the Gemini File Search / vector-store config's get_complete_url when no API base can be resolved: the api_base argument is None and GeminiModelInfo.get_api_base() (which reads GEMINI_API_BASE env / default config) also returns None. Because the URL cannot be constructed, the call fails before authentication.

Source

Thrown at litellm/llms/gemini/vector_stores/transformation.py:91

            api_key: Final = litellm_params.get("api_key") or get_api_key_from_env()
            if api_key:
                self._cached_api_key = api_key
                headers["x-goog-api-key"] = api_key

        return headers

    def get_complete_url(self, api_base: str | None, litellm_params: dict) -> str:
        """
        Get the complete base URL for Gemini API.

        Note: This returns the base URL WITHOUT the API key.
        The API key will be appended to specific endpoint URLs in the transform methods.
        """
        if api_base is None:
            api_base = GeminiModelInfo.get_api_base()

        if api_base is None:
            raise ValueError("GEMINI_API_BASE is not set")

        # Ensure we're using the v1beta version for File Search
        api_version: Final = "v1beta"
        return f"{api_base}/{api_version}"

    def get_error_class(self, error_message: str, status_code: int, headers: dict | httpx.Headers) -> GeminiError:
        """Return Gemini-specific error class."""
        return GeminiError(
            status_code=status_code,
            message=error_message,
            headers=headers,
        )

    def transform_search_vector_store_request(
        self,
        vector_store_id: str,
        query: str | list[str],
        vector_store_search_optional_params: VectorStoreSearchOptionalRequestParams,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set GEMINI_API_BASE (e.g. https://generativelanguage.googleapis.com) in the environment.
  2. Pass api_base explicitly on the vector-store call: litellm.vector_store_search(..., api_base='https://generativelanguage.googleapis.com').
  3. For Vertex-style deployments, provide the appropriate regional base URL your setup expects.

Example fix

# before
results = litellm.vector_store_search(vector_store_id=vs_id, query='hello', litellm_params={'model': 'gemini/gemini-2.5-flash'})

# after
import os
os.environ['GEMINI_API_BASE'] = 'https://generativelanguage.googleapis.com'
results = litellm.vector_store_search(vector_store_id=vs_id, query='hello', litellm_params={'model': 'gemini/gemini-2.5-flash', 'api_base': os.environ['GEMINI_API_BASE']})
Defensive patterns

Strategy: validation

Validate before calling

import os

def resolve_gemini_api_base(api_base=None) -> str:
    base = api_base or os.environ.get("GEMINI_API_BASE") or "https://generativelanguage.googleapis.com"
    if not base:
        raise ConfigError("GEMINI_API_BASE not configured")
    return base

Try / catch

try:
    results = litellm.vector_store_search(vector_store_id=vs, query=q, litellm_params=params)
except ValueError as e:
    if "GEMINI_API_BASE is not set" in str(e):
        raise ConfigError("Set GEMINI_API_BASE for Gemini File Search") from e
    raise

Prevention

When it happens

Trigger: Using litellm's vector_store/file-search API with the Gemini provider, passing no api_base, and having no GEMINI_API_BASE environment variable (nor the default base registered) available.

Common situations: Air-gapped or self-hosted setups where the default generativelanguage.googleapis.com base is not configured; env var set only in some services of a deployment; typo'd GEMINI_API_BASE name; Vertex-based users missing a base override.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/c97a53b410c7a382. Report an issue: GitHub.