BerriAI/litellm · error · ValueError
Unable to get Image Response. Please pass a valid llm_provid
Error message
Unable to get Image Response. Please pass a valid llm_provider.
What it means
In image generation, the provider function's result is normalized: a dict is unpacked into ImageResponse, an ImageResponse passes through (cache hits), and a pending coroutine is awaited. If after all that response is still None — the provider returned nothing recognizable — LiteLLM raises ValueError and then re-raises it through exception_type with the provider's error mapping.
Source
Thrown at litellm/images/main.py:118
# Add the context to the function
ctx: Final = contextvars.copy_context()
func_with_context: Final = partial(ctx.run, func)
_, custom_llm_provider, _, _ = get_llm_provider(model=model, api_base=kwargs.get("api_base", None))
# Await normally
init_response: Final = await loop.run_in_executor(None, func_with_context)
response: ImageResponse | None = None
if isinstance(init_response, dict):
response = ImageResponse(**init_response)
elif isinstance(init_response, ImageResponse): ## CACHING SCENARIO
response = init_response
elif asyncio.iscoroutine(init_response):
response = await init_response
if response is None:
raise ValueError("Unable to get Image Response. Please pass a valid llm_provider.")
return response
except Exception as e:
custom_llm_provider = custom_llm_provider or "openai"
raise exception_type(
model=model,
custom_llm_provider=custom_llm_provider,
original_exception=e,
completion_kwargs=args,
extra_kwargs=kwargs,
)
# fmt: off
# Overload for when aimg_generation=True (returns Coroutine)
@overload
def image_generation(View on GitHub (pinned to 6c2dcb801b)
Solutions
- Verify image support: use a model/provider with real image support (e.g. openai/dall-e-3, azure image models, gemini image models, stability)
- Set custom_llm_provider correctly for your model string instead of omitting/typoing it
- Upgrade litellm — image adapters that previously returned None for some paths have been filled in over releases
- Reproduce with litellm.image_generation(model='<provider>/<image-model>', prompt=..., custom_llm_provider='<provider>') and inspect the provider call if it still fails
Example fix
# before r = litellm.image_generation(model='some-oss-model', prompt='a cat') # provider returns None # after r = litellm.image_generation(model='dall-e-3', prompt='a cat', custom_llm_provider='openai')
Defensive patterns
Strategy: fallback
Validate before calling
SUPPORTED_IMAGE_PROVIDERS = {"openai", "azure", "gemini", "stability", "bedrock", "vertex_ai"}
if custom_llm_provider not in SUPPORTED_IMAGE_PROVIDERS:
raise ValueError(f"{custom_llm_provider} has no image generation support") Type guard
def provider_supports_images(provider: str) -> bool:
import litellm
return provider in getattr(litellm, "image_providers", {"openai", "azure", "gemini", "stability"}) Try / catch
try:
r = litellm.image_generation(model=m, prompt=p, custom_llm_provider=prov)
except Exception as e:
if "Unable to get Image Response" in str(e):
r = litellm.image_generation(model="dall-e-3", prompt=p, custom_llm_provider="openai") # fallback Prevention
- Always pass custom_llm_provider for image calls
- Verify the model actually serves images before wiring it in
When it happens
Trigger: Calling litellm.image_generation with a custom_llm_provider that has no real image implementation (returns None), a provider adapter that silently swallows errors and returns None, or kwargs (e.g. async flags) that route to a code path which never produces a response.
Common situations: Passing an unsupported provider/model for image generation (e.g. a text-only provider); version mismatches where a provider class exists but its image method is a stub; mocking provider calls to return None in tests.
Related errors
- Error: {response.status_code} - {response.text}
- Missing Authorization header
- Invalid bearer token
- Invalid API key
- Prompt '{prompt_id}' not found
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/6f8a59d0b5c1e415.
Report an issue: GitHub.