Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions litellm/llms/azure_ai/image_edit/flux2_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ class AzureFoundryFlux2ImageEditConfig(OpenAIImageEditConfig):
"""

def get_supported_openai_params(self, model: str) -> list:
"""
FLUX 2 supports a subset of OpenAI image edit params
"""
return [
"prompt",
"image",
"model",
"n",
"size",
"width",
"height",
Comment on lines +35 to +36

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Direct dimensions are filtered out

When callers pass the newly supported width and height parameters through the public image_edit API, the shared request filter removes them because ImageEditOptionalRequestParams does not define those keys, causing the provider request to omit the requested dimensions and use its default size.

Knowledge Base Used: LLM Provider Adapters

]

def map_openai_params(
Expand All @@ -43,15 +42,17 @@ def map_openai_params(
model: str,
drop_params: bool,
) -> dict:
"""
Map OpenAI params to FLUX 2 params.
FLUX 2 uses the same param names as OpenAI for supported params.
"""
mapped_params: Final[dict[str, Any]] = {}
supported_params: Final = self.get_supported_openai_params(model)

for key, value in dict(image_edit_optional_params).items():
if key in supported_params and value is not None:
if key not in supported_params or value is None:
continue
if key == "size" and isinstance(value, str) and "x" in value:
w, h = value.lower().split("x", 1)
mapped_params["width"] = int(w)
mapped_params["height"] = int(h)
Comment on lines +53 to +54

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Dimension mapping mutates final state

The new assignments incrementally mutate the Final dictionary, contrary to the repository's immutability convention and making the mapping logic dependent on mutation order; construct the mapped dimensions without mutating local state.

Context Used: CLAUDE.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

elif key != "size":
mapped_params[key] = value

return mapped_params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
0, os.path.abspath("../../../../..")
) # Adds the parent directory to the system path

from litellm.llms.azure_ai.image_edit.flux2_transformation import (
AzureFoundryFlux2ImageEditConfig,
)
from litellm.llms.azure_ai.image_edit.transformation import (
AzureFoundryFluxImageEditConfig,
)
Expand Down Expand Up @@ -32,3 +35,24 @@ def test_azure_ai_url_generation():
)
expected_url = f"{api_base}/openai/deployments/FLUX.1-Kontext-pro/images/edits?api-version=2025-04-01-preview"
assert complete_url == expected_url


def test_flux2_size_param_translates_to_width_height():
config = AzureFoundryFlux2ImageEditConfig()
result = config.map_openai_params(
image_edit_optional_params={"size": "896x1184"},
model="flux.2-pro",
drop_params=False,
)
assert result == {"width": 896, "height": 1184}
assert "size" not in result


def test_flux2_explicit_width_height_pass_through():
config = AzureFoundryFlux2ImageEditConfig()
result = config.map_openai_params(
image_edit_optional_params={"width": 512, "height": 512},
model="flux.2-pro",
drop_params=False,
)
assert result == {"width": 512, "height": 512}
Loading