fix(models): convert input_file items that reference a file_id on the Chat Completions path - #4295
Merged
Merged
Conversation
… Chat Completions path The Chat Completions file content part accepts either inline file_data or an uploaded file_id, and the SDK's own ToolOutputFileContent emits file-id-only input_file items. The converter rejected any input_file without file_data, so a user message or tool output referencing an uploaded file raised UserError even though it is representable. Fall back to file_id when file_data is absent.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Chat Completions converter (
Converter.extract_all_content) rejected anyinput_filecontent part that did not carry inlinefile_data, raisingUserError("Only file_data is supported for input_file ..."). But the ChatCompletions
filecontent part (openai.types.chat...FileFile) accepts eitherinline
file_dataor a reference to an uploadedfile_id, so aninput_filethat references afile_idis fully representable and should beconverted rather than rejected.
This also fixes an internal inconsistency: the SDK's own
ToolOutputFileContentemitsfile_id-onlyinput_fileitems (seeItemHelpers._convert_single_tool_output_pydantic_model). A function tool thatreturns
ToolOutputFileContent(file_id=...)therefore produced a tool outputthat the SDK's own Chat Completions converter refused to convert on the next
turn.
extract_all_contentis called on tool outputs regardless ofpreserve_tool_output_all_content(the non-preserve branch still calls itbefore filtering to text), so this
UserErroraborts the run instead of lettingthe caller degrade the output.
Fix (minimal): prefer inline
file_datawhen present, otherwise fall backto
file_id. Only raise when neither is present. Afile_urlremainsunrepresentable on Chat Completions and still raises, and existing
file_databehavior (including the
file_data-takes-precedence and optionalfilenamehandling) is unchanged.
Before:
After:
Root cause
The
input_filebranch guarded onfile_dataonly and raised for everythingelse, predating (and never updated for) the
file_idfield that both theResponses
input_fileparam and the Chat Completionsfilepart support.Why minimal
file_datapath,file_data-over-file_idprecedence,filenameforwarding, and prompt-cache-breakpoint copying are all preserved.
file_urlis intentionally left unsupported (not representable on ChatCompletions) and still raises.
Test plan
Added three focused unit tests in
tests/models/test_openai_chatcompletions_converter.py:test_extract_all_content_supports_input_file_file_id— converts afile_id-onlyinput_file(fails onmain, passes here).test_extract_all_content_prefers_input_file_data_over_file_id—file_datastill wins when both are present.
test_extract_all_content_rejects_input_file_without_data_or_id— neitherpresent still raises
UserError.Validation commands (all pass):
uv run pytest tests/models/test_openai_chatcompletions_converter.py -q→ 51 passeduv run pytest tests/models -q→ 695 passeduv run pytest -q→ 7161 passed, 39 skippeduv run ruff check .→ All checks passeduv run ruff format --check .→ cleanuv run mypy . --exclude site→ Success (852 source files)uv run pyright→ 0 errorsCompatibility: behavior only broadens (previously-raising inputs now convert);
no changes to items that already converted. No dependency or config changes.
Issue number
N/A (no OpenAI API key or live service required to reproduce).
Checks
.agents/skills/code-change-verification/scripts/run.sh/reviewbefore submitting this PR