Skip to content

Commit d89990e

Browse files
bernataPlan42.ai
andauthored
Add license metadata to health/readiness endpoint. (#15997)
* health: expose license metadata (available & expiration) in /health/readiness endpoint * test: add health readiness license metadata coverage * test: ensure /health/readiness response includes license metadata * chore: remove standalone license metadata test as requested; existing test covers codepath --------- Co-authored-by: Plan42.ai <[email protected]>
1 parent a5b7259 commit d89990e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

litellm/proxy/health_endpoints/_health_endpoints.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,28 @@ async def health_readiness():
831831
index_info = "index does not exist - error: " + str(e)
832832
cache_type = {"type": cache_type, "index_info": index_info}
833833

834+
# build license metadata
835+
try:
836+
from litellm.proxy.proxy_server import _license_check # type: ignore
837+
838+
license_available: bool = _license_check.is_premium() if _license_check else False
839+
license_expiration: Optional[str] = None
840+
841+
if getattr(_license_check, "airgapped_license_data", None):
842+
license_expiration = _license_check.airgapped_license_data.get( # type: ignore[arg-type]
843+
"expiration_date"
844+
)
845+
846+
license_metadata = {
847+
"license": {
848+
"has_license": license_available,
849+
"expiration_date": license_expiration,
850+
}
851+
}
852+
except Exception:
853+
# fail closed: don't let license check break readiness
854+
license_metadata = {"license": {"has_license": False, "expiration_date": None}}
855+
834856
# check DB
835857
if prisma_client is not None: # if db passed in, check if it's connected
836858
db_health_status = await _db_health_readiness_check()
@@ -841,6 +863,7 @@ async def health_readiness():
841863
"litellm_version": version,
842864
"success_callbacks": success_callback_names,
843865
"use_aiohttp_transport": AsyncHTTPHandler._should_use_aiohttp_transport(),
866+
**license_metadata,
844867
**db_health_status,
845868
}
846869
else:
@@ -851,6 +874,7 @@ async def health_readiness():
851874
"litellm_version": version,
852875
"success_callbacks": success_callback_names,
853876
"use_aiohttp_transport": AsyncHTTPHandler._should_use_aiohttp_transport(),
877+
**license_metadata,
854878
}
855879
except Exception as e:
856880
raise HTTPException(status_code=503, detail=f"Service Unhealthy ({str(e)})")

tests/basic_proxy_startup_tests/test_basic_proxy_startup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ async def test_health_and_chat_completion():
2525
readiness_response = await response.json()
2626
assert readiness_response["status"] == "connected"
2727

28+
# New assertion: license metadata is present
29+
assert "license" in readiness_response
30+
assert "has_license" in readiness_response["license"]
31+
2832
# Test liveness endpoint
2933
async with session.get("http://0.0.0.0:4000/health/liveness") as response:
3034
assert response.status == 200

0 commit comments

Comments
 (0)