Skip to content

Commit 6135466

Browse files
krrishdholakiastefan--
authored andcommitted
UI - Custom Server Root Path (Multiple Fixes) (BerriAI#11337)
* fix(proxy_server.py): working swagger on custom base removes the swagger monkey patch - this seems to render the swagger on custom base paths * fix(ui/): working custom auth uptil login success event * fix(ui/): working custom server root path for login * fix(proxy_server.py): create typed dict for ui returned token allows better documentation of expected params * refactor(proxy_server.py): refactor all ui login endpoints to use same returned ui token object * feat(ui_sso.py): add server root path to ui token * feat(ui_sso.py): allows ui to call correct endpoint * fix(networking.tsx): update proxy base url with custom root path * fix(networking.tsx): handle updating proxy base url for non-local instances * refactor: remove uneccessary references to proxybaseurl in ui code - reduce potential for errors * fix: fix linting error * fix(onboarding_link.tsx): fix onboarding link when custom server path is set * 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 * feat(_types.py): add litellm well known config as public route allows ui to query it * fix(/_types.py): add .well-known config to as public route * fix(page.tsx): create pattern for loading in ui config before making network requests ensures requests are formatted correctly * fix(page.tsx): call credential endpoint once ui config is loaded * fix(page.tsx): route correctly to litellm dashboard from new user login * fix(page.tsx): remove hardcoded `/litellm` for /sso/key/generate request * fix(proxy_server.py): re-add moderations endpoint * fix(proxy_server.py): mount __next__ at / and /litellm allows it to work when proxy is mounted on root * docs(contributing.md): remove /ui on ui doc - it will now run on root * docs(custom_root_ui.md): add docs on custom root path
1 parent d8234c5 commit 6135466

File tree

83 files changed

+639
-459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+639
-459
lines changed

docs/my-website/docs/contributing.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ cd litellm/ui/litellm-dashboard
3333

3434
npm run dev
3535

36-
# starts on http://0.0.0.0:3000/ui
36+
# starts on http://0.0.0.0:3000
3737
```
3838

3939
## 3. Go to local UI
4040

41-
```
42-
http://0.0.0.0:3000/ui
41+
```bash
42+
http://0.0.0.0:3000
4343
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# UI - Custom Root Path
2+
3+
💥 Use this when you want to serve LiteLLM on a custom base url path like `https://localhost:4000/api/v1`
4+
5+
## Usage
6+
7+
### 1. Set `SERVER_ROOT_PATH` in your .env
8+
9+
👉 Set `SERVER_ROOT_PATH` in your .env and this will be set as your server root path
10+
11+
```
12+
export SERVER_ROOT_PATH="/api/v1"
13+
```
14+
15+
### 2. Run the Proxy
16+
17+
```shell
18+
litellm proxy --config /path/to/config.yaml
19+
```
20+
21+
After running the proxy you can access it on `http://0.0.0.0:4000/api/v1/` (since we set `SERVER_ROOT_PATH="/api/v1"`)
22+
23+
24+
### 3. Reserve the `/litellm` path
25+
26+
LiteLLM uses the `/litellm` path to discover the custom root path. So you need to reserve this path in your proxy.
27+
28+
If you are running the UI, it will query the `/litellm/.well-known/litellm-ui-config` endpoint to get the UI configuration.
29+
30+
So you need to reserve the `/litellm` path in your proxy.
31+
32+
You can see the results with:
33+
34+
```bash
35+
curl http://0.0.0.0:4000/litellm/.well-known/litellm-ui-config
36+
```
37+
38+
Expected result:
39+
40+
```json
41+
42+
{
43+
"server_root_path": "/api/v1",
44+
...
45+
}
46+
47+
```
48+
49+
50+
### 4. Verify Running on correct path
51+
52+
<Image img={require('../../img/custom_root_path.png')} />
53+
54+
**That's it**, that's all you need to run the proxy on a custom root path
55+
56+
57+
## Demo
58+
59+
[Here's a demo video](https://drive.google.com/file/d/1zqAxI0lmzNp7IJH1dxlLuKqX2xi3F_R3/view?usp=sharing) of running the proxy on a custom root path

docs/my-website/docs/proxy/deploy.md

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -619,101 +619,8 @@ docker pull ghcr.io/berriai/litellm-non_root:main-stable
619619
620620
### 1. Custom server root path (Proxy base url)
621621
622-
💥 Use this when you want to serve LiteLLM on a custom base url path like `https://localhost:4000/api/v1`
622+
Refer to [Custom Root Path](./custom_root_ui) for more details.
623623
624-
:::info
625-
626-
In a Kubernetes deployment, it's possible to utilize a shared DNS to host multiple applications by modifying the virtual service
627-
628-
:::
629-
630-
Customize the root path to eliminate the need for employing multiple DNS configurations during deployment.
631-
632-
Step 1.
633-
👉 Set `SERVER_ROOT_PATH` in your .env and this will be set as your server root path
634-
```
635-
export SERVER_ROOT_PATH="/api/v1"
636-
```
637-
638-
**Step 2** (If you want the Proxy Admin UI to work with your root path you need to use this dockerfile)
639-
- Use the dockerfile below (it uses litellm as a base image)
640-
- 👉 Set `UI_BASE_PATH=$SERVER_ROOT_PATH/ui` in the Dockerfile, example `UI_BASE_PATH=/api/v1/ui`
641-
642-
Dockerfile
643-
644-
```shell
645-
# Use the provided base image
646-
FROM ghcr.io/berriai/litellm:main-latest
647-
648-
# Set the working directory to /app
649-
WORKDIR /app
650-
651-
# Install Node.js and npm (adjust version as needed)
652-
RUN apt-get update && apt-get install -y nodejs npm
653-
654-
# Copy the UI source into the container
655-
COPY ./ui/litellm-dashboard /app/ui/litellm-dashboard
656-
657-
# Set an environment variable for UI_BASE_PATH
658-
# This can be overridden at build time
659-
# set UI_BASE_PATH to "<your server root path>/ui"
660-
# 👇👇 Enter your UI_BASE_PATH here
661-
ENV UI_BASE_PATH="/api/v1/ui"
662-
663-
# Build the UI with the specified UI_BASE_PATH
664-
WORKDIR /app/ui/litellm-dashboard
665-
RUN npm install
666-
RUN UI_BASE_PATH=$UI_BASE_PATH npm run build
667-
668-
# Create the destination directory
669-
RUN mkdir -p /app/litellm/proxy/_experimental/out
670-
671-
# Move the built files to the appropriate location
672-
# Assuming the build output is in ./out directory
673-
RUN rm -rf /app/litellm/proxy/_experimental/out/* && \
674-
mv ./out/* /app/litellm/proxy/_experimental/out/
675-
676-
# Switch back to the main app directory
677-
WORKDIR /app
678-
679-
# Make sure your entrypoint.sh is executable
680-
RUN chmod +x ./docker/entrypoint.sh
681-
682-
# Expose the necessary port
683-
EXPOSE 4000/tcp
684-
685-
# Override the CMD instruction with your desired command and arguments
686-
# only use --detailed_debug for debugging
687-
CMD ["--port", "4000", "--config", "config.yaml"]
688-
```
689-
690-
**Step 3** build this Dockerfile
691-
692-
```shell
693-
docker build -f Dockerfile -t litellm-prod-build . --progress=plain
694-
```
695-
696-
**Step 4. Run Proxy with `SERVER_ROOT_PATH` set in your env **
697-
698-
```shell
699-
docker run \
700-
-v $(pwd)/proxy_config.yaml:/app/config.yaml \
701-
-p 4000:4000 \
702-
-e LITELLM_LOG="DEBUG"\
703-
-e SERVER_ROOT_PATH="/api/v1"\
704-
-e DATABASE_URL=postgresql://<user>:<password>@<host>:<port>/<dbname> \
705-
-e LITELLM_MASTER_KEY="sk-1234"\
706-
litellm-prod-build \
707-
--config /app/config.yaml
708-
```
709-
710-
After running the proxy you can access it on `http://0.0.0.0:4000/api/v1/` (since we set `SERVER_ROOT_PATH="/api/v1"`)
711-
712-
**Step 5. Verify Running on correct path**
713-
714-
<Image img={require('../../img/custom_root_path.png')} />
715-
716-
**That's it**, that's all you need to run the proxy on a custom root path
717624
718625
### 2. SSL Certification
719626

docs/my-website/sidebars.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const sidebars = {
102102
items: [
103103
"proxy/ui",
104104
"proxy/admin_ui_sso",
105+
"proxy/custom_root_ui",
105106
"proxy/self_serve",
106107
"proxy/public_teams",
107108
"tutorials/scim_litellm",

litellm/proxy/_experimental/out/_next/static/chunks/117-1c5bfc45bfc4237d.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

litellm/proxy/_experimental/out/_next/static/chunks/117-c4922b1dd81b62ce.js

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/litellm-dashboard/out/_next/static/chunks/660-52b9dbb37b758151.js renamed to litellm/proxy/_experimental/out/_next/static/chunks/660-8945b6c12184d209.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/app/layout-413324e69a201f65.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/app/layout-f6fbbcb965e8cc49.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

ui/litellm-dashboard/out/_next/static/chunks/app/model_hub/page-ce40c5a05f3174ca.js renamed to litellm/proxy/_experimental/out/_next/static/chunks/app/model_hub/page-38df01e06b8ad4aa.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-0aa6cc914ba0c59d.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/app/onboarding/page-c2a273e1698ea2da.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_experimental/out/_next/static/chunks/app/page-600ab8b71da0074f.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_experimental/out/_next/static/chunks/app/page-d16f3e78ac977ba3.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/main-8ee698634884314e.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

litellm/proxy/_experimental/out/_next/static/chunks/main-app-475d6efe4080647d.js renamed to litellm/proxy/_experimental/out/_next/static/chunks/main-app-4f7318ae681a6d94.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

litellm/proxy/_experimental/out/_next/static/chunks/main-d44a021deddb5790.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)