BerriAI/litellm · error · ValueError
image_response must be of type ImageResponse, got type={type
Error message
image_response must be of type ImageResponse, got type={type(image_response)} What it means
Type guard in the RunwayML cost calculator: pricing is per generated image, but the object passed as image_response is not an ImageResponse instance (wrong shape from a nonstandard handler), so num_images cannot be determined.
Source
Thrown at litellm/llms/runwayml/cost_calculator.py:28
) -> float:
"""
RunwayML image generation cost calculator.
RunwayML charges per image generated, not per pixel.
Pricing is stored in model_prices_and_context_window.json with output_cost_per_image.
"""
_model_info: Final = litellm.get_model_info(
model=model,
custom_llm_provider=litellm.LlmProviders.RUNWAYML.value,
)
output_cost_per_image: Final[float] = _model_info.get("output_cost_per_image") or 0.0
num_images: int = 0
if isinstance(image_response, ImageResponse):
if image_response.data:
num_images = len(image_response.data)
return output_cost_per_image * num_images
else:
raise ValueError(f"image_response must be of type ImageResponse, got type={type(image_response)}")
View on GitHub (pinned to 77b7c6c40c)
Solutions
- Internal type check failed; pass the ImageResponse returned by litellm rather than a custom object.
- If reached from a public call, report it to the litellm issue tracker.
Example fix
# use litellm.image_generation output directly for cost tracking.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Triggered when the RunwayML cost calculator receives an image_response that is not an ImageResponse instance.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/4dcf6ebadcb651ac.
Report an issue: GitHub.