BerriAI/litellm · error · ValueError
Invalid image_url type
Error message
Invalid image_url type: {type(image_url).__name__}. Expected str or dict with 'url' field. What it means
Type-dispatch fallback in the image token counter: image_url is neither a dict with a 'url' field nor a string (e.g. None or another type), so its token cost cannot be computed.
Solutions
- Pass image_url as a string or a dict with a 'url' field.
- Fix the type of the image_url value in the message.
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at litellm/litellm_core_utils/token_counter.py:607 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/429ab15e34b314e2.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/token_counter.py:607
raise ValueError(f"Invalid detail value: {detail}. Expected 'low', 'high', or 'auto'.")
url: Final = image_url.get("url")
if not url:
raise ValueError("Missing required key 'url' in image_url dict.")
return calculate_img_tokens(
data=url,
mode=detail,
use_default_image_token_count=use_default_image_token_count,
)
elif isinstance(image_url, str):
if not image_url.strip():
raise ValueError("Empty image_url string is not valid.")
return calculate_img_tokens(
data=image_url,
mode="auto",
use_default_image_token_count=use_default_image_token_count,
)
else:
raise ValueError(f"Invalid image_url type: {type(image_url).__name__}. Expected str or dict with 'url' field.")
def _validate_anthropic_content(content: Mapping[str, Any]) -> type:
"""
Validate and determine which Anthropic TypedDict applies.
Returns the corresponding TypedDict class if recognized, otherwise raises.
"""
content_type: Final = content.get("type")
if not content_type:
raise ValueError("Anthropic content missing required field: 'type'")
mapping: Final = {
"tool_use": AnthropicMessagesToolUseParam,
"tool_result": AnthropicMessagesToolResultParam,
}
expected_cls: Final = mapping.get(content_type)View on GitHub (pinned to 77b7c6c40c)