{"record":{"id":"11138e45da5e75d5","repo":"BerriAI/litellm","slug":"api-base-is-required-for-openai-image-variations","errorCode":null,"errorMessage":"API base is required for OpenAI image variations","messagePattern":"API base is required for OpenAI image variations","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/images/main.py","lineNumber":662,"sourceCode":"\n    provider_config: Final = ProviderConfigManager.get_provider_model_info(\n        model=model or \"\",  # openai defaults to dall-e-2\n        provider=llm_provider,\n    )\n\n    if provider_config is None:\n        raise ValueError(\n            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}\"\n        )\n\n    api_key: Final = provider_config.get_api_key(litellm_params.get(\"api_key\", None))\n    api_base = provider_config.get_api_base(litellm_params.get(\"api_base\", None))\n\n    if image_variation_provider == LITELLM_IMAGE_VARIATION_PROVIDERS.OPENAI:\n        if api_key is None:\n            raise ValueError(\"API key is required for OpenAI image variations\")\n        if api_base is None:\n            raise ValueError(\"API base is required for OpenAI image variations\")\n\n        response = openai_image_variations.image_variations(\n            model_response=model_response,\n            api_key=api_key,\n            api_base=api_base,\n            model=model,\n            image=image,\n            timeout=litellm_params.get(\"timeout\", None),\n            custom_llm_provider=custom_llm_provider,\n            logging_obj=litellm_logging_obj,\n            optional_params={},\n            litellm_params=litellm_params,\n        )\n    elif image_variation_provider == LITELLM_IMAGE_VARIATION_PROVIDERS.TOPAZ:\n        if api_key is None:\n            raise ValueError(\"API key is required for Topaz image variations\")\n        if api_base is None:\n            raise ValueError(\"API base is required for Topaz image variations\")","sourceCodeStart":644,"sourceCodeEnd":680,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/images/main.py#L644-L680","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nresp = litellm.image_variation(model=\"dall-e-2\", image=img, api_key=key)\n# ValueError: API base is required for OpenAI image variations\n\n# after\nresp = litellm.image_variation(model=\"dall-e-2\", image=img, api_key=key, api_base=\"https://api.openai.com/v1\")","handlingStrategy":"validation","validationCode":"import litellm\n\nAPI_BASE = \"https://api.openai.com/v1\"  # or your gateway\nif litellm.api_base is None:\n    litellm.api_base = API_BASE\n# then every image_variation call inherits a non-None api_base","typeGuard":null,"tryCatchPattern":"try:\n    resp = litellm.image_variation(model=\"dall-e-2\", image=img, api_key=key)\nexcept ValueError as e:\n    if \"API base is required for OpenAI image variations\" in str(e):\n        resp = litellm.image_variation(model=\"dall-e-2\", image=img, api_key=key, api_base=\"https://api.openai.com/v1\")\n    else:\n        raise","preventionTips":["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."],"tags":["litellm","image-variation","openai","api-base","endpoint-url"],"backgroundTag":"missing-api-base-url","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}