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: support image_edit health checks
Devin AI5c8852c0d671
diff --git a/litellm/litellm_core_utils/health_check_helpers.py b/litellm/litellm_core_utils/health_check_helpers.pyindex 3a79eb78b17..43b2eca2fd5 100644--- a/litellm/litellm_core_utils/health_check_helpers.py+++ b/litellm/litellm_core_utils/health_check_helpers.py@@ -2,6 +2,7 @@Helper functions for health check calls."""+import base64from collections.abc import Callablefrom typing import TYPE_CHECKING, Final, Literal@@ -13,6 +14,14 @@ if TYPE_CHECKING:# Minimal PDF for health checks - base64 encoded 1-page PDF with just "test"TEST_PDF_URL = "data:application/pdf;base64,JVBERi0xLjQKJeLjz9MKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL01lZGlhQm94IFswIDAgNjEyIDc5Ml0KL0NvbnRlbnRzIDQgMCBSCi9SZXNvdXJjZXMgPDwvRm9udCA8PC9GMSAyIDAgUj4+Pj4+PgplbmRvYmoKNCAwIG9iago8PC9MZW5ndGggNDQ+PgpzdHJlYW0KQlQKL0YxIDI0IFRmCjEwMCA3MDAgVGQKKHRlc3QpIFRqCkVUCmVuZHN0cmVhbQplbmRvYmoKMiAwIG9iago8PC9UeXBlIC9Gb250Ci9TdWJ0eXBlIC9UeXBlMQovQmFzZUZvbnQgL0hlbHZldGljYT4+CmVuZG9iagoxIDAgb2JqCjw8L1R5cGUgL1BhZ2VzCi9LaWRzIFszIDAgUl0KL0NvdW50IDE+PgplbmRvYmoKNSAwIG9iago8PC9UeXBlIC9DYXRhbG9nCi9QYWdlcyAxIDAgUj4+CmVuZG9iagp0cmFpbGVyCjw8L1NpemUgNgovUm9vdCA1IDAgUj4+CnN0YXJ0eHJlZgozMjQKJSVFT0Y="+# Minimal image for health checks - base64 encoded 512x512 solid-gray PNG+TEST_IMAGE_BASE64 = "iVBORw0KGgoAAAANSUhEUgAAAgAAAAIACAIAAAB7GkOtAAAFlklEQVR42u3VMQEAAAzCMKQjHQ97l0jo0xSAlyIBgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGACAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGACAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGACAAUgAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGACAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGACAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgBgAAAYAAAGAIABAGAAABgAAAYAgAEAYAAAGAAABgCAAQBgAAAYAAAGAIABAGAAABgAADcDrctaAb6XeXAAAAAASUVORK5CYII="+++def get_image_file_for_health_check() -> bytes:+ """Return the image used for health checks."""+ return base64.b64decode(TEST_IMAGE_BASE64)+class HealthCheckHelpers:@staticmethod@@ -127,6 +136,7 @@ class HealthCheckHelpers:"audio_speech","audio_transcription","image_generation",+ "image_edit","video_generation","rerank","realtime",@@ -185,6 +195,11 @@ class HealthCheckHelpers:**_filter_model_params(model_params=model_params),prompt=prompt,),+ "image_edit": lambda: litellm.aimage_edit(+ **_filter_model_params(model_params=model_params),+ image=get_image_file_for_health_check(),+ prompt=prompt or "test",+ ),"video_generation": lambda: litellm.avideo_generation(**_filter_model_params(model_params=model_params),prompt=prompt or "test video generation",diff --git a/tests/test_litellm/litellm_core_utils/test_health_check_helpers.py b/tests/test_litellm/litellm_core_utils/test_health_check_helpers.pyindex 8f4799e3e7d..c2e2f92ad8a 100644--- a/tests/test_litellm/litellm_core_utils/test_health_check_helpers.py+++ b/tests/test_litellm/litellm_core_utils/test_health_check_helpers.py@@ -12,6 +12,55 @@ from litellm.proxy._types import UserAPIKeyAuthfrom litellm.types.utils import LIST_BATCHES_SUPPORTED_PROVIDERS+async def test_image_edit_health_check_handler_uses_png_and_prompt():+ model_params = {"model": "openai/gpt-image-1", "api_key": "sk-test"}+ mode_handlers = HealthCheckHelpers.get_mode_handlers(+ model="gpt-image-1",+ custom_llm_provider="openai",+ model_params=model_params,+ )++ assert "image_edit" in mode_handlers++ with patch( # test-quality-ok: the public health-check path has no dependency injection seam+ "litellm.aimage_edit", new_callable=AsyncMock, return_value={}+ ) as mock_aimage_edit:+ await mode_handlers["image_edit"]()+ await HealthCheckHelpers.get_mode_handlers(+ model="gpt-image-1",+ custom_llm_provider="openai",+ model_params=model_params,+ prompt="edit this image",+ )["image_edit"]()++ assert mock_aimage_edit.call_count == 2+ default_call = mock_aimage_edit.call_args_list[0].kwargs+ explicit_call = mock_aimage_edit.call_args_list[1].kwargs+ assert default_call["model"] == "openai/gpt-image-1"+ assert default_call["prompt"] == "test"+ assert explicit_call["prompt"] == "edit this image"+ image = default_call["image"]+ assert isinstance(image, bytes)+ assert image.startswith(b"\x89PNG")+ assert int.from_bytes(image[16:20], "big") == 512+ assert int.from_bytes(image[20:24], "big") == 512+++async def test_ahealth_check_supports_image_edit_mode():+ with patch( # test-quality-ok: the public health-check path has no dependency injection seam+ "litellm.aimage_edit", new_callable=AsyncMock, return_value={}+ ):+ result = await ahealth_check(+ {"model": "gpt-image-1", "api_key": "sk-test"},+ mode="image_edit",+ )++ assert "error" not in result+ assert "Mode image_edit not supported" not in str(result)++def test_update_model_params_with_health_check_tracking_information():"""Test _update_model_params_with_health_check_tracking_information adds required tracking info."""initial_model_params = {"model": "gpt-3.5-turbo", "api_key": "test_key"}