OpenAI Responses Image Content Blocks Do Not Support File_id Inputs
The OpenAI Responses block translator in langchain-core raises ValueError when converting image blocks with file_id or legacy id source types, even though the Responses API supports input_image.file_id.
In langchain_core.messages.block_translators.openai.convert_to_openai_data_block, the responses branch for ImageContentBlock only handles source types 'url' and 'base64', raising ValueError for 'file_id' and legacy 'id'. This is an incomplete implementation of the OpenAI Responses API input_image schema.
1. Import convert_to_openai_data_block and create_image_block from langchain_core.messages.
2. Create block = create_image_block(file_id='file-abc123').
3. Call convert_to_openai_data_block(block, api='responses').
4. Observe ValueError: Unsupported source type. Only 'url' and 'base64' are supported.
Fixing Code Block
def _convert_image_block_to_responses(block: ImageContentBlock) -> dict:
source = block['source']
source_type = source.get('type')
if source_type == 'url':
return {'type': 'input_image', 'image_url': source['url']}
if source_type == 'base64':
media_type = source.get('media_type', 'image/jpeg')
data = source['data']
image_url = f'data:{media_type};base64,{data}'
return {'type': 'input_image', 'image_url': image_url}
if source_type == 'file_id':
return {'type': 'input_image', 'file_id': source['file_id']}
if source_type == 'id':
return {'type': 'input_image', 'file_id': source['id']}
raise ValueError(
'Unsupported image source type: ' + source_type +
'. Only url, base64, file_id, and id are supported for Responses API.'
)
Adds explicit branches for source types 'file_id' and legacy 'id' in the Responses image translator, returning the OpenAI Responses payload {'type': 'input_image', 'file_id': ...}. The existing url and base64 branches are preserved, and the Chat Completions path remains untouched.
Edge Case Audit
The change assumes the file_id is valid and accessible at runtime; the OpenAI Responses API may still reject the payload with 400/404 if the file has expired or belongs to a different organization. The function is pure and stateless, so no concurrency or threading issues are introduced. Rollback: revert the modified function or pin langchain-core to a version without this change. If existing users were passing unsupported source types, they will now receive the new ValueError listing supported types, which is more informative but could surface unexpected failures.