Skip to content

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]

refactor: remove 'input_fidelity' from image gen -> it's a image_edit param

Krrish Dholakia7a083750ceb4
diff --git a/docs/my-website/docs/image_generation.md b/docs/my-website/docs/image_generation.md
index 60a6356f012..7e7ff9922d6 100644
--- a/docs/my-website/docs/image_generation.md
+++ b/docs/my-website/docs/image_generation.md
@@ -124,8 +124,6 @@ Any non-openai params, will be treated as provider-specific params, and sent in
- `size`: *string (optional)* The size of the generated images. Must be one of `1024x1024`, `1536x1024` (landscape), `1024x1536` (portrait), or `auto` (default value) for `gpt-image-1`, one of `256x256`, `512x512`, or `1024x1024` for `dall-e-2`, and one of `1024x1024`, `1792x1024`, or `1024x1792` for `dall-e-3`.
-- `input_fidelity`: *string (optional)* Controls how closely the model follows the input prompt. Supported for `gpt-image-1` model. Higher fidelity may improve prompt adherence but could affect generation speed.
-
- `timeout`: *integer* - The maximum time, in seconds, to wait for the API to respond. Defaults to 600 seconds (10 minutes).
- `user`: *string (optional)* A unique identifier representing your end-user,
diff --git a/docs/my-website/release_notes/v1.74.7/index.md b/docs/my-website/release_notes/v1.74.7/index.md
index e3a2ac0aa00..7d7a568e13f 100644
--- a/docs/my-website/release_notes/v1.74.7/index.md
+++ b/docs/my-website/release_notes/v1.74.7/index.md
@@ -148,7 +148,6 @@ Starting with this release, you can run health endpoints on an isolated process
- New provider integration for v0.dev - [PR #12751](https://github.com/BerriAI/litellm/pull/12751), [Get Started](../../docs/providers/v0)
- **[OpenAI](../../docs/providers/openai)**
- Use OpenAI DeepResearch models with `litellm.completion` (`/chat/completions`) - [PR #12627](https://github.com/BerriAI/litellm/pull/12627) **DOC NEEDED**
- - Add `input_fidelity` parameter for OpenAI image generation - [PR #12662](https://github.com/BerriAI/litellm/pull/12662), [Get Started](../../docs/image_generation)
- **[Azure OpenAI](../../docs/providers/azure_openai)**
- Use Azure OpenAI DeepResearch models with `litellm.completion` (`/chat/completions`) - [PR #12627](https://github.com/BerriAI/litellm/pull/12627) **DOC NEEDED**
- Added `response_format` support for openai gpt-4.1 models - [PR #12745](https://github.com/BerriAI/litellm/pull/12745)
diff --git a/litellm/llms/openai/image_generation/gpt_transformation.py b/litellm/llms/openai/image_generation/gpt_transformation.py
index 150cffba21c..1cee13784e7 100644
--- a/litellm/llms/openai/image_generation/gpt_transformation.py
+++ b/litellm/llms/openai/image_generation/gpt_transformation.py
@@ -16,7 +16,6 @@ class GPTImageGenerationConfig(BaseImageGenerationConfig):
) -> List[OpenAIImageGenerationOptionalParams]:
return [
"background",
- "input_fidelity",
"moderation",
"n",
"output_compression",
diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py
index 5b58c232964..a72651f35d5 100644
--- a/litellm/types/llms/openai.py
+++ b/litellm/types/llms/openai.py
@@ -914,7 +914,6 @@ OpenAIImageVariationOptionalParams = Literal["n", "size", "response_format", "us
OpenAIImageGenerationOptionalParams = Literal[
"background",
- "input_fidelity",
"moderation",
"n",
"output_compression",
diff --git a/litellm/utils.py b/litellm/utils.py
index 14d00cc528b..60716cb5c11 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -542,9 +542,9 @@ def function_setup( # noqa: PLR0915
function_id: Optional[str] = kwargs["id"] if "id" in kwargs else None
## DYNAMIC CALLBACKS ##
- dynamic_callbacks: Optional[
- List[Union[str, Callable, CustomLogger]]
- ] = kwargs.pop("callbacks", None)
+ dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = (
+ kwargs.pop("callbacks", None)
+ )
all_callbacks = get_dynamic_callbacks(dynamic_callbacks=dynamic_callbacks)
if len(all_callbacks) > 0:
@@ -1298,9 +1298,9 @@ def client(original_function): # noqa: PLR0915
exception=e,
retry_policy=kwargs.get("retry_policy"),
)
- kwargs[
- "retry_policy"
- ] = reset_retry_policy() # prevent infinite loops
+ kwargs["retry_policy"] = (
+ reset_retry_policy()
+ ) # prevent infinite loops
litellm.num_retries = (
None # set retries to None to prevent infinite loops
)
@@ -2508,7 +2508,6 @@ def get_optional_params_image_gen(
size: Optional[str] = None,
style: Optional[str] = None,
user: Optional[str] = None,
- input_fidelity: Optional[str] = None,
custom_llm_provider: Optional[str] = None,
additional_drop_params: Optional[list] = None,
provider_config: Optional[BaseImageGenerationConfig] = None,
@@ -2545,7 +2544,6 @@ def get_optional_params_image_gen(
"size": None,
"style": None,
"user": None,
- "input_fidelity": None,
}
non_default_params = _get_non_default_params(
@@ -3119,10 +3117,10 @@ def pre_process_non_default_params(
if "response_format" in non_default_params:
if provider_config is not None:
- non_default_params[
- "response_format"
- ] = provider_config.get_json_schema_from_pydantic_object(
- response_format=non_default_params["response_format"]
+ non_default_params["response_format"] = (
+ provider_config.get_json_schema_from_pydantic_object(
+ response_format=non_default_params["response_format"]
+ )
)
else:
non_default_params["response_format"] = type_to_response_format_param(
@@ -3250,16 +3248,16 @@ def pre_process_optional_params(
True # so that main.py adds the function call to the prompt
)
if "tools" in non_default_params:
- optional_params[
- "functions_unsupported_model"
- ] = non_default_params.pop("tools")
+ optional_params["functions_unsupported_model"] = (
+ non_default_params.pop("tools")
+ )
non_default_params.pop(
"tool_choice", None
) # causes ollama requests to hang
elif "functions" in non_default_params:
- optional_params[
- "functions_unsupported_model"
- ] = non_default_params.pop("functions")
+ optional_params["functions_unsupported_model"] = (
+ non_default_params.pop("functions")
+ )
elif (
litellm.add_function_to_prompt
): # if user opts to add it to prompt instead
@@ -4364,9 +4362,9 @@ def _count_characters(text: str) -> int:
def get_response_string(response_obj: Union[ModelResponse, ModelResponseStream]) -> str:
- _choices: Union[
- List[Union[Choices, StreamingChoices]], List[StreamingChoices]
- ] = response_obj.choices
+ _choices: Union[List[Union[Choices, StreamingChoices]], List[StreamingChoices]] = (
+ response_obj.choices
+ )
response_str = ""
for choice in _choices:
@@ -6891,6 +6889,7 @@ class ProviderConfigManager:
from litellm.llms.vertex_ai.vertex_ai_partner_models.gpt_oss.transformation import (
VertexAIGPTOSSTransformation,
)
+
return VertexAIGPTOSSTransformation()
elif model in litellm.vertex_mistral_models:
if "codestral" in model:
@@ -7310,7 +7309,7 @@ class ProviderConfigManager:
return BedrockFilesConfig()
return None
-
+
@staticmethod
def get_provider_batches_config(
model: str,
@@ -7318,6 +7317,7 @@ class ProviderConfigManager:
) -> Optional[BaseBatchesConfig]:
if LlmProviders.BEDROCK == provider:
from litellm.llms.bedrock.batches.transformation import BedrockBatchesConfig
+
return BedrockBatchesConfig()
return None
diff --git a/tests/image_gen_tests/test_image_generation.py b/tests/image_gen_tests/test_image_generation.py
index c761da6d16c..7a803daf5d1 100644
--- a/tests/image_gen_tests/test_image_generation.py
+++ b/tests/image_gen_tests/test_image_generation.py
@@ -147,13 +147,13 @@ class TestBedrockNovaCanvasColorGuidedGeneration(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
litellm.in_memory_llm_clients_cache = InMemoryCache()
return {
- "model": "bedrock/amazon.nova-canvas-v1:0",
- "n": 1,
- "size": "320x320",
- "imageGenerationConfig": {"cfgScale":6.5,"seed":12},
- "taskType": "COLOR_GUIDED_GENERATION",
- "colorGuidedGenerationParams":{"colors":["#FFFFFF"]},
- "aws_region_name": "us-east-1",
+ "model": "bedrock/amazon.nova-canvas-v1:0",
+ "n": 1,
+ "size": "320x320",
+ "imageGenerationConfig": {"cfgScale": 6.5, "seed": 12},
+ "taskType": "COLOR_GUIDED_GENERATION",
+ "colorGuidedGenerationParams": {"colors": ["#FFFFFF"]},
+ "aws_region_name": "us-east-1",
}
@@ -161,22 +161,27 @@ class TestOpenAIDalle3(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
return {"model": "dall-e-3"}
+
class TestOpenAIGPTImage1(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
return {"model": "gpt-image-1"}
+
class TestRecraftImageGeneration(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
return {"model": "recraft/recraftv3"}
+
class TestAimlImageGeneration(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
return {"model": "aiml/flux-pro/v1.1"}
+
class TestGoogleImageGen(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
return {"model": "gemini/imagen-4.0-generate-001"}
+
class TestAzureOpenAIDalle3(BaseImageGenTest):
def get_base_image_generation_call_args(self) -> dict:
litellm.set_verbose = True
@@ -191,7 +196,6 @@ class TestAzureOpenAIDalle3(BaseImageGenTest):
}
},
}
-
class TestAzureFoundryFlux(BaseImageGenTest):
@@ -268,117 +272,50 @@ async def test_aimage_generation_bedrock_with_optional_params():
pytest.fail(f"An exception occurred - {str(e)}")
-async def test_gpt_image_1_with_input_fidelity():
- """Test gpt-image-1 with input_fidelity parameter (mocked)"""
- from unittest.mock import AsyncMock, patch
-
- # Mock OpenAI response
- mock_openai_response = {
- "created": 1703658209,
- "data": [
- {
- "url": "https://example.com/generated_image.png"
- }
- ]
- }
-
- # Create a proper mock response object
- class MockResponse:
- def model_dump(self):
- return mock_openai_response
-
- # Create a mock client with the images.generate method
- mock_client = AsyncMock()
- mock_client.images.generate = AsyncMock(return_value=MockResponse())
-
- # Capture the actual arguments sent to OpenAI client
- captured_args = None
- captured_kwargs = None
-
- async def capture_generate_call(*args, **kwargs):
- nonlocal captured_args, captured_kwargs
- captured_args = args
- captured_kwargs = kwargs
- return MockResponse()
-
- mock_client.images.generate.side_effect = capture_generate_call
-
- # Mock the _get_openai_client method to return our mock client
- with patch.object(litellm.main.openai_chat_completions, '_get_openai_client', return_value=mock_client):
- response = await litellm.aimage_generation(
- prompt="A cute baby sea otter",
- model="gpt-image-1",
- input_fidelity="high",
- quality="medium",
- size="1024x1024",
- )
-
- # Validate the response
- assert response is not None
- assert response.created == 1703658209
- assert response.data is not None
- assert len(response.data) == 1
- assert response.data[0].url == "https://example.com/generated_image.png"
-
- # Validate that the OpenAI client was called with correct parameters
- mock_client.images.generate.assert_called_once()
- assert captured_kwargs is not None
- assert captured_kwargs["model"] == "gpt-image-1"
- assert captured_kwargs["prompt"] == "A cute baby sea otter"
- assert captured_kwargs["input_fidelity"] == "high"
- assert captured_kwargs["quality"] == "medium"
- assert captured_kwargs["size"] == "1024x1024"
-
-
@pytest.mark.asyncio
async def test_aiml_image_generation_with_dynamic_api_key():
"""
Test that when api_key is passed as a dynamic parameter to aimage_generation,
it gets properly used for AIML provider authentication instead of falling back
to environment variables.
-
+
This test validates the fix for ensuring dynamic API keys are respected
when making image generation requests to the AIML provider.
"""
from unittest.mock import AsyncMock, patch, MagicMock
import httpx
-
+
# Mock AIML response
mock_aiml_response = {
"created": 1703658209,
- "data": [
- {
- "url": "https://example.com/generated_image.png"
- }
- ]
+ "data": [{"url": "https://example.com/generated_image.png"}],
}
-
+
# Track captured arguments
captured_headers = None
captured_url = None
captured_json_data = None
-
+
def capture_post_call(*args, **kwargs):
nonlocal captured_headers, captured_url, captured_json_data
- captured_url = kwargs.get('url') or (args[0] if args else None)
- captured_headers = kwargs.get('headers', {})
- captured_json_data = kwargs.get('json', {})
-
+ captured_url = kwargs.get("url") or (args[0] if args else None)
+ captured_headers = kwargs.get("headers", {})
+ captured_json_data = kwargs.get("json", {})
+
# Create a mock response
mock_response = MagicMock()
mock_response.status_code = 200
mock_response.json.return_value = mock_aiml_response
mock_response.text = json.dumps(mock_aiml_response)
return mock_response
-
+
# Mock the HTTP client that actually makes the request (sync version for image generation)
- with patch('litellm.llms.custom_httpx.http_handler.HTTPHandler.post') as mock_post:
+ with patch("litellm.llms.custom_httpx.http_handler.HTTPHandler.post") as mock_post:
mock_post.side_effect = capture_post_call
-
+
# Test with dynamic api_key
test_api_key = "test-dynamic-api-key-12345"
-
+
response = await litellm.aimage_generation(
prompt="A cute baby sea otter",
model="aiml/flux-pro/v1.1",
@@ -387,7 +324,7 @@ async def test_aiml_image_generation_with_dynamic_api_key():
# Validate the response (mocked response processing might not populate data correctly)
assert response is not None
-
+
# The most important validations: API key and endpoint usage
# These prove that the dynamic API key was properly used
assert captured_headers is not None
@@ -398,10 +335,8 @@ async def test_aiml_image_generation_with_dynamic_api_key():
assert captured_url is not None
assert "api.aimlapi.com" in captured_url
assert "/v1/images/generations" in captured_url
-
+
# Validate the request data
assert captured_json_data is not None
assert captured_json_data["prompt"] == "A cute baby sea otter"
assert captured_json_data["model"] == "flux-pro/v1.1"
-
-