From 15db5497d30b2ab325d4862ff38efd5e0d1f5e3c Mon Sep 17 00:00:00 2001 From: kebyn Date: Mon, 17 Nov 2025 22:40:09 +0800 Subject: [PATCH] [feature] Custom base path on FastAPI server (#5879) Co-authored-by: lianhu.yin Co-authored-by: kebyn Co-authored-by: Liangsheng Yin --- python/sglang/srt/entrypoints/http_server.py | 2 ++ python/sglang/srt/server_args.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/python/sglang/srt/entrypoints/http_server.py b/python/sglang/srt/entrypoints/http_server.py index 460c5065a..b8a320112 100644 --- a/python/sglang/srt/entrypoints/http_server.py +++ b/python/sglang/srt/entrypoints/http_server.py @@ -1383,6 +1383,7 @@ def launch_server( app, host=server_args.host, port=server_args.port, + root_path=server_args.fastapi_root_path, log_level=server_args.log_level_http or server_args.log_level, timeout_keep_alive=5, loop="uvloop", @@ -1401,6 +1402,7 @@ def launch_server( "sglang.srt.entrypoints.http_server:app", host=server_args.host, port=server_args.port, + root_path=server_args.fastapi_root_path, log_level=server_args.log_level_http or server_args.log_level, timeout_keep_alive=5, loop="uvloop", diff --git a/python/sglang/srt/server_args.py b/python/sglang/srt/server_args.py index b6fd815f8..5a7e52248 100644 --- a/python/sglang/srt/server_args.py +++ b/python/sglang/srt/server_args.py @@ -243,6 +243,7 @@ class ServerArgs: # HTTP server host: str = "127.0.0.1" port: int = 30000 + fastapi_root_path: str = "" grpc_mode: bool = False skip_server_warmup: bool = False warmups: Optional[str] = None @@ -2024,6 +2025,12 @@ class ServerArgs: default=ServerArgs.port, help="The port of the HTTP server.", ) + parser.add_argument( + "--fastapi-root-path", + type=str, + default=ServerArgs.fastapi_root_path, + help="App is behind a path based routing proxy.", + ) parser.add_argument( "--grpc-mode", action="store_true",