BerriAI/litellm · error · ValueError

GEMINI_API_KEY or GOOGLE_API_KEY is required for Veo video g

Error message

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.

What it means

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.

Source

Thrown at litellm/llms/gemini/videos/transformation.py:205

    def validate_environment(
        self,
        headers: dict,
        model: str,
        api_key: str | None = None,
        litellm_params: GenericLiteLLMParams | None = None,
    ) -> dict:
        """
        Validate environment and add Gemini API key to headers.
        Gemini uses x-goog-api-key header for authentication.
        """
        # Use api_key from litellm_params if available, otherwise fall back to other sources
        if litellm_params and litellm_params.api_key:
            api_key = api_key or litellm_params.api_key

        api_key = api_key or litellm.api_key or get_secret_str("GOOGLE_API_KEY") or get_secret_str("GEMINI_API_KEY")

        if not api_key:
            raise ValueError(
                "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."
            )

        headers.update(
            {
                "x-goog-api-key": api_key,
                "Content-Type": "application/json",
            }
        )
        return headers

    def get_complete_url(
        self,
        model: str,
        api_base: str | None,
        litellm_params: dict,
    ) -> str:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Pass api_key='AIza...' directly to the Veo generation call.
  2. Set GOOGLE_API_KEY or GEMINI_API_KEY in the environment.
  3. If you only have Vertex AI service-account credentials, route via the Vertex AI provider path instead of the Gemini API-key path.

Example fix

# before
video = litellm.generate_video(model='veo-3', prompt='a cat surfing')

# after
import os
video = litellm.generate_video(
    model='veo-3',
    prompt='a cat surfing',
    api_key=os.environ['GOOGLE_API_KEY'],
)
Defensive patterns

Strategy: validation

Validate before calling

import os
from litellm import get_secret_str

def resolve_veo_key(api_key=None, litellm_params=None) -> str:
    key = (
        api_key
        or (litellm_params or {}).api_key
        or litellm.api_key
        or get_secret_str("GOOGLE_API_KEY")
        or get_secret_str("GEMINI_API_KEY")
    )
    if not key:
        raise ConfigError("Veo requires GOOGLE_API_KEY/GEMINI_API_KEY or explicit api_key")
    return key

Try / catch

try:
    video = litellm.generate_video(model="veo-3", prompt=p, api_key=key)
except ValueError as e:
    if "required for Veo video generation" in str(e):
        raise ConfigError("Veo call missing API key") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/0f43a269b38414d3. Report an issue: GitHub.