BerriAI/litellm · error · ValueError

API base is required for Topaz image variations

Error message

API base is required for Topaz image variations

What it means

The Topaz branch resolves api_base via provider_config.get_api_base (explicit argument or litellm.api_base) and raises when it is None — unlike the key, no Topaz default URL is auto-applied on this path. The subsequent aiohttp handler would have nothing to POST the image to, so litellm aborts early.

Solutions

  1. Pass api_base explicitly, e.g. api_base='https://www.topazlabs.com/api' (or your Topaz endpoint) in the call.
  2. Or set litellm.api_base once if all Topaz traffic shares one endpoint.
  3. Add api_base to the topaz model's litellm_params in Router/proxy config.
  4. Wrap a small client function that always injects provider, key, and base so call sites cannot omit them.

Example fix

# before
resp = litellm.image_variation(model="topaz/upscayl", image=img, api_key=key)
# ValueError: API base is required for Topaz image variations

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

Strategy: validation

Validate before calling

TOPAZ_API_BASE = "https://www.topazlabs.com/api"

def topaz_variation(model, image, api_key):
    return litellm.image_variation(
        model=model, image=image, api_key=api_key, api_base=TOPAZ_API_BASE
    )  # api_base never omitted

Try / catch

try:
    resp = litellm.image_variation(model="topaz/upscayl", image=img, api_key=key)
except ValueError as e:
    if "API base is required for Topaz image variations" in str(e):
        resp = litellm.image_variation(model="topaz/upscayl", image=img, api_key=key, api_base="https://www.topazlabs.com/api")
    else:
        raise

Prevention

When it happens

Trigger: Calling image_variation with a topaz model and api_key set but no api_base and no litellm.api_base; assuming litellm knows Topaz's URL automatically; copying an OpenAI-variation call and only changing the model.

Common situations: First-time Topaz integrations following docs that show the key but not the base; proxy config with topaz model entries missing the api_base litellm_param.

Related errors


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

Appendix: source

Thrown at litellm/images/main.py:680

            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
    if response is None:
        raise ValueError(

View on GitHub (pinned to 77b7c6c40c)