BerriAI/litellm · error · ValueError

GEMINI_API_KEY is not set

Error message

GEMINI_API_KEY is not set

What it means

Error "GEMINI_API_KEY is not set" thrown in BerriAI/litellm.

Source

Thrown at litellm/llms/gemini/image_generation/transformation.py:104

        else:
            # All other Imagen models use predict endpoint
            complete_url = f"{complete_url}/models/{model}:predict"

        return complete_url

    def validate_environment(
        self,
        headers: dict,
        model: str,
        messages: list[AllMessageValues],
        optional_params: dict,
        litellm_params: dict,
        api_key: str | None = None,
        api_base: str | None = None,
    ) -> dict:
        final_api_key: Final[str | None] = api_key or get_secret_str("GEMINI_API_KEY")
        if not final_api_key:
            raise ValueError("GEMINI_API_KEY is not set")

        headers["x-goog-api-key"] = final_api_key
        headers["Content-Type"] = "application/json"
        return headers

    def transform_image_generation_request(
        self,
        model: str,
        prompt: str,
        optional_params: dict,
        litellm_params: dict,
        headers: dict,
    ) -> dict:
        """
        Transform the image generation request to Gemini format

        For Gemini 2.5 Flash Image Preview, use the standard Gemini format with response_modalities:
        {

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Set GEMINI_API_KEY in the environment.

When it happens

Trigger: Thrown at litellm/llms/gemini/image_generation/transformation.py:104 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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