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] /get_image returns stale cached logo instead of custom UI_LOGO_PATH
yuneng-jianga8026154ab43
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 0e702abfc6c..45d1af06525 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -10694,13 +10694,17 @@ async def get_image():cache_dir = assets_dir if os.access(assets_dir, os.W_OK) else current_dircache_path = os.path.join(cache_dir, "cached_logo.jpg")- # [OPTIMIZATION] Check if the cached image exists first- if os.path.exists(cache_path):- return FileResponse(cache_path, media_type="image/jpeg")-logo_path = os.getenv("UI_LOGO_PATH", default_logo)verbose_proxy_logger.debug("Reading logo from path: %s", logo_path)+ # If UI_LOGO_PATH points to a local file, serve it directly (skip cache)+ if logo_path != default_logo and not logo_path.startswith(("http://", "https://")):+ return FileResponse(logo_path, media_type="image/jpeg")++ # [OPTIMIZATION] For HTTP URLs and default logo, check if the cached image exists+ if os.path.exists(cache_path):+ return FileResponse(cache_path, media_type="image/jpeg")+# Check if the logo path is an HTTP/HTTPS URLif logo_path.startswith(("http://", "https://")):try:diff --git a/tests/test_litellm/proxy/test_proxy_server.py b/tests/test_litellm/proxy/test_proxy_server.pyindex 79b5e34022f..532e11e70f1 100644--- a/tests/test_litellm/proxy/test_proxy_server.py+++ b/tests/test_litellm/proxy/test_proxy_server.py@@ -3154,6 +3154,76 @@ async def test_get_image_root_case_uses_current_dir(monkeypatch):assert mock_file_response.called, "FileResponse should be called"+async def test_get_image_custom_local_logo_bypasses_cache(monkeypatch):+ """+ Test that when UI_LOGO_PATH is set to a local file, get_image serves it+ directly and does not return a stale cached_logo.jpg.++ Regression test: previously the cache check ran before reading UI_LOGO_PATH,+ so a pre-existing cached_logo.jpg (e.g. from the base Docker image) would+ always be returned, ignoring the user's custom logo.+ """+ from unittest.mock import patch++ from litellm.proxy.proxy_server import get_image++ monkeypatch.setenv("UI_LOGO_PATH", "/app/custom_logo.jpg")+ monkeypatch.delenv("LITELLM_NON_ROOT", raising=False)+ monkeypatch.delenv("LITELLM_ASSETS_PATH", raising=False)++ calls_to_file_response = []++ def fake_file_response(path, **kwargs):+ calls_to_file_response.append(path)+ return MagicMock()++ with patch("litellm.proxy.proxy_server.os.path.exists", return_value=True), \+ patch("litellm.proxy.proxy_server.os.access", return_value=True), \+ patch("litellm.proxy.proxy_server.FileResponse", side_effect=fake_file_response):++ await get_image()++ assert len(calls_to_file_response) == 1, "FileResponse should be called exactly once"+ assert calls_to_file_response[0] == "/app/custom_logo.jpg", (+ f"Expected custom logo path, got {calls_to_file_response[0]}. "+ "A stale cached_logo.jpg may have been returned instead."+ )+++async def test_get_image_default_logo_still_uses_cache(monkeypatch):+ """+ Test that when UI_LOGO_PATH is NOT set (default logo), the cache+ optimization still works — cached_logo.jpg is returned if it exists.+ """+ from unittest.mock import patch++ from litellm.proxy.proxy_server import get_image++ monkeypatch.delenv("UI_LOGO_PATH", raising=False)+ monkeypatch.delenv("LITELLM_NON_ROOT", raising=False)+ monkeypatch.delenv("LITELLM_ASSETS_PATH", raising=False)++ calls_to_file_response = []++ def fake_file_response(path, **kwargs):+ calls_to_file_response.append(path)+ return MagicMock()++ with patch("litellm.proxy.proxy_server.os.path.exists", return_value=True), \+ patch("litellm.proxy.proxy_server.os.access", return_value=True), \+ patch("litellm.proxy.proxy_server.FileResponse", side_effect=fake_file_response):++ await get_image()++ assert len(calls_to_file_response) == 1, "FileResponse should be called exactly once"+ served_path = calls_to_file_response[0]+ assert served_path.endswith("cached_logo.jpg"), (+ f"Expected cached_logo.jpg for default logo, got {served_path}"+ )++def test_get_config_normalizes_string_callbacks(monkeypatch):"""Test that /get/config/callbacks normalizes string callbacks to lists.