Python: fix: exclude null file_id from input_image payload to prevent 400 sch… (#5125)

* 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 <sergey.borisov@dataimpact.io>
This commit is contained in:
S3rj
2026-04-22 00:29:00 +02:00
committed by GitHub
Unverified
parent f2b215a2f6
commit bca40a7e90
2 changed files with 12 additions and 1 deletions
@@ -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"):
@@ -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."""