BerriAI/litellm · error · ValueError

API key is required for Topaz image variations

Error message

API key is required for Topaz image variations

What it means

Topaz Labs image variations authenticate with an API key; if provider_config.get_api_key() returns None at litellm/images/main.py:678, litellm raises ValueError because the Topaz API rejects anonymous requests.

Source

Thrown at litellm/images/main.py:678

            raise ValueError("API key is required for OpenAI image variations")
        if api_base is None:
            raise ValueError("API base is required for OpenAI image variations")

        response = openai_image_variations.image_variations(
            model_response=model_response,
            api_key=api_key,
            api_base=api_base,
            model=model,
            image=image,
            timeout=litellm_params.get("timeout", None),
            custom_llm_provider=custom_llm_provider,
            logging_obj=litellm_logging_obj,
            optional_params={},
            litellm_params=litellm_params,
        )
    elif image_variation_provider == LITELLM_IMAGE_VARIATION_PROVIDERS.TOPAZ:
        if api_key is None:
            raise ValueError("API key is required for Topaz image variations")
        if api_base is None:
            raise ValueError("API base is required for Topaz image variations")

        response = base_llm_aiohttp_handler.image_variations(
            model_response=model_response,
            api_key=api_key,
            api_base=api_base,
            model=model,
            image=image,
            timeout=litellm_params.get("timeout", None) or DEFAULT_REQUEST_TIMEOUT,
            custom_llm_provider=custom_llm_provider,
            logging_obj=litellm_logging_obj,
            optional_params={},
            litellm_params=litellm_params,
            client=client,
        )

    # return the response

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Export TOPAZ_API_KEY in the process environment
  2. Or pass api_key explicitly to litellm.image_variations(...)
  3. Verify the key at topazlabs.com and that it has image API access

Example fix

# before
litellm.image_variations(model="topaz/topaz-image-alter-v1", image=img)

# after
litellm.image_variations(model="topaz/topaz-image-alter-v1", image=img, api_key=os.environ["TOPAZ_API_KEY"])
Defensive patterns

Strategy: validation

Validate before calling

import os

def has_topaz_key(explicit: str | None = None) -> bool:
    return bool(explicit or os.getenv("TOPAZ_API_KEY"))

Try / catch

try:
    r = litellm.image_variations(model="topaz/topaz-image-alter-v1", image=img)
except ValueError as e:
    if "API key is required for Topaz" in str(e):
        raise RuntimeError("set TOPAZ_API_KEY") from e
    raise

Prevention

When it happens

Trigger: Calling litellm.image_variations(model='topaz/...', image=...) without TOPAZ_API_KEY in the environment, without an api_key argument, and without litellm.api_key.

Common situations: New Topaz integration where the developer only configured OpenAI env vars; CI missing the TOPAZ_API_KEY secret.

Related errors


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