{"record":{"id":"14f373b1e16ad929","repo":"BerriAI/litellm","slug":"gemini-api-key-is-not-set","errorCode":null,"errorMessage":"GEMINI_API_KEY is not set","messagePattern":"GEMINI_API_KEY is not set","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/image_edit/transformation.py","lineNumber":65,"sourceCode":"    ) -> dict[str, Any]:\n        return map_openai_image_params_to_gemini(\n            params=image_edit_optional_params,\n            model=model,\n            supported_params=self.get_supported_openai_params(model),\n            parse_image_config_string=True,\n        )\n\n    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        litellm_params: dict | None = None,\n        api_base: str | None = None,\n    ) -> dict:\n        final_api_key: Final[str | None] = api_key or get_secret_str(\"GEMINI_API_KEY\")\n        if not final_api_key:\n            raise ValueError(\"GEMINI_API_KEY is not set\")\n\n        headers[\"x-goog-api-key\"] = final_api_key\n        headers[\"Content-Type\"] = \"application/json\"\n        return headers\n\n    def use_multipart_form_data(self) -> bool:\n        \"\"\"Gemini uses JSON requests, not multipart/form-data.\"\"\"\n        return False\n\n    def get_complete_url(\n        self,\n        model: str,\n        api_base: str | None,\n        litellm_params: dict,\n    ) -> str:\n        base_url = api_base or get_secret_str(\"GEMINI_API_BASE\") or self.DEFAULT_BASE_URL\n        base_url = base_url.rstrip(\"/\")\n        return f\"{base_url}/models/{model}:generateContent\"","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/gemini/image_edit/transformation.py#L47-L83","documentation":"Raised by GeminiImageEditConfig.validate_environment before any request is sent for litellm.image_edit with a gemini/ image model (e.g. gemini/gemini-2.5-flash-image). Resolution is the explicit api_key argument OR the GEMINI_API_KEY secret — notably GOOGLE_API_KEY is NOT consulted here, unlike the chat/interactions Gemini handlers. The key is placed in the x-goog-api-key header.","triggerScenarios":"litellm.image_edit(model='gemini/gemini-2.5-flash-image', prompt=..., image=...) with no api_key kwarg while GEMINI_API_KEY is unset — even if GOOGLE_API_KEY IS set, because this handler ignores it.","commonSituations":"Users who set only GOOGLE_API_KEY (chat completion works, image edit fails); env vars missing in CI/containers; VPN/proxy deployments that inject keys under other names; free-tier projects using AI Studio keys.","solutions":["Set GEMINI_API_KEY in the environment (export GEMINI_API_KEY=...)","Or pass the key per call: litellm.image_edit(..., api_key=os.environ['GOOGLE_API_KEY']) — the explicit argument is checked first","If you only have GOOGLE_API_KEY, alias it: export GEMINI_API_KEY=\"$GOOGLE_API_KEY\"","Verify: python -c \"from litellm.secret_managers.main import get_secret_str; print(get_secret_str('GEMINI_API_KEY'))\""],"exampleFix":"# before\nresp = litellm.image_edit(model='gemini/gemini-2.5-flash-image', prompt='add a hat', image=img_bytes)\n# ValueError: GEMINI_API_KEY is not set\n\n# after\nresp = litellm.image_edit(\n    model='gemini/gemini-2.5-flash-image',\n    prompt='add a hat',\n    image=img_bytes,\n    api_key=os.environ['GOOGLE_API_KEY'],  # explicit key is accepted\n)","handlingStrategy":"validation","validationCode":"from litellm.secret_managers.main import get_secret_str\n\ndef gemini_image_edit_ready(api_key: str | None) -> bool:\n    # NOTE: this handler accepts ONLY api_key arg or GEMINI_API_KEY — not GOOGLE_API_KEY\n    return bool(api_key or get_secret_str('GEMINI_API_KEY'))\n\nassert gemini_image_edit_ready(None), 'Set GEMINI_API_KEY or pass api_key= to image_edit'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize on GEMINI_API_KEY for all Gemini image features — it is the only env var image_edit/image_generation check","Pass api_key explicitly when the key lives under GOOGLE_API_KEY","Fail fast at startup with a readiness probe that checks the exact env var each feature needs"],"tags":["gemini","image-edit","authentication","missing-env-var"],"backgroundTag":"missing-api-key","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}