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
- Provide one of `url` or `base64` (+ `mime_type` for base64) on the image block
- 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"`
- 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
- Never put file_id on a type:'image' block — use type:'file'
- Validate blocks against a small schema before invoking OpenAI models
- Prefer the typed v1 block constructors over hand-written dicts
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
- mime_type key is required for base64 data.
- Keys base64, url, or file_id required for file blocks.
- Block of type {block['type']} is not supported.
- Must provide one of: url, base64, or file_id
- Unrecognized content block at messages[{i}].content[{j}] has
AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14).
Data as JSON: /api/errors/f21fb9173c5c8c49.
Report an issue: GitHub.