{"record":{"id":"3bd86563583e1d24","repo":"BerriAI/litellm","slug":"when-overriding-api-base-for-gemini-agents-you-mu","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/agents/transformation.py","lineNumber":108,"sourceCode":"        litellm_params: dict[str, Any],\n    ) -> str:\n        return f\"{self._base_url(api_base)}/agents\"\n\n    def validate_environment(\n        self,\n        headers: dict[str, str],\n        litellm_params: dict[str, Any],\n    ) -> 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            )","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/agents/transformation.py#L90-L126","documentation":"Error \"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.\" thrown in BerriAI/litellm.","triggerScenarios":"Thrown at litellm/llms/gemini/agents/transformation.py:108 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["When overriding api_base for Gemini agents, also pass an explicit api_key; env fallback is refused to avoid leaking the shared key to arbitrary hosts."],"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"}