feat(ui_discovery_endpoints.py): add new public .well-known/ route for litellm ui config

returns the server root path and proxy base url for constructing api calls
This commit is contained in:
Krrish Dholakia 2025-06-02 14:21:41 -07:00
parent 66ce04d9e9
commit c4a15dcdcb
6 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,12 @@
Return the proxy base url and server root path, so UI can construct the correct url to access the proxy.
This is useful when the proxy is deployed at a different path than the root of the domain.
## How to use
**Action** Route the `/litellm` path to the proxy.
**Result** The UI will call `/litellm/.well-known/litellm-ui-config` to get the proxy base url and server root path.

View file

@ -0,0 +1,3 @@
from .ui_discovery_endpoints import router as ui_discovery_endpoints_router
__all__ = ["ui_discovery_endpoints_router"]

View file

@ -0,0 +1,20 @@
#### Analytics Endpoints #####
from fastapi import APIRouter
from litellm.types.proxy.discovery_endpoints.ui_discovery_endpoints import (
UiDiscoveryEndpoints,
)
router = APIRouter()
@router.get(".well-known/litellm-ui-config", response_model=UiDiscoveryEndpoints)
@router.get(
"/litellm/.well-known/litellm-ui-config", response_model=UiDiscoveryEndpoints
) # if mounted at root path
async def get_ui_config():
from litellm.proxy.utils import get_proxy_base_url, get_server_root_path
return UiDiscoveryEndpoints(
server_root_path=get_server_root_path(), proxy_base_url=get_proxy_base_url()
)

View file

@ -203,6 +203,7 @@ from litellm.proxy.common_utils.swagger_utils import ERROR_RESPONSES
from litellm.proxy.credential_endpoints.endpoints import router as credential_router
from litellm.proxy.db.db_transaction_queue.spend_log_cleanup import SpendLogCleanup
from litellm.proxy.db.exception_handler import PrismaDBExceptionHandler
from litellm.proxy.discovery_endpoints import ui_discovery_endpoints_router
from litellm.proxy.fine_tuning_endpoints.endpoints import router as fine_tuning_router
from litellm.proxy.fine_tuning_endpoints.endpoints import set_fine_tuning_config
from litellm.proxy.guardrails.guardrail_endpoints import router as guardrails_router
@ -8150,3 +8151,4 @@ app.include_router(budget_management_router)
app.include_router(model_management_router)
app.include_router(tag_management_router)
app.include_router(enterprise_router)
app.include_router(ui_discovery_endpoints_router)

View file

@ -2865,6 +2865,13 @@ def get_custom_url(request_base_url: str) -> str:
return ui_link
def get_proxy_base_url() -> Optional[str]:
"""
Get the proxy base url from the environment variables.
"""
return os.getenv("PROXY_BASE_URL")
def get_server_root_path() -> str:
"""
Get the server root path from the environment variables.

View file

@ -0,0 +1,8 @@
from typing import Optional
from pydantic import BaseModel
class UiDiscoveryEndpoints(BaseModel):
server_root_path: str
proxy_base_url: Optional[str]