From bca40a7e905351cadbd02e875e82f8f28d43d218 Mon Sep 17 00:00:00 2001 From: S3rj <31356555+Serjbory@users.noreply.github.com> Date: Wed, 22 Apr 2026 00:29:00 +0200 Subject: [PATCH] =?UTF-8?q?Python:=20fix:=20exclude=20null=20file=5Fid=20f?= =?UTF-8?q?rom=20input=5Fimage=20payload=20to=20prevent=20400=20sch?= =?UTF-8?q?=E2=80=A6=20(#5125)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: exclude null file_id from input_image payload to prevent 400 schema error (#5120) * test: add case for additional_properties present without file_id key --------- Co-authored-by: Sergey Borisov --- .../openai/agent_framework_openai/_chat_client.py | 2 +- .../openai/tests/openai/test_openai_chat_client.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/python/packages/openai/agent_framework_openai/_chat_client.py b/python/packages/openai/agent_framework_openai/_chat_client.py index 5b7584dc6d..9da2ab354e 100644 --- a/python/packages/openai/agent_framework_openai/_chat_client.py +++ b/python/packages/openai/agent_framework_openai/_chat_client.py @@ -1405,7 +1405,7 @@ class RawOpenAIChatClient( # type: ignore[misc] else "auto", } file_id = content.additional_properties.get("file_id") if content.additional_properties else None - if file_id: + if file_id is not None: result["file_id"] = file_id return result if content.has_top_level_media_type("audio"): diff --git a/python/packages/openai/tests/openai/test_openai_chat_client.py b/python/packages/openai/tests/openai/test_openai_chat_client.py index 8c956a6339..e6b93b19c3 100644 --- a/python/packages/openai/tests/openai/test_openai_chat_client.py +++ b/python/packages/openai/tests/openai/test_openai_chat_client.py @@ -2975,6 +2975,17 @@ def test_prepare_content_for_openai_image_content() -> None: assert result["detail"] == "auto" assert "file_id" not in result + # Test image content with additional_properties present but no file_id key + image_content_detail_only = Content.from_uri( + uri="https://example.com/basic.png", + media_type="image/png", + additional_properties={"detail": "high"}, + ) + result = client._prepare_content_for_openai("user", image_content_detail_only) + assert result["type"] == "input_image" + assert result["detail"] == "high" + assert "file_id" not in result + def test_prepare_content_for_openai_audio_content() -> None: """Test _prepare_content_for_openai with audio content variations."""