This commit is contained in:
Zsanz3 2026-09-12 14:53:42 -04:00 committed by GitHub
commit 65853c9ea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 2 deletions

View file

@ -64,6 +64,9 @@ from litellm.utils import (
# Cache for ImageEditRequestUtils to avoid repeated __getattr__ calls
_ImageEditRequestUtils_cache: Optional["ImageEditRequestUtils"] = None
# Kept out of all_litellm_params because that list is stripped before drop_params is applied.
_IMAGE_EDIT_CONTROL_KWARGS: Final = frozenset(("drop_params", "additional_drop_params"))
def _get_ImageEditRequestUtils() -> "ImageEditRequestUtils":
"""Get ImageEditRequestUtils, loading it lazily if needed."""
@ -759,8 +762,8 @@ def image_edit(
litellm_params_list: Final = all_litellm_params
default_params: Final = openai_params + litellm_params_list
non_default_params: Final = {
k: v for k, v in kwargs.items() if k not in default_params
} # model-specific params - pass them straight to the model/provider
k: v for k, v in kwargs.items() if k not in default_params and k not in _IMAGE_EDIT_CONTROL_KWARGS
}
litellm_logging_obj: Final[LiteLLMLoggingObj] = kwargs.get("litellm_logging_obj")
litellm_call_id: Final[str | None] = kwargs.get("litellm_call_id", None)
model_info: Final = kwargs.get("model_info", None)

View file

@ -121,6 +121,35 @@ def test_image_edit_forwards_scalar_array_as_repeated_fields():
assert b"style_a" in body and b"style_b" in body and b"style_c" in body
@pytest.mark.parametrize("drop_params", [True, False])
def test_image_edit_strips_per_model_drop_params_from_multipart(drop_params):
"""Per-model drop_params / additional_drop_params are LiteLLM control
flags. If they survive into non_default_params they are flattened onto the
OpenAI images/edits multipart body and the provider rejects the call with
Unknown parameter: 'drop_params'. Issue #40153."""
captured = {}
client = HTTPHandler(client=httpx.Client(transport=httpx.MockTransport(_capture_image_edit_request(captured))))
litellm.image_edit(
model="openai/gpt-image-1",
image=PNG_BYTES,
prompt="Make the background blue",
api_key="sk-test",
api_base="https://edit.example/v1",
client=client,
seed=42,
drop_params=drop_params,
additional_drop_params=["quality_level"],
)
fields = _multipart_text_fields(captured["content_type"], captured["body"])
assert "drop_params" not in fields
assert "additional_drop_params" not in fields
assert fields["seed"] == "42"
assert fields["prompt"] == "Make the background blue"
assert fields["model"] == "gpt-image-1"
@pytest.mark.asyncio
async def test_aimage_edit_forwards_extra_body():
"""aimage_edit used to drop extra_headers/extra_query/extra_body when