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 @@ def _prepare_content_for_openai( 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."""