{"record":{"id":"d6fd7fddde8560e7","repo":"browser-use/browser-use","slug":"failed-to-download-image-from-url-e","errorCode":null,"errorMessage":"Failed to download image from {url}: {e}","messagePattern":"Failed to download image from (.+?): (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"browser_use/llm/aws/serializer.py","lineNumber":88,"sourceCode":"\t\t\tresponse.raise_for_status()\n\n\t\t\t# Detect format from content type or URL\n\t\t\tcontent_type = response.headers.get('content-type', '').lower()\n\t\t\tif 'jpeg' in content_type or url.lower().endswith(('.jpg', '.jpeg')):\n\t\t\t\timage_format = 'jpeg'\n\t\t\telif 'png' in content_type or url.lower().endswith('.png'):\n\t\t\t\timage_format = 'png'\n\t\t\telif 'gif' in content_type or url.lower().endswith('.gif'):\n\t\t\t\timage_format = 'gif'\n\t\t\telif 'webp' in content_type or url.lower().endswith('.webp'):\n\t\t\t\timage_format = 'webp'\n\t\t\telse:\n\t\t\t\timage_format = 'jpeg'  # Default format\n\n\t\t\treturn image_format, response.content\n\n\t\texcept Exception as e:\n\t\t\traise ValueError(f'Failed to download image from {url}: {e}')\n\n\t@staticmethod\n\tdef _serialize_content_part_text(part: ContentPartTextParam) -> dict[str, Any]:\n\t\t\"\"\"Convert a text content part to AWS Bedrock format.\"\"\"\n\t\treturn {'text': part.text}\n\n\t@staticmethod\n\tdef _serialize_content_part_image(part: ContentPartImageParam) -> dict[str, Any]:\n\t\t\"\"\"Convert an image content part to AWS Bedrock format.\"\"\"\n\t\turl = part.image_url.url\n\n\t\tif AWSBedrockMessageSerializer._is_base64_image(url):\n\t\t\t# Handle base64 encoded images\n\t\t\timage_format, image_bytes = AWSBedrockMessageSerializer._parse_base64_url(url)\n\t\telif AWSBedrockMessageSerializer._is_url_image(url):\n\t\t\t# Download and convert URL images\n\t\t\timage_format, image_bytes = AWSBedrockMessageSerializer._download_and_convert_image(url)\n\t\telse:","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/browser-use/browser-use/blob/6c73fced2f6d45a11d88622fe56365a5fe18f28b/browser_use/llm/aws/serializer.py#L70-L106","documentation":"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.","triggerScenarios":"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).","commonSituations":"Screenshots hosted on short-lived CDNs; internal URLs not reachable from the agent's network; hotlink protection blocking httpx's default headers.","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"],"exampleFix":"```python\n# before - rely on remote URL\nimg = {'type': 'image_url', 'image_url': {'url': 'https://cdn/expiring.png'}}\n\n# after - fetch once yourself and inline\nimport httpx, base64\nb = httpx.get(url, timeout=30).content\nimg = {'type': 'image_url', 'image_url': {'url': 'data:image/png;base64,' + base64.b64encode(b).decode()}}\n```","handlingStrategy":"fallback","validationCode":"```python\nimport httpx\ndef url_fetchable(url: str) -> bool:\n    try:\n        return httpx.head(url, timeout=10, follow_redirects=True).status_code < 400\n    except Exception:\n        return False\n```","typeGuard":null,"tryCatchPattern":"```python\ntry:\n    await llm.ainvoke(msgs)\nexcept ValueError as e:\n    if 'Failed to download image' in str(e):\n        b64 = inline_image_as_data_url(url)  # fetch yourself, send base64\n```","preventionTips":["Use long-lived, directly reachable image URLs","Pre-download images and inline them to remove network dependence at LLM-call time"],"tags":["aws","bedrock","images","network","download"],"backgroundTag":null,"analyzedSha":"6c73fced2f6d45a11d88622fe56365a5fe18f28b","analyzedAt":"2026-08-14T19:42:40.557Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}