{"record":{"id":"0f43a269b38414d3","repo":"BerriAI/litellm","slug":"gemini-api-key-or-google-api-key-is-required-for-v","errorCode":null,"errorMessage":"GEMINI_API_KEY or GOOGLE_API_KEY is required for Veo video generation. Set it via environment variable or pass it as api_key parameter.","messagePattern":"GEMINI_API_KEY or GOOGLE_API_KEY is required for Veo video generation\\. Set it via environment variable or pass it as api_key parameter\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/llms/gemini/videos/transformation.py","lineNumber":205,"sourceCode":"    def validate_environment(\n        self,\n        headers: dict,\n        model: str,\n        api_key: str | None = None,\n        litellm_params: GenericLiteLLMParams | None = None,\n    ) -> dict:\n        \"\"\"\n        Validate environment and add Gemini API key to headers.\n        Gemini uses x-goog-api-key header for authentication.\n        \"\"\"\n        # Use api_key from litellm_params if available, otherwise fall back to other sources\n        if litellm_params and litellm_params.api_key:\n            api_key = api_key or litellm_params.api_key\n\n        api_key = api_key or litellm.api_key or get_secret_str(\"GOOGLE_API_KEY\") or get_secret_str(\"GEMINI_API_KEY\")\n\n        if not api_key:\n            raise ValueError(\n                \"GEMINI_API_KEY or GOOGLE_API_KEY is required for Veo video generation. \"\n                \"Set it via environment variable or pass it as api_key parameter.\"\n            )\n\n        headers.update(\n            {\n                \"x-goog-api-key\": api_key,\n                \"Content-Type\": \"application/json\",\n            }\n        )\n        return headers\n\n    def get_complete_url(\n        self,\n        model: str,\n        api_base: str | None,\n        litellm_params: dict,\n    ) -> str:","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/gemini/videos/transformation.py#L187-L223","documentation":"Raised in the Veo video-generation config's header helper. It resolves the key from: explicit api_key arg, then litellm_params.api_key, then litellm.api_key, then GOOGLE_API_KEY, then GEMINI_API_KEY secrets. If every source is empty it raises ValueError, because the x-goog-api-key header (Veo's auth mechanism) cannot be set.","triggerScenarios":"Calling litellm's video generation (model veo-3 / veo-2 via Gemini) without an api_key parameter, without litellm.api_key set, and without GOOGLE_API_KEY/GEMINI_API_KEY environment variables.","commonSituations":"Video generation endpoint deployed without the Gemini secret mounted; using Vertex-style service-account auth where no API key exists (this Gemini transport requires an API key, not a service account); empty-string env vars after a failed secret injection.","solutions":["Pass api_key='AIza...' directly to the Veo generation call.","Set GOOGLE_API_KEY or GEMINI_API_KEY in the environment.","If you only have Vertex AI service-account credentials, route via the Vertex AI provider path instead of the Gemini API-key path."],"exampleFix":"# before\nvideo = litellm.generate_video(model='veo-3', prompt='a cat surfing')\n\n# after\nimport os\nvideo = litellm.generate_video(\n    model='veo-3',\n    prompt='a cat surfing',\n    api_key=os.environ['GOOGLE_API_KEY'],\n)\n","handlingStrategy":"validation","validationCode":"import os\nfrom litellm import get_secret_str\n\ndef resolve_veo_key(api_key=None, litellm_params=None) -> str:\n    key = (\n        api_key\n        or (litellm_params or {}).api_key\n        or litellm.api_key\n        or get_secret_str(\"GOOGLE_API_KEY\")\n        or get_secret_str(\"GEMINI_API_KEY\")\n    )\n    if not key:\n        raise ConfigError(\"Veo requires GOOGLE_API_KEY/GEMINI_API_KEY or explicit api_key\")\n    return key","typeGuard":null,"tryCatchPattern":"try:\n    video = litellm.generate_video(model=\"veo-3\", prompt=p, api_key=key)\nexcept ValueError as e:\n    if \"required for Veo video generation\" in str(e):\n        raise ConfigError(\"Veo call missing API key\") from e\n    raise","preventionTips":["Mount GOOGLE_API_KEY/GEMINI_API_KEY as secrets in every service calling Veo.","Note this Gemini transport needs an API key, not a Vertex service account.","Validate key presence before queueing long video jobs."],"tags":["auth","gemini","veo","video-generation","api-key","config"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}