browser-use/browser-use · error · ValueError
Failed to download image from {url}: {e}
Error message
Failed to download image from {url}: {e} What it means
Raised when downloading an http(s) image for Bedrock fails: the httpx GET raised, returned a non-2xx status (raise_for_status), or any other exception occurred during fetch. The original error is embedded in the message.
Source
Thrown at browser_use/llm/aws/serializer.py:88
response.raise_for_status()
# Detect format from content type or URL
content_type = response.headers.get('content-type', '').lower()
if 'jpeg' in content_type or url.lower().endswith(('.jpg', '.jpeg')):
image_format = 'jpeg'
elif 'png' in content_type or url.lower().endswith('.png'):
image_format = 'png'
elif 'gif' in content_type or url.lower().endswith('.gif'):
image_format = 'gif'
elif 'webp' in content_type or url.lower().endswith('.webp'):
image_format = 'webp'
else:
image_format = 'jpeg' # Default format
return image_format, response.content
except Exception as e:
raise ValueError(f'Failed to download image from {url}: {e}')
@staticmethod
def _serialize_content_part_text(part: ContentPartTextParam) -> dict[str, Any]:
"""Convert a text content part to AWS Bedrock format."""
return {'text': part.text}
@staticmethod
def _serialize_content_part_image(part: ContentPartImageParam) -> dict[str, Any]:
"""Convert an image content part to AWS Bedrock format."""
url = part.image_url.url
if AWSBedrockMessageSerializer._is_base64_image(url):
# Handle base64 encoded images
image_format, image_bytes = AWSBedrockMessageSerializer._parse_base64_url(url)
elif AWSBedrockMessageSerializer._is_url_image(url):
# Download and convert URL images
image_format, image_bytes = AWSBedrockMessageSerializer._download_and_convert_image(url)
else:View on GitHub (pinned to 6c73fced2f)
Solutions
- Verify the URL is reachable (curl -I) from the machine running the agent
- If the URL is presigned/expiring, refresh it or download the image yourself and pass a base64 data URL
- Increase reliability by hosting images somewhere stable and public to the agent
Example fix
```python
# before - rely on remote URL
img = {'type': 'image_url', 'image_url': {'url': 'https://cdn/expiring.png'}}
# after - fetch once yourself and inline
import httpx, base64
b = httpx.get(url, timeout=30).content
img = {'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,' + base64.b64encode(b).decode()}}
``` Defensive patterns
Strategy: fallback
Validate before calling
```python
import httpx
def url_fetchable(url: str) -> bool:
try:
return httpx.head(url, timeout=10, follow_redirects=True).status_code < 400
except Exception:
return False
``` Try / catch
```python
try:
await llm.ainvoke(msgs)
except ValueError as e:
if 'Failed to download image' in str(e):
b64 = inline_image_as_data_url(url) # fetch yourself, send base64
``` Prevention
- Use long-lived, directly reachable image URLs
- Pre-download images and inline them to remove network dependence at LLM-call time
When it happens
Trigger: 404/403 on the image URL, expired signed URLs (presigned S3 links), DNS failure, TLS errors, server timeouts beyond the 30s limit, or a content-type the code cannot classify (it defaults to jpeg but the fetch itself may still fail).
Common situations: Screenshots hosted on short-lived CDNs; internal URLs not reachable from the agent's network; hotlink protection blocking httpx's default headers.
Related errors
- {e.message}
- Invalid base64 URL: {url}
- Failed to decode base64 image data: {e}
- httpx not available. Please install it to use URL images wit
- Unsupported image URL format: {url}
AI-assisted analysis of browser-use/browser-use@6c73fced2f (2026-08-14).
Data as JSON: /api/errors/d6fd7fddde8560e7.
Report an issue: GitHub.