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(proxy): expose db status on public /health/readiness
Yuneng Jiangd6fa08307b05
diff --git a/litellm/proxy/health_endpoints/_health_endpoints.py b/litellm/proxy/health_endpoints/_health_endpoints.pyindex 3032c9d38cc..ff3df11c448 100644--- a/litellm/proxy/health_endpoints/_health_endpoints.py+++ b/litellm/proxy/health_endpoints/_health_endpoints.py@@ -1548,15 +1548,21 @@ def _allow_public_health_readiness_details() -> bool:return general_settings.get("allow_public_health_readiness_details") is True-async def _set_public_readiness_status(response: Response) -> None:+async def _resolve_public_readiness_db(response: Response) -> str:+ """+ Return the db status string for the public probe and flip the response to+ 503 when a configured DB is unreachable. Mirrors the legacy values:+ "Not connected" (no DB configured), "connected", "disconnected".+ """from litellm.proxy.proxy_server import prisma_clientif prisma_client is None:- return+ return "Not connected"db_health_status = await _db_health_readiness_check()if db_health_status["status"] != "connected":response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE+ return db_health_status["status"]@router.get(@@ -1565,15 +1571,17 @@ async def _set_public_readiness_status(response: Response) -> None:)async def health_readiness(response: Response):"""- Public readiness probe. Keep this low-detail for unauthenticated load- balancers by default. Admins can opt into the legacy detailed public- payload with general_settings.allow_public_health_readiness_details.+ Public readiness probe. Returns a low-detail payload safe to expose to+ unauthenticated load balancers — `status` plus `db` so orchestrators and+ external probes can distinguish "healthy" from "DB unreachable" without a+ credential. Admins can opt into the legacy detailed payload with+ general_settings.allow_public_health_readiness_details."""if _allow_public_health_readiness_details():return await _get_health_readiness_details(response=response)- await _set_public_readiness_status(response=response)- return {"status": "healthy"}+ db_status = await _resolve_public_readiness_db(response=response)+ return {"status": "healthy", "db": db_status}@router.get(diff --git a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.pyindex bcd7fcb37b3..80a4804956c 100644--- a/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py+++ b/tests/test_litellm/proxy/health_endpoints/test_health_endpoints.py@@ -844,9 +844,14 @@ def test_health_readiness(proxy_client):duration_ms < 500), f"Health check took {duration_ms:.2f}ms, expected < 500ms for readiness endpoint"- # Assert response contains only low-detail public probe fields+ # Assert response contains only low-detail public probe fields. `db` is+ # included so unauthenticated probes can distinguish "DB unreachable"+ # from a fully-healthy worker; its value depends on whether the test env+ # exposes DATABASE_URL.response_data = response.json()- assert response_data == {"status": "healthy"}+ assert set(response_data.keys()) == {"status", "db"}+ assert response_data["status"] == "healthy"+ assert response_data["db"] in {"connected", "disconnected", "Not connected"}print(f"Response time: {duration_ms:.2f}ms")@@ -1750,7 +1755,7 @@ async def test_health_readiness_returns_503_when_db_disconnected():result = await health_readiness(response=response)assert response.status_code == 503- assert result == {"status": "healthy"}+ assert result == {"status": "healthy", "db": "disconnected"}@pytest.mark.asyncio@@ -1773,7 +1778,7 @@ async def test_health_readiness_returns_200_when_db_connected():result = await health_readiness(response=response)assert response.status_code == 200- assert result == {"status": "healthy"}+ assert result == {"status": "healthy", "db": "connected"}@pytest.mark.asyncio@@ -1792,7 +1797,7 @@ async def test_health_readiness_returns_200_when_no_db_configured():result = await health_readiness(response=response)assert response.status_code == 200- assert result == {"status": "healthy"}+ assert result == {"status": "healthy", "db": "Not connected"}def test_clean_endpoint_data_strips_credentials_keeps_routing_fields():