Skip to content

Conversation

oliviergodement
Copy link

  • 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

    • Example: Adds examples/responses/file_input_pdf_streaming.py showing:
      • Setting a filename on an in-memory buffer (so the server infers application/pdf), or
      • Using tuple-style upload (filename, bytes, "application/pdf").
      • Using input=[{"role": "user", "content": [{"type":"input_text"}, {"type":"input_file", "file_id": ...}]}] with client.responses.stream(...).
    • Tests:
      • tests/test_multipart_pdf_upload.py: Asserts multipart includes filename="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 with input_file completes.
  • Why this works

    • Providing a filename (or tuple with explicit content type) ensures correct MIME handling on the server.
    • Using input_file with input_text matches the Responses API input schema and avoids malformed content arrays.
  • How to run

    • Example:
      python examples/responses/file_input_pdf_streaming.py /path/to/document.pdf --prompt "Summarize this document."
    • Tests:
      pytest -k "multipart_pdf_upload or responses_file_input"
  • Backward compatibility

    • No breaking changes; adds example and tests only.
  • Closes

@oliviergodement oliviergodement requested a review from a team as a code owner August 7, 2025 21:57
@oliviergodement oliviergodement deleted the fix/file-upload-mime-streaming-example branch August 7, 2025 22:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Uploading PDF via Files API and using in Streaming gives 400 bad request

2 participants