{"record":{"id":"27a2a52bdcbfe7eb","repo":"BerriAI/litellm","slug":"google-api-key-is-required-set-google-api-key-or","errorCode":null,"errorMessage":"Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.","messagePattern":"Google API key is required\\. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/agents/transformation.py","lineNumber":116,"sourceCode":"    ) -> dict[str, str]:\n        headers = dict(headers)\n        headers[\"Content-Type\"] = \"application/json\"\n        explicit_api_key: Final = litellm_params.get(\"api_key\")\n        # SECURITY: when the caller overrides ``api_base``, refuse to fall back\n        # to the process-wide GOOGLE_API_KEY / GEMINI_API_KEY env vars. Otherwise\n        # an authenticated proxy user could set ``api_base`` to an attacker-\n        # controlled host and have the proxy ship its shared Gemini key in the\n        # ``x-goog-api-key`` header.\n        if litellm_params.get(\"api_base\") and not explicit_api_key:\n            raise ValueError(\n                \"When overriding api_base for Gemini agents, you must also \"\n                \"supply an explicit api_key. Falling back to GOOGLE_API_KEY / \"\n                \"GEMINI_API_KEY env vars with a custom api_base is refused \"\n                \"to prevent leaking the shared provider key to arbitrary hosts.\"\n            )\n        api_key: Final = GeminiModelInfo.get_api_key(explicit_api_key)\n        if not api_key:\n            raise ValueError(\"Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.\")\n        headers[\"x-goog-api-key\"] = api_key\n        return headers\n\n    def _raise_for_status(self, raw_response: httpx.Response) -> None:\n        if not (200 <= raw_response.status_code < 300):\n            raise GeminiError(\n                message=raw_response.text,\n                status_code=raw_response.status_code,\n                headers=dict(raw_response.headers),\n            )\n\n    # ------------------------------------------------------------------ #\n    # CREATE                                                               #\n    # ------------------------------------------------------------------ #\n\n    def transform_create_request(\n        self,\n        name: str,","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/agents/transformation.py#L98-L134","documentation":"Error \"Google API key is required. Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key.\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/gemini/agents/transformation.py:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set GOOGLE_API_KEY or GEMINI_API_KEY, or pass api_key explicitly."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}