From c1d02c68665050f38e48661f70829ee23aa219b6 Mon Sep 17 00:00:00 2001 From: Mrun25 <165297479+Mrun25@users.noreply.github.com> Date: Fri, 16 Oct 2026 10:10:42 +0530 Subject: [PATCH] fix(bfl): normalize image=None in aimage_edit so BFL surfaces a clean 400 The sync image_edit normalizes image=None to [], but aimage_edit built [None], crashing the Black Forest Labs handler with APIConnectionError ("Unsupported image type: ") instead of the expected 400. Mirror the sync normalization and add a regression test. Fixes #46835 --- litellm/images/main.py | 4 ++-- .../test_bfl_image_edit_transformation.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/litellm/images/main.py b/litellm/images/main.py index be32ea4daed..a994bddd9cb 100644 --- a/litellm/images/main.py +++ b/litellm/images/main.py @@ -981,7 +981,7 @@ def image_edit( @client async def aimage_edit( - image: FileTypes | list[FileTypes], + image: FileTypes | list[FileTypes] | None, model: str, prompt: str, mask: str | None = None, @@ -1021,7 +1021,7 @@ async def aimage_edit( model=model, api_base=local_vars.get("base_url", None) ) - images: Final = image if isinstance(image, list) else [image] + images: Final = image if isinstance(image, list) else ([image] if image is not None else []) func: Final = partial( image_edit, diff --git a/tests/unit/llms/black_forest_labs/image_edit/test_bfl_image_edit_transformation.py b/tests/unit/llms/black_forest_labs/image_edit/test_bfl_image_edit_transformation.py index d9d6e813d86..2668db64f9c 100644 --- a/tests/unit/llms/black_forest_labs/image_edit/test_bfl_image_edit_transformation.py +++ b/tests/unit/llms/black_forest_labs/image_edit/test_bfl_image_edit_transformation.py @@ -375,3 +375,22 @@ async def test_async_transform_image_edit_request_downloads_only_the_first_url_o assert fetched == ["https://cdn.example/a.png"] assert base64.b64decode(data["input_image"]) == b"first-bytes" + + +async def test_aimage_edit_none_image_raises_bad_request(monkeypatch): + """aimage_edit with image=None must surface a clean 400, not an APIConnectionError. + + Regression test: the sync `image_edit` normalizes ``image=None`` to ``[]`` while + `aimage_edit` used to build ``[None]``, which crashed the BFL handler with + "Unsupported image type: ". + """ + import litellm + + monkeypatch.setenv("BFL_API_KEY", "test-key") + + with pytest.raises(litellm.BadRequestError, match="No image provided"): + await litellm.aimage_edit( + model="black_forest_labs/flux-kontext-pro", + prompt="make it blue", + image=None, + )