BerriAI/litellm · error · ValueError
API base is required for OpenAI image variations
Error message
API base is required for OpenAI image variations
What it means
Unlike other litellm paths that silently default to https://api.openai.com/v1, the OpenAI image-variation branch resolves api_base only from the explicit argument or litellm module-level api_base via provider_config.get_api_base, and treats None as fatal before calling openai_image_variations.image_variations. This is a hard requirement of this endpoint's routing code.
Solutions
- Pass api_base explicitly: litellm.image_variation(..., api_base='https://api.openai.com/v1').
- Or set the module default once: litellm.api_base = 'https://api.openai.com/v1'.
- For gateways, point api_base at your compatible endpoint instead of api.openai.com.
- Centralize both api_key and api_base in one config helper so no call site can omit them.
Example fix
# before resp = litellm.image_variation(model="dall-e-2", image=img, api_key=key) # ValueError: API base is required for OpenAI image variations # after resp = litellm.image_variation(model="dall-e-2", image=img, api_key=key, api_base="https://api.openai.com/v1")
Defensive patterns
Strategy: validation
Validate before calling
import litellm
API_BASE = "https://api.openai.com/v1" # or your gateway
if litellm.api_base is None:
litellm.api_base = API_BASE
# then every image_variation call inherits a non-None api_base Try / catch
try:
resp = litellm.image_variation(model="dall-e-2", image=img, api_key=key)
except ValueError as e:
if "API base is required for OpenAI image variations" in str(e):
resp = litellm.image_variation(model="dall-e-2", image=img, api_key=key, api_base="https://api.openai.com/v1")
else:
raise Prevention
- Wrap image_variation in one client function that always passes api_key and api_base together.
- For OpenAI-compatible gateways, load both key and base from the same config object.
- Remember this branch ignores OPENAI_API_BASE — only the argument or litellm.api_base counts.
When it happens
Trigger: litellm.image_variation(model='dall-e-2', image=..., api_key='sk-...') with no api_base and no litellm.api_base set; relying on OPENAI_API_BASE env alone (this branch does not read it); migrations from image_generation calls where api_base defaulted automatically.
Common situations: Users surprised that generation works without api_base but variations does not; OpenAI-compatible gateways (Azure OpenAI, proxies) where the caller carefully passes the key but forgets the base; notebook sessions where litellm.api_base was never assigned.
Related errors
- API base is required for Topaz image variations
- API key is required for OpenAI image variations
- Invalid image variation provider
- api_base is required
- api_base is required for A2A provider. Either provide…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/11138e45da5e75d5.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/images/main.py:662
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))
if image_variation_provider == LITELLM_IMAGE_VARIATION_PROVIDERS.OPENAI:
if api_key is None:
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")View on GitHub (pinned to 77b7c6c40c)