fix: map Chat Completion file type to Responses API input_file

When bridging /chat/completions to the Responses API, content items with
type 'file' were falling through to the default handler and being
stringified as input_text. This caused the model to receive the Python
dict representation as plain text instead of the actual file content.

Add explicit handling for type 'file' that correctly maps:
  {"type": "file", "file": {"file_data": "...", "filename": "..."}}
to:
  {"type": "input_file", "file_data": "...", "filename": "..."}

Fixes BerriAI/litellm#23588
This commit is contained in:
Ethan T. 2026-03-14 15:12:48 +08:00
parent 25ee2fb3f9
commit 0bdfd95ad8

View file

@ -693,6 +693,20 @@ class LiteLLMResponsesTransformationHandler(CompletionTransformationBridge):
verbose_logger.debug(
f"Chat provider: image -> {converted}"
)
elif item_type == "file":
# Map Chat Completion file to Responses API input_file
# {"type": "file", "file": {"file_data": "...", "filename": "..."}}
# -> {"type": "input_file", "file_data": "...", "filename": "..."}
file_data = item.get("file", {})
converted = {"type": "input_file"}
if isinstance(file_data, dict):
for key in ["file_id", "file_data", "filename"]:
if key in file_data:
converted[key] = file_data[key]
result.append(converted)
verbose_logger.debug(
f"Chat provider: file -> {converted}"
)
elif item_type in [
"input_text",
"input_image",