fix(images): forward image_config on OpenRouter image edits

image_config was honored on OpenRouter image generation but silently dropped on image edits.
The default edit branch in image_edit() never merged non_default_params (which still carries
image_config after the optional-param whitelist filters it out) before calling the handler,
unlike the bedrock, stability, and black_forest_labs branches. Merge non_default_params for the
openrouter path so image_config survives; OpenRouter's transform already forwards extra
top-level params into the chat-completions body, so it then reaches the provider

Fixes #30753
This commit is contained in:
Ewerton Silva 2026-06-18 21:15:37 -03:00
parent e4a53f50de
commit f9fa377215
2 changed files with 56 additions and 0 deletions

View file

@ -963,6 +963,8 @@ def image_edit(
client=kwargs.get("client"),
aimage_edit=_is_async,
)
if custom_llm_provider == "openrouter":
image_edit_request_params.update(non_default_params)
# Call the handler with _is_async flag instead of directly calling the async handler
return base_llm_http_handler.image_edit_handler(
model=model,

View file

@ -269,6 +269,60 @@ class TestImageEditCustomPricing:
assert use_custom_pricing_for_model(litellm_params) is False
class TestImageEditOpenRouterImageConfig:
"""
Regression test for https://github.com/BerriAI/litellm/issues/30753
image_config is honored on OpenRouter image generation but was silently dropped on
image edits: the default edit path never merged non_default_params (which still carries
image_config) before calling the handler, unlike the bedrock/stability/black_forest_labs
branches. OpenRouter's transform forwards extra top-level params, so once image_config
survives the merge it reaches the provider.
"""
def test_openrouter_image_edit_forwards_image_config(self):
from litellm.images.main import image_edit
image_config = {"aspect_ratio": "16:9", "image_size": "2K"}
with (
patch(
"litellm.images.main.get_llm_provider",
return_value=(
"google/gemini-3-pro-image-preview",
"openrouter",
None,
None,
),
),
patch(
"litellm.images.main.ProviderConfigManager.get_provider_image_edit_config",
return_value=MagicMock(),
),
patch(
"litellm.images.main._get_ImageEditRequestUtils",
return_value=MagicMock(
get_requested_image_edit_optional_param=MagicMock(return_value={}),
get_optional_params_image_edit=MagicMock(return_value={}),
),
),
patch("litellm.images.main.base_llm_http_handler") as mock_handler,
):
mock_handler.image_edit_handler.return_value = MagicMock()
image_edit(
image=b"fake-image-data",
prompt="add a red border",
model="openrouter/google/gemini-3-pro-image-preview",
image_config=image_config,
)
forwarded = mock_handler.image_edit_handler.call_args.kwargs[
"image_edit_optional_request_params"
]
assert forwarded.get("image_config") == image_config
class TestImageEditHandlerCredentialsForwarding:
"""
Regression tests for Vertex AI image_edit credentials bug.