Add PDF upload + Responses streaming example and ensure MIME via filename #2527
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.
Problem: Uploading raw PDF bytes without a filename leads to the server receiving an unsupported MIME type (None), causing 400 errors when referenced in Responses streaming. Also, the correct content payload for Responses should use
input_text
+input_file
. See Issue #2472.What this changes
examples/responses/file_input_pdf_streaming.py
showing:(filename, bytes, "application/pdf")
.input=[{"role": "user", "content": [{"type":"input_text"}, {"type":"input_file", "file_id": ...}]}]
withclient.responses.stream(...)
.tests/test_multipart_pdf_upload.py
: Asserts multipart includesfilename="document.pdf"
and, when tuple is used,Content-Type: application/pdf
.tests/api_resources/test_responses_file_input.py
: Mocks file upload +/responses
and verifies a streaming call withinput_file
completes.Why this works
input_file
withinput_text
matches the Responses API input schema and avoids malformed content arrays.How to run
python examples/responses/file_input_pdf_streaming.py /path/to/document.pdf --prompt "Summarize this document."
pytest -k "multipart_pdf_upload or responses_file_input"
Backward compatibility
Closes