From f605612b879bb182a568f2de357c4d47e3de11d1 Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Thu, 12 Mar 2026 20:54:32 -0700 Subject: [PATCH] [HTTP] Fix `/GET` HTTP route when ollama endpoint is not set. (#20494) --- python/sglang/srt/entrypoints/http_server.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/python/sglang/srt/entrypoints/http_server.py b/python/sglang/srt/entrypoints/http_server.py index 853b402e0..ae81acb7f 100644 --- a/python/sglang/srt/entrypoints/http_server.py +++ b/python/sglang/srt/entrypoints/http_server.py @@ -1617,12 +1617,22 @@ async def v1_rerank_request(request: V1RerankReqInput, raw_request: Request): ##### Ollama-compatible API endpoints ##### +_ollama_root_route = os.environ.get("SGLANG_OLLAMA_ROOT_ROUTE") +if _ollama_root_route is not None: -@app.get(os.environ.get("SGLANG_OLLAMA_ROOT_ROUTE", "/")) -@app.head(os.environ.get("SGLANG_OLLAMA_ROOT_ROUTE", "/")) -async def ollama_root(): - """Ollama-compatible root endpoint for health check.""" - return "Ollama is running" + @app.get(_ollama_root_route) + @app.head(_ollama_root_route) + async def ollama_root(): + """Ollama-compatible root endpoint.""" + return "Ollama is running" + +else: + + @app.get("/") + @app.head("/") + async def sglang_root(): + """Default root endpoint.""" + return "SGLang is running" @app.post(os.environ.get("SGLANG_OLLAMA_CHAT_ROUTE", "/api/chat"))