-
Notifications
You must be signed in to change notification settings - Fork 179
Open
Labels
Description
Bug Description
When a user sends an oversized image in a conversation, the LLM API call fails with:
litellm.BadRequestError: Error code: 400 - AnthropicException -
{"type":"error","error":{"type":"invalid_request_error",
"message":"messages.4.content.1.image.source.base64.data:
At least one of the image dimensions exceed max allowed size
for many-image requests: 2000 pixels"}}
The error crashes the conversation with no recovery, even though the runtime is still alive.
Root Cause
The ImageContent class in openhands-sdk/openhands/sdk/llm/message.py passes image URLs/base64 data directly to the LLM provider without any dimension validation or resizing. Anthropic enforces a 2000px max dimension for many-image requests, and other providers have similar limits.
class ImageContent(BaseContent):
type: Literal["image"] = "image"
image_urls: list[str]
def to_llm_dict(self) -> list[dict[str, str | dict[str, str]]]:
images: list[dict[str, str | dict[str, str]]] = []
for url in self.image_urls:
images.append({"type": "image_url", "image_url": {"url": url}})
# No dimension check or resize happens here
return imagesExpected Behavior
The SDK should automatically downscale images that exceed provider dimension limits before including them in LLM API calls. This should happen transparently so users can attach any image without hitting cryptic API errors.
Proposed Solution
- Add image resizing logic — When converting
ImageContentto LLM format (into_llm_dict()or at the message serialization layer), detect base64-encoded images, decode them, check dimensions, and resize if any dimension exceeds the max (e.g., 2000px for Anthropic, or a conservative default). - Make the limit configurable — The max dimension could be tied to the LLM provider config or exposed as a setting, since different providers have different limits.
- Handle both base64 and URL images — For base64 images, resize in-memory. For URL-based images, consider fetching and resizing, or at minimum validate and warn.
- Preserve aspect ratio — When downscaling, maintain the original aspect ratio.
Reproduction Steps
- Start a conversation using an Anthropic model (e.g.,
claude-opus-4-6) - Send a message with an attached image where at least one dimension exceeds 2000px
- Observe the
litellm.BadRequestErrorcrash
Environment
- Model:
claude-opus-4-6(via LiteLLM) - Error source: Anthropic API
invalid_request_error
Reactions are currently unavailable