{"record":{"id":"f21fb9173c5c8c49","repo":"langchain-ai/langchain","slug":"unsupported-source-type-only-url-and-base64-a","errorCode":null,"errorMessage":"Unsupported source type. Only 'url' and 'base64' are supported.","messagePattern":"Unsupported source type\\. Only 'url' and 'base64' are supported\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/messages/block_translators/openai.py","lineNumber":55,"sourceCode":"            \"type\": \"image_url\",\n            \"image_url\": {\n                \"url\": block[\"url\"],\n            },\n        }\n    if \"base64\" in block or block.get(\"source_type\") == \"base64\":\n        if \"mime_type\" not in block:\n            error_message = \"mime_type key is required for base64 data.\"\n            raise ValueError(error_message)\n        mime_type = block[\"mime_type\"]\n        base64_data = block[\"data\"] if \"data\" in block else block[\"base64\"]\n        return {\n            \"type\": \"image_url\",\n            \"image_url\": {\n                \"url\": f\"data:{mime_type};base64,{base64_data}\",\n            },\n        }\n    error_message = \"Unsupported source type. Only 'url' and 'base64' are supported.\"\n    raise ValueError(error_message)\n\n\ndef convert_to_openai_data_block(\n    block: dict[str, Any],\n    api: Literal[\"chat/completions\", \"responses\"] = \"chat/completions\",\n) -> dict[str, Any]:\n    \"\"\"Format standard data content block to format expected by OpenAI.\n\n    \"Standard data content block\" can include old-style LangChain v0 blocks\n    (URLContentBlock, Base64ContentBlock, IDContentBlock) or new ones.\n\n    Args:\n        block: The content block to convert.\n        api: The OpenAI API being targeted. Either \"chat/completions\" or \"responses\".\n\n    Raises:\n        ValueError: If required keys are missing.\n        ValueError: If file URLs are used with Chat Completions API.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/messages/block_translators/openai.py#L37-L73","documentation":"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.","triggerScenarios":"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`.","commonSituations":"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.","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"],"exampleFix":"# before\nblock = {\"type\": \"image\", \"file_id\": \"file-abc123\"}\n\n# after\nblock = {\"type\": \"file\", \"file_id\": \"file-abc123\"}","handlingStrategy":"type-guard","validationCode":"def has_image_source(block: dict) -> bool:\n    return \"url\" in block or \"base64\" in block or block.get(\"source_type\") == \"base64\"","typeGuard":"def is_openai_image_block(block: dict) -> bool:\n    return block.get(\"type\") == \"image\" and (\"url\" in block or \"base64\" in block or block.get(\"source_type\") == \"base64\")","tryCatchPattern":null,"preventionTips":["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"],"tags":["openai","image","content-blocks","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}