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
test(e2e): cover /v1/images/edits (#34476)
mubashir1osmania11383de3430
diff --git a/tests/e2e/coverage_registry/llm_nonconversational.yaml b/tests/e2e/coverage_registry/llm_nonconversational.yamlindex 63e6fde14a3..1e49cb13538 100644--- a/tests/e2e/coverage_registry/llm_nonconversational.yaml+++ b/tests/e2e/coverage_registry/llm_nonconversational.yaml@@ -36,6 +36,7 @@- {id: llm.rerank.bedrock.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: rerank, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "llms/bedrock/rerank/handler.py", rationale: "Bedrock rerank"}- {id: llm.rerank.together_ai.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: rerank, route: together_ai, capability: basic, streaming: nonstream, assertions: [works], source: "llms/together_ai/rerank/handler.py", rationale: "Together rerank"}- {id: llm.images_generations.openai.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: images_generations, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "test_image_generation_e2e.py:22", rationale: "OpenAI image gen, b64/url"}+- {id: llm.images_edits.openai.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: images_edits, route: openai, capability: basic, streaming: nonstream, assertions: [works], source: "test_image_edits_e2e.py", rationale: "OpenAI /v1/images/edits (multipart image+prompt), distinct native route from image generation (LIT-4753)"}- {id: llm.images_generations.azure_openai.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: images_generations, route: azure_openai, capability: basic, streaming: nonstream, assertions: [works], source: "llms/azure/azure.py", rationale: "Azure DALL-E"}- {id: llm.images_generations.vertex.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: images_generations, route: vertex, capability: basic, streaming: nonstream, assertions: [works], source: "vertex_ai/image_generation/image_generation_handler.py", rationale: "Vertex Imagen"}- {id: llm.images_generations.bedrock.basic.nonstream.works, module: llm, tier: P1, subject_endpoint: images_generations, route: bedrock_converse, capability: basic, streaming: nonstream, assertions: [works], source: "bedrock/image_generation/image_handler.py", rationale: "Bedrock Titan Image"}diff --git a/tests/e2e/coverage_registry/schema.py b/tests/e2e/coverage_registry/schema.pyindex 1a6dc111e2b..89f5df73a4f 100644--- a/tests/e2e/coverage_registry/schema.py+++ b/tests/e2e/coverage_registry/schema.py@@ -34,6 +34,7 @@ LlmEndpoint = Literal["files","rerank","images_generations",+ "images_edits","audio_speech","audio_transcriptions","moderations",diff --git a/tests/e2e/e2e_http.py b/tests/e2e/e2e_http.pyindex 03d7b5d051a..d16e84bd754 100644--- a/tests/e2e/e2e_http.py+++ b/tests/e2e/e2e_http.py@@ -480,14 +480,15 @@ def upload[R: BaseModel](filename: str,content: bytes,file_content_type: str = "application/jsonl",+ file_field: str = "file",params: BaseModel | None = None,response_type: type[R],timeout: float = 60.0,) -> Result[R]:- """Multipart POST for file-bearing routes (/v1/files, /v1/audio/transcriptions).- Form fields come from `form`, the file bytes are sent as the `file` part with- `file_content_type`, and `params` carries any query routing (e.g. ?model=).- requests sets the multipart Content-Type itself."""+ """Multipart POST for file-bearing routes (/v1/files, /v1/audio/transcriptions,+ /v1/images/edits). Form fields come from `form`, the file bytes are sent as the+ `file_field` part with `file_content_type`, and `params` carries any query+ routing (e.g. ?model=). requests sets the multipart Content-Type itself."""dumped: dict[str, object] = form.model_dump(by_alias=True, exclude_none=True)data = {key: str(value) for key, value in dumped.items()}try:@@ -496,7 +497,7 @@ def upload[R: BaseModel](headers=_headers(headers),params=_params(params),data=data,- files={"file": (filename, content, file_content_type)},+ files={file_field: (filename, content, file_content_type)},timeout=timeout,)except requests.RequestException as exc:diff --git a/tests/e2e/llm_translation/endpoints_client.py b/tests/e2e/llm_translation/endpoints_client.pyindex ace621d03b3..ba201cbb5c0 100644--- a/tests/e2e/llm_translation/endpoints_client.py+++ b/tests/e2e/llm_translation/endpoints_client.py@@ -223,6 +223,12 @@ class ImagesResult(BaseModel):data: list[ImageItem] = []+class ImageEditForm(BaseModel):+ model: str+ prompt: str+ n: int = 1++class TranscriptionResult(BaseModel):text: str = ""@@ -380,6 +386,20 @@ class EndpointsClient:"/v1/images/generations", key, ImageRequest(model=model, prompt=prompt))+ def image_edit(+ self, key: str, model: str, prompt: str, image: bytes, *, filename: str = "image.png"+ ) -> Result[ImagesResult]:+ return self.proxy.transport.upload(+ "/v1/images/edits",+ headers=self.proxy.transport.bearer(key),+ form=ImageEditForm(model=model, prompt=prompt),+ filename=filename,+ content=image,+ file_content_type="image/png",+ file_field="image",+ response_type=ImagesResult,+ )+def build_endpoints_client(proxy: ProxyClient) -> EndpointsClient:return EndpointsClient(proxy=proxy)diff --git a/tests/e2e/llm_translation/test_image_edits_e2e.py b/tests/e2e/llm_translation/test_image_edits_e2e.pynew file mode 100644index 00000000000..faad8703e74--- /dev/null+++ b/tests/e2e/llm_translation/test_image_edits_e2e.py@@ -0,0 +1,54 @@+"""Live e2e: POST /v1/images/edits returns an edited image.++Registers an OpenAI image model, then sends a small PNG plus an edit prompt as a+multipart request to /v1/images/edits and asserts the response carries an image+(url or base64). /images/edits is a distinct native route from+/images/generations: it is multipart file upload with the image sent as the+`image` part, not a JSON body. The fixture image is a small generated 64x64 PNG,+so no external asset is needed.+"""++from __future__ import annotations++import base64++import pytest++from e2e_config import unique_marker+from e2e_http import unwrap+from endpoints_client import EndpointsClient+from lifecycle import ResourceManager+from models import LiteLLMParamsBody++pytestmark = pytest.mark.e2e++_TEST_PNG = base64.b64decode(+ "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAIAAAAlC+aJAAAAS0lEQVR42u3PMQ0AAAwDoPo3"+ "3UrYvQQckD4XAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB"+ "AYHLAMpT0sIcNbcEAAAAAElFTkSuQmCC"+)+++class TestImageEdit:+ @pytest.mark.covers("llm.images_edits.openai.basic.nonstream.works")+ def test_image_edit_returns_image(+ self, endpoints_client: EndpointsClient, resources: ResourceManager+ ) -> None:+ model = f"e2e-image-edit-{unique_marker()}"+ model_id = endpoints_client.create_model(+ model,+ LiteLLMParamsBody(model="openai/gpt-image-1", api_key="os.environ/OPENAI_API_KEY"),+ )+ resources.defer(lambda: endpoints_client.delete_model(model_id))+ key = resources.key()++ edited = unwrap(+ endpoints_client.image_edit(+ key, model, "Add a small red circle in the center", _TEST_PNG+ )+ )+ assert edited.data, f"/images/edits returned no data: {edited}"+ first = edited.data[0]+ assert first.b64_json or first.url, (+ f"edited image has neither b64_json nor url: {first}"+ )diff --git a/tests/e2e/transport.py b/tests/e2e/transport.pyindex da4252e550e..a6adf83ed1f 100644--- a/tests/e2e/transport.py+++ b/tests/e2e/transport.py@@ -89,6 +89,7 @@ class Transport(Protocol):filename: str,content: bytes,file_content_type: str = "application/jsonl",+ file_field: str = "file",params: BaseModel | None = None,response_type: type[R],) -> Result[R]: ...@@ -242,6 +243,7 @@ class HttpTransport:filename: str,content: bytes,file_content_type: str = "application/jsonl",+ file_field: str = "file",params: BaseModel | None = None,response_type: type[R],) -> Result[R]:@@ -252,6 +254,7 @@ class HttpTransport:filename=filename,content=content,file_content_type=file_content_type,+ file_field=file_field,params=params,response_type=response_type,timeout=self.request_timeout,@@ -411,6 +414,7 @@ class SplitTransport:filename: str,content: bytes,file_content_type: str = "application/jsonl",+ file_field: str = "file",params: BaseModel | None = None,response_type: type[R],) -> Result[R]:@@ -421,6 +425,7 @@ class SplitTransport:filename=filename,content=content,file_content_type=file_content_type,+ file_field=file_field,params=params,response_type=response_type,)