BerriAI/litellm · error · ValueError

Google API key is required. Set GOOGLE_API_KEY or…

Error message

Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.

What it means

Error "Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key." thrown in BerriAI/litellm.

Solutions

  1. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key explicitly.

When it happens

Trigger: Thrown at litellm/llms/gemini/agents/transformation.py:116 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/27a2a52bdcbfe7eb. Report an issue: GitHub.

Appendix: source

Thrown at litellm/llms/gemini/agents/transformation.py:116

    ) -> dict[str, str]:
        headers = dict(headers)
        headers["Content-Type"] = "application/json"
        explicit_api_key: Final = litellm_params.get("api_key")
        # SECURITY: when the caller overrides ``api_base``, refuse to fall back
        # to the process-wide GOOGLE_API_KEY / GEMINI_API_KEY env vars. Otherwise
        # an authenticated proxy user could set ``api_base`` to an attacker-
        # controlled host and have the proxy ship its shared Gemini key in the
        # ``x-goog-api-key`` header.
        if litellm_params.get("api_base") and not explicit_api_key:
            raise ValueError(
                "When overriding api_base for Gemini agents, you must also "
                "supply an explicit api_key. Falling back to GOOGLE_API_KEY / "
                "GEMINI_API_KEY env vars with a custom api_base is refused "
                "to prevent leaking the shared provider key to arbitrary hosts."
            )
        api_key: Final = GeminiModelInfo.get_api_key(explicit_api_key)
        if not api_key:
            raise ValueError("Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.")
        headers["x-goog-api-key"] = api_key
        return headers

    def _raise_for_status(self, raw_response: httpx.Response) -> None:
        if not (200 <= raw_response.status_code < 300):
            raise GeminiError(
                message=raw_response.text,
                status_code=raw_response.status_code,
                headers=dict(raw_response.headers),
            )

    # ------------------------------------------------------------------ #
    # CREATE                                                               #
    # ------------------------------------------------------------------ #

    def transform_create_request(
        self,
        name: str,

View on GitHub (pinned to 77b7c6c40c)