langchain-ai/langchain · error · ValueError

Unsupported source type. Only 'url' and 'base64' are support

Error message

Unsupported source type. Only 'url' and 'base64' are supported.

What it means

Raised when an image content block sent to the OpenAI converter has neither a `url` key, a `base64` key, nor `source_type == "base64"`. The converter only knows how to represent images as a URL or as base64 data; any other shape (e.g. only a `file_id`) is rejected on this path.

Source

Thrown at libs/core/langchain_core/messages/block_translators/openai.py:55

            "type": "image_url",
            "image_url": {
                "url": block["url"],
            },
        }
    if "base64" in block or block.get("source_type") == "base64":
        if "mime_type" not in block:
            error_message = "mime_type key is required for base64 data."
            raise ValueError(error_message)
        mime_type = block["mime_type"]
        base64_data = block["data"] if "data" in block else block["base64"]
        return {
            "type": "image_url",
            "image_url": {
                "url": f"data:{mime_type};base64,{base64_data}",
            },
        }
    error_message = "Unsupported source type. Only 'url' and 'base64' are supported."
    raise ValueError(error_message)


def convert_to_openai_data_block(
    block: dict[str, Any],
    api: Literal["chat/completions", "responses"] = "chat/completions",
) -> dict[str, Any]:
    """Format standard data content block to format expected by OpenAI.

    "Standard data content block" can include old-style LangChain v0 blocks
    (URLContentBlock, Base64ContentBlock, IDContentBlock) or new ones.

    Args:
        block: The content block to convert.
        api: The OpenAI API being targeted. Either "chat/completions" or "responses".

    Raises:
        ValueError: If required keys are missing.
        ValueError: If file URLs are used with Chat Completions API.

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Provide one of `url` or `base64` (+ `mime_type` for base64) on the image block
  2. If you meant to reference an uploaded file, pass the file reference through the file-block path (`type: "file"` with `file_id`) instead of `type: "image"`
  3. Validate/normalize blocks with the v1 constructors (`ImageContentBlock(url=...)`) before sending

Example fix

# before
block = {"type": "image", "file_id": "file-abc123"}

# after
block = {"type": "file", "file_id": "file-abc123"}
Defensive patterns

Strategy: type-guard

Validate before calling

def has_image_source(block: dict) -> bool:
    return "url" in block or "base64" in block or block.get("source_type") == "base64"

Type guard

def is_openai_image_block(block: dict) -> bool:
    return block.get("type") == "image" and ("url" in block or "base64" in block or block.get("source_type") == "base64")

Prevention

When it happens

Trigger: Passing an image block that only carries `file_id` or `source_type: "id"` to the image branch of the OpenAI block formatter; blocks with typo'd keys (`"urls"`, `"src"`); empty image dicts with only `type`/`id`.

Common situations: Reusing file-ID-based image blocks that work with Responses-style APIs on a path that only supports url/base64; typos when constructing blocks by hand from documentation; blocks that were filtered/partially copied from another message.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/f21fb9173c5c8c49. Report an issue: GitHub.