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
fix(images): forward gpt-image supported params like background to OpenAI and Azure
Devin AIe1b2d9de3c85
diff --git a/litellm/types/utils.py b/litellm/types/utils.pyindex 569fce4f7b8..0bdbb83fbb4 100644--- a/litellm/types/utils.py+++ b/litellm/types/utils.py@@ -2543,6 +2543,7 @@ class ImageResponse(OpenAIImageResponse, BaseLiteLLMOpenAIResponseObject):)super().__init__(created=created, data=_data, usage=_usage)+ self.background = kwargs.get("background", None)self.quality = kwargs.get("quality", None)self.output_format = kwargs.get("output_format", None)self.size = kwargs.get("size", None)diff --git a/litellm/utils.py b/litellm/utils.pyindex ba456fc353b..239673a20d9 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -3338,6 +3338,9 @@ def get_optional_params_image_gen(continuepassed_params[k] = v+ provider_supported_params: Final[tuple[str, ...]] = (+ tuple(provider_config.get_supported_openai_params(model=model or "")) if provider_config is not None else ()+ )default_params: Final = {"n": None,"quality": None,@@ -3348,6 +3351,7 @@ def get_optional_params_image_gen("imageConfig": None,"tools": None,"web_search_options": None,+ **{k: None for k in provider_supported_params},}non_default_params: Final = _get_non_default_params(@@ -3407,10 +3411,9 @@ def get_optional_params_image_gen(if size is not None:optional_params["aspectRatio"] = _map_openai_size_to_vertex_ai_aspect_ratio(size)- openai_params: list[str] = list(default_params.keys())- if provider_config is not None:- supported_params = provider_config.get_supported_openai_params(model=model or "")- openai_params = list(supported_params)+ openai_params: Final[list[str]] = (+ list(provider_supported_params) if provider_config is not None else list(default_params.keys())+ )optional_params = add_provider_specific_params_to_optional_params(optional_params=optional_params,diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 200cfd02197..99c69d6bc31 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -330,6 +330,37 @@ def test_get_optional_params_image_gen():assert optional_params["n"] == 3[email protected]("custom_llm_provider", ["openai", "azure"])+def test_get_optional_params_image_gen_keeps_gpt_image_supported_params(custom_llm_provider):+ """https://github.com/BerriAI/litellm/issues/38649"""+ from litellm.types.utils import LlmProviders++ provider_config = ProviderConfigManager.get_provider_image_generation_config(+ model="gpt-image-2", provider=LlmProviders(custom_llm_provider)+ )+ optional_params = get_optional_params_image_gen(+ model="gpt-image-2",+ n=1,+ size="1024x1024",+ custom_llm_provider=custom_llm_provider,+ provider_config=provider_config,+ background="transparent",+ output_format="png",+ moderation="low",+ output_compression=50,+ unknown_param="kept-in-extra-body",+ )+ assert optional_params == {+ "n": 1,+ "size": "1024x1024",+ "background": "transparent",+ "output_format": "png",+ "moderation": "low",+ "output_compression": 50,+ "extra_body": {"unknown_param": "kept-in-extra-body"},+ }++def test_get_optional_params_image_gen_vertex_ai_size():"""Test that Vertex AI image generation properly handles size parameter and maps it to aspectRatio"""# Test with various size parametersdiff --git a/tests/test_litellm/types/test_types_utils.py b/tests/test_litellm/types/test_types_utils.pyindex c081b9e8e0d..554604ab200 100644--- a/tests/test_litellm/types/test_types_utils.py+++ b/tests/test_litellm/types/test_types_utils.py@@ -759,3 +759,12 @@ def test_delta_function_tool_call_unchanged_by_custom_support():delta = Delta(tool_calls=[{"index": 0, "id": "c2", "type": "function", "function": {"name": "g", "arguments": ""}}])assert isinstance(delta.tool_calls[0], ChatCompletionDeltaToolCall)assert "custom" not in delta.model_dump()["tool_calls"][0]+++def test_image_response_keeps_background():+ """https://github.com/BerriAI/litellm/issues/38649"""+ from litellm.types.utils import ImageResponse++ response = ImageResponse(created=1, data=[{"b64_json": "aGk="}], background="transparent", output_format="png")+ assert response.background == "transparent"+ assert response.model_dump()["background"] == "transparent"