From 1a5590e84a5ff396b3f08e47dbd672882a240b22 Mon Sep 17 00:00:00 2001 From: Dev Sharma <12devsharma10c@gmail.com> Date: Thu, 31 Jul 2025 12:38:38 +0530 Subject: [PATCH] fix: support Files API references (PDFs) in streaming Responses API calls (#2472) ### Summary Fixes #2472 by normalizing Files API references when using uploaded files (e.g., PDFs) in streaming Responses API calls. ### Changes - Added normalization for `input` to convert file objects into `file_id` references. - Ensures PDFs and other file types uploaded via Files API work in streaming calls. ### Why The API expects file references (`file_id`), but the SDK previously sent full file objects, causing 400 Bad Request errors. --- src/openai/resources/responses/responses.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/openai/resources/responses/responses.py b/src/openai/resources/responses/responses.py index 8de46dbab8..7e42139dd0 100644 --- a/src/openai/resources/responses/responses.py +++ b/src/openai/resources/responses/responses.py @@ -740,8 +740,18 @@ def create( timeout: Override the client-level default timeout for this request, in seconds """ ... - - def create( + + inputs = kwargs.get("input", []) + +# Normalize file references (Edge case: PDF + streaming) +for item in inputs: + if isinstance(item, dict) and "file" in item: + # If using Files API, replace raw file dict with file_id reference + file_obj = item.pop("file") + if isinstance(file_obj, dict) and "id" in file_obj: + item["file_id"] = file_obj["id"] + + def create( self, *, background: Optional[bool] | NotGiven = NOT_GIVEN,