fix(ui/): working custom server root path for login

This commit is contained in:
Krrish Dholakia 2025-06-02 10:41:59 -07:00
parent 526f5dd907
commit e9d33c4d02
2 changed files with 26 additions and 5 deletions

View file

@ -309,6 +309,7 @@ from litellm.proxy.utils import (
_get_redoc_url,
_is_projected_spend_over_limit,
_is_valid_team_configs,
get_custom_url,
get_error_message_str,
hash_token,
update_spend,
@ -6586,8 +6587,10 @@ async def fallback_login(request: Request):
PROXY_BASE_URL should be the your deployed proxy endpoint, e.g. PROXY_BASE_URL="https://litellm-production-7002.up.railway.app/"
Example:
"""
from litellm.proxy.proxy_server import ui_link
# get url from request
redirect_url = os.getenv("PROXY_BASE_URL", str(request.base_url))
redirect_url = get_custom_url(str(request.base_url))
ui_username = os.getenv("UI_USERNAME")
if redirect_url.endswith("/"):
redirect_url += "sso/callback"
@ -6711,7 +6714,7 @@ async def login(request: Request): # noqa: PLR0915
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
key = response["token"] # type: ignore
litellm_dashboard_ui = os.getenv("PROXY_BASE_URL", "")
litellm_dashboard_ui = get_custom_url(str(request.base_url))
if litellm_dashboard_ui.endswith("/"):
litellm_dashboard_ui += "ui/"
else:
@ -6812,7 +6815,7 @@ async def login(request: Request): # noqa: PLR0915
code=status.HTTP_500_INTERNAL_SERVER_ERROR,
)
key = response["token"] # type: ignore
litellm_dashboard_ui = os.getenv("PROXY_BASE_URL", "")
litellm_dashboard_ui = get_custom_url(str(request.base_url))
if litellm_dashboard_ui.endswith("/"):
litellm_dashboard_ui += "ui/"
else:
@ -6858,7 +6861,7 @@ async def login(request: Request): # noqa: PLR0915
@app.get("/onboarding/get_token", include_in_schema=False)
async def onboarding(invite_link: str):
async def onboarding(invite_link: str, request: Request):
"""
- Get the invite link
- Validate it's still 'valid'
@ -6938,7 +6941,7 @@ async def onboarding(invite_link: str):
)
key = response["token"] # type: ignore
litellm_dashboard_ui = os.getenv("PROXY_BASE_URL", "")
litellm_dashboard_ui = get_custom_url(str(request.base_url))
if litellm_dashboard_ui.endswith("/"):
litellm_dashboard_ui += "ui/onboarding"
else:

View file

@ -2845,3 +2845,21 @@ def is_known_model(model: Optional[str], llm_router: Optional[Router]) -> bool:
is_in_list = True
return is_in_list
def get_custom_url(request_base_url: str) -> str:
"""
Use proxy base url, if set.
Else, use request base url.
"""
from httpx import URL
proxy_base_url = os.getenv("PROXY_BASE_URL")
server_root_path = os.getenv("SERVER_ROOT_PATH") or ""
if proxy_base_url:
ui_link = str(URL(proxy_base_url).join(server_root_path))
else:
ui_link = str(URL(request_base_url).join(server_root_path))
return ui_link