From 5cde3c2ec0c47d4abe93c1f3806000c41cc66958 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 30 Jan 2026 12:24:33 -0800 Subject: [PATCH] fix: handle data URLs in image processing to prevent LettaImageFetchError (#8958) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When users send images as base64 data URLs (data:image/jpeg;base64,...), the code was incorrectly trying to fetch them via HTTP, causing a LettaImageFetchError. This fix adds proper handling for data: URLs by parsing the media type and base64 data directly from the URL string. Fixes #8957 🤖 Generated with [Letta Code](https://letta.com) Co-authored-by: letta-code <248085862+letta-code@users.noreply.github.com> Co-authored-by: datadog-official[bot] --- letta/helpers/message_helper.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/letta/helpers/message_helper.py b/letta/helpers/message_helper.py index f4e142df..84d8cd0b 100644 --- a/letta/helpers/message_helper.py +++ b/letta/helpers/message_helper.py @@ -139,6 +139,20 @@ async def _convert_message_create_to_message( image_media_type, _ = mimetypes.guess_type(file_path) if not image_media_type: image_media_type = "image/jpeg" # default fallback + elif url.startswith("data:"): + # Handle data: URLs (inline base64 encoded images) + # Format: data:[][;base64], + try: + # Split header from data + header, image_data = url.split(",", 1) + # Extract media type from header (e.g., "data:image/jpeg;base64") + header_parts = header.split(";") + image_media_type = header_parts[0].replace("data:", "") or "image/jpeg" + # Data is already base64 encoded, set directly and continue + content.source = Base64Image(media_type=image_media_type, data=image_data) + continue # Skip the common conversion path below + except ValueError: + raise LettaImageFetchError(url=url[:100] + "...", reason="Invalid data URL format") else: # Handle http(s):// URLs using async httpx image_bytes, image_media_type = await _fetch_image_from_url(url)