BerriAI/litellm · error · ValueError
Invalid image variation provider
Error message
Invalid image variation provider: {custom_llm_provider}. Supported providers are: {LITELLM_IMAGE_VARIATION_PROVIDERS} What it means
litellm.image_variation only supports providers listed in the LITELLM_IMAGE_VARIATION_PROVIDERS enum, which currently contains exactly OPENAI and TOPAZ (litellm/types/utils.py:3828-3834). The code first converts the provider to LlmProviders then to LITELLM_IMAGE_VARIATION_PROVIDERS; any other provider (stability, gemini, bedrock, ...) fails that enum conversion and raises this ValueError.
Solutions
- Use an OpenAI model (dall-e-2 is the classic variation model) via model='openai/dall-e-2' or the plain 'dall-e-2' default.
- Use Topaz: model='topaz/...' with TOPAZ credentials.
- For other providers, call their native variation/edit API directly instead of litellm.image_variation.
- Watch litellm release notes and upgrade — the enum grows over time, then re-test.
Example fix
# before resp = litellm.image_variation(model="stability/stable-diffusion-xl-1024-v1-0", image=img) # ValueError: Invalid image variation provider: stability ... # after resp = litellm.image_variation(model="dall-e-2", image=img) # openai path
Defensive patterns
Strategy: validation
Validate before calling
from litellm.types.utils import LITELLM_IMAGE_VARIATION_PROVIDERS
from litellm import LlmProviders
SUPPORTED = {p.value for p in LITELLM_IMAGE_VARIATION_PROVIDERS}
def can_variation(provider: str) -> bool:
return provider in SUPPORTED
assert can_variation("openai") and can_variation("topaz") # only these pass Type guard
from litellm.types.utils import LITELLM_IMAGE_VARIATION_PROVIDERS
def is_supported_variation_provider(provider: str) -> bool:
"""Type/narrowing guard: True only for providers with a wired image_variation branch."""
try:
LITELLM_IMAGE_VARIATION_PROVIDERS(LlmProviders(provider))
return True
except ValueError:
return False Try / catch
try:
resp = litellm.image_variation(model=model, image=img)
except ValueError as e:
if "Invalid image variation provider" in str(e):
# fall back to an OpenAI variation model or the provider's native API
resp = litellm.image_variation(model="dall-e-2", image=img)
else:
raise Prevention
- Treat image_variation support as an allowlist (openai, topaz) — never assume parity with image_generation.
- Gate variation features behind a config flag listing supported providers.
- Re-run an allowlist check after every litellm upgrade since the enum grows over time.
When it happens
Trigger: litellm.image_variation(model='stability/stable-diffusion-xl-...', image=image) or any provider-prefixed model whose provider is not openai/topaz; passing custom_llm_provider explicitly for an unsupported provider; calling image_variation on a model string that get_llm_provider maps to something other than openai or topaz.
Common situations: Assuming the image_variation endpoint has parity with image_generation providers; migrating code from image_generation (many providers) to image_variation (two); using a proxy model name that infers a non-openai provider.
Related errors
- API base is required for OpenAI image variations
- API base is required for Topaz image variations
- API key is required for OpenAI image variations
- API key is required for Topaz image variations
- API key is required for Topaz image variations. Set via…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/b48b746a70624657.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/images/main.py:638
# get logging object
litellm_logging_obj: Final = cast(LiteLLMLoggingObj, kwargs.get("litellm_logging_obj"))
# get the litellm params
litellm_params: Final = get_litellm_params(**kwargs)
# get the custom llm provider
model, custom_llm_provider, dynamic_api_key, api_base = get_llm_provider(
model=model,
custom_llm_provider=litellm_params.get("custom_llm_provider", None),
api_base=litellm_params.get("api_base", None),
api_key=litellm_params.get("api_key", None),
)
# route to the correct provider w/ the params
try:
llm_provider: Final = LlmProviders(custom_llm_provider)
image_variation_provider: Final = LITELLM_IMAGE_VARIATION_PROVIDERS(llm_provider)
except ValueError:
raise ValueError(
f"Invalid image variation provider: {custom_llm_provider}. Supported providers are: {LITELLM_IMAGE_VARIATION_PROVIDERS}"
)
model_response: Final = ImageResponse()
response: ImageResponse | None = None
provider_config: Final = ProviderConfigManager.get_provider_model_info(
model=model or "", # openai defaults to dall-e-2
provider=llm_provider,
)
if provider_config is None:
raise ValueError(
f"image variation provider has no known model info config - required for getting api keys, etc.: {custom_llm_provider}. Supported providers are: {LITELLM_IMAGE_VARIATION_PROVIDERS}"
)
api_key: Final = provider_config.get_api_key(litellm_params.get("api_key", None))
api_base = provider_config.get_api_base(litellm_params.get("api_base", None))View on GitHub (pinned to 77b7c6c40c)