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

The Topaz branch of litellm.image_variation resolves the key via provider_config.get_api_key (litellm_params api_key falling back to TOPAZ_API_KEY env) and requires it non-None before dispatching to base_llm_aiohttp_handler.image_variations. Topaz has no anonymous access, so an unresolved key aborts the call.

Solutions

  1. Export TOPAZ_API_KEY in the process that runs litellm.
  2. Or pass api_key explicitly in the image_variation call / Router litellm_params.
  3. Store it in the proxy's environment_config_settings / secret manager so workers inherit it.
  4. Add a startup assertion for required env vars per provider you enable.

Example fix

# before
resp = litellm.image_variation(model="topaz/upscayl", image=img, api_base="https://www.topazlabs.com/api")
# ValueError: API key is required for Topaz image variations

# after
export TOPAZ_API_KEY=...
resp = litellm.image_variation(model="topaz/upscayl", image=img, api_base="https://www.topazlabs.com/api")
Defensive patterns

Strategy: validation

Validate before calling

import os

api_key = os.getenv("TOPAZ_API_KEY")
if not api_key:
    raise RuntimeError("TOPAZ_API_KEY not set; required for Topaz image variations")
resp = litellm.image_variation(model="topaz/upscayl", image=img, api_key=api_key, api_base="https://www.topazlabs.com/api")

Try / catch

try:
    resp = litellm.image_variation(model="topaz/upscayl", image=img, api_base=base)
except ValueError as e:
    if "API key is required for Topaz image variations" in str(e):
        raise RuntimeError("set TOPAZ_API_KEY or pass api_key=") from e
    raise

Prevention

When it happens

Trigger: litellm.image_variation(model='topaz/...', image=...) without api_key while TOPAZ_API_KEY is unset; running the proxy in an environment where the Topaz secret was never added; typos in the env var name (e.g. TOPAZ_KEY) so the fallback misses.

Common situations: Docker/systemd units missing the secret; rotating a leaked key and forgetting to update the deployment; local shell has the var but the spawned worker does not.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


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

Appendix: 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 77b7c6c40c)