The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
feat(images): support input_fidelity parameter for image edit API
Chesars2ea2660ba530
diff --git a/litellm/llms/openai/image_edit/transformation.py b/litellm/llms/openai/image_edit/transformation.pyindex a1e5375d098..a92a89eac65 100644--- a/litellm/llms/openai/image_edit/transformation.py+++ b/litellm/llms/openai/image_edit/transformation.py@@ -40,6 +40,7 @@ class OpenAIImageEditConfig(BaseImageEditConfig):"image","prompt","background",+ "input_fidelity","mask","model","n",diff --git a/litellm/types/images/main.py b/litellm/types/images/main.pyindex 3002f9bffb4..819f4954589 100644--- a/litellm/types/images/main.py+++ b/litellm/types/images/main.py@@ -13,6 +13,7 @@ class ImageEditOptionalRequestParams(TypedDict, total=False):"""background: Optional[Literal["transparent", "opaque", "auto"]]+ input_fidelity: Optional[Literal["high", "low"]]mask: Optional[str]n: Optional[int]quality: Optional[Literal["high", "medium", "low", "standard", "auto"]]diff --git a/tests/test_litellm/llms/openai/test_openai_image_edit_transformation.py b/tests/test_litellm/llms/openai/test_openai_image_edit_transformation.pyindex cd5e297a774..f884f745a06 100644--- a/tests/test_litellm/llms/openai/test_openai_image_edit_transformation.py+++ b/tests/test_litellm/llms/openai/test_openai_image_edit_transformation.py@@ -4,6 +4,7 @@ from typing import Dictimport pytestfrom litellm import image_edit+from litellm.images.utils import ImageEditRequestUtilsfrom litellm.llms.openai.image_edit.transformation import OpenAIImageEditConfigfrom litellm.types.router import GenericLiteLLMParams@@ -254,3 +255,50 @@ def test_transform_image_edit_request_with_mask_list(image_edit_config: OpenAIImmask_file = next(f for f in files if f[0] == "mask")assert mask_file[1][1] == mask1 # Should be the first mask, not the second++def test_transform_image_edit_request_with_input_fidelity(+ image_edit_config: OpenAIImageEditConfig,+):+ """Test that input_fidelity is included in the data dict when provided"""+ model = "gpt-image-1"+ prompt = "Make the background blue"+ image = b"fake_image_data"+ image_edit_optional_request_params = {"input_fidelity": "high"}+ litellm_params = GenericLiteLLMParams()+ headers = {}++ data, files = image_edit_config.transform_image_edit_request(+ model=model,+ prompt=prompt,+ image=image,+ image_edit_optional_request_params=image_edit_optional_request_params,+ litellm_params=litellm_params,+ headers=headers,+ )++ assert data["input_fidelity"] == "high"+ assert data["model"] == model+ assert data["prompt"] == prompt+ assert "image" not in data+++def test_get_supported_openai_params_includes_input_fidelity(+ image_edit_config: OpenAIImageEditConfig,+):+ """Test that input_fidelity is in the supported params list"""+ supported = image_edit_config.get_supported_openai_params(model="gpt-image-1")+ assert "input_fidelity" in supported+++def test_input_fidelity_passes_through_optional_param_filter():+ """Test that input_fidelity is not dropped by get_requested_image_edit_optional_param"""+ params = {+ "input_fidelity": "low",+ "quality": "high",+ "unknown_param": "should_be_dropped",+ }+ filtered = ImageEditRequestUtils.get_requested_image_edit_optional_param(params)+ assert filtered["input_fidelity"] == "low"+ assert filtered["quality"] == "high"+ assert "unknown_param" not in filtered+