SGLang launches with a single command sglang serve <model> in a Docker container lmsysorg/sglang or in a Python environment, after which it exposes an OpenAI-compatible API on port 30000. You need Linux, an NVIDIA GPU, and a driver with CUDA 13 support; starting from version 0.5.20 images and wheels for CUDA 12 are no longer published. Below: installation, first launch, API check, key memory and scheduling settings, metrics, and security.
The guide was prepared by Vladimir Lomtev's AI Studio on November 16, 2026, based on the SGLang quickstart guide, the installation guide, the server arguments reference and the 0.5.23 release notes. The commands were checked for syntax, but we did not run them on a specific GPU. Check default values against the --help output for your version.
Contents
- When to choose SGLang
- Requirements
- Install and run with Docker
- Install in a Python environment
- API check
- Key server settings
- Multiple GPUs
- Metrics
- Security and updates
- Common errors
- FAQ
When to choose SGLang
SGLang is a GPU inference server with a strong advantage in reusing shared prefixes: its RadixAttention stores the cache as a tree and reuses it across requests with the same beginning. This is useful for agents, multi-turn chats, RAG with shared instructions, and structured output. vLLM solves similar problems and is more widely adopted. The choice between them is usually made by testing on your own workload; reference points are in the article “vLLM, Ollama, llama.cpp, or SGLang”.
Requirements
| Component | What you need |
|---|---|
| OS | Linux |
| GPU | A supported NVIDIA GPU (there are separate instructions for AMD, Intel, TPU, and other platforms) |
| Driver | Compatible with CUDA 13 |
| Docker path | Docker Engine and NVIDIA Container Toolkit |
| Python path | Python 3.11 or newer |
The installation guide says SGLang images ship with a CUDA 13 environment, and the latest tag for CUDA 12 is lmsysorg/sglang:v0.5.19-cu129. The switch is tied to the move to PyTorch 2.14, which has no builds for CUDA 12.9. If the driver on the host is old, update it first; otherwise the new image will not start.
Install and run with Docker
Docker is the easiest path: the image already includes Python, SGLang, and dependencies. Pin the image version instead of latest, so updates happen deliberately:
docker pull lmsysorg/sglang:v0.5.23
docker run --rm --gpus all --ipc=host --shm-size 32g \
-p 127.0.0.1:30000:30000 \
-v /srv/hf-cache:/root/.cache/huggingface \
-e HF_TOKEN \
lmsysorg/sglang:v0.5.23 \
sglang serve Qwen/Qwen3-8B --host 0.0.0.0 --port 30000 \
--api-key "$SGLANG_API_KEY"
What matters here:
--ipc=hostand--shm-size 32ggive the engine processes shared memory; without it, failures are possible;- the
/srv/hf-cachedirectory preserves downloaded weights between container restarts; -e HF_TOKENis only needed for gated models on Hugging Face;- publishing the port on
127.0.0.1keeps the server accessible only from the host, and external access is better provided through a reverse proxy.
The server is ready when the log shows The server is fired up and ready to roll!.
Install in a Python environment
If Docker is not an option, the guide suggests installing via uv:
uv venv --python 3.12
source .venv/bin/activate
uv pip install --prerelease=allow sglang
sglang serve Qwen/Qwen3-8B --host 127.0.0.1 --port 30000 --api-key "$SGLANG_API_KEY"
The flag --prerelease=allow is included in the official instructions: some dependencies are published as pre-release versions. For reproducibility, pin the package version, for example sglang==0.5.23.
In older instructions, you may still see the command python -m sglang.launch_server --model-path .... It is still used in some documentation, but the quick start guide now shows sglang serve.
API check
curl http://127.0.0.1:30000/v1/chat/completions \
-H "Authorization: Bearer $SGLANG_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"Qwen/Qwen3-8B","messages":[{"role":"user","content":"Name three signs of an overloaded LLM server"}],"max_tokens":200}'
Look for the response in choices[0].message.content. From Python, the OpenAI client works:
import os
from openai import OpenAI
client = OpenAI(base_url="http://127.0.0.1:30000/v1", api_key=os.environ["SGLANG_API_KEY"])
stream = client.chat.completions.create(
model="Qwen/Qwen3-8B",
messages=[{"role": "user", "content": "Explain what prefix caching is in three sentences"}],
max_tokens=300,
stream=True,
)
for chunk in stream:
delta = chunk.choices[0].delta.content
if delta:
print(delta, end="", flush=True)
The --served-model-name flag changes the name the server returns in /v1/models; this is useful when clients should not depend on the path to the weights.
Main server parameters
| Parameter | Default | Why change it |
|---|---|---|
--api-key |
not set | Protect the API with a key |
--context-length |
from config.json for the model |
Limit the maximum context and the memory allocated for it |
--mem-fraction-static |
calculated based on GPU memory, 0.88 if it could not be determined | The share of memory for weights and the KV cache pool; reduce it if you run into out-of-memory errors |
--tp-size |
1 | Split the model across multiple GPUs |
--chunked-prefill-size |
not set | Chunk size for chunked prefill; -1 disables splitting |
--max-running-requests |
not set | Limit the number of requests processed at the same time |
--schedule-policy |
fcfs |
Choose the scheduling order: lpm, priority, routing-key and others |
--kv-cache-dtype |
auto |
Compress the KV cache, for example to fp8_e4m3 |
--enable-metrics |
disabled | Enable Prometheus metrics |
--tool-call-parser |
not set | Tool call parsing; auto takes it from the chat template |
--disable-radix-cache |
disabled | Disable prefix caching, for example for tests |
The argument reference recommends reducing --mem-fraction-static if memory is tight, for example to 0.7. For details on cache compression, see the article "KV Cache in FP8", and for offloading the cache to system RAM via HiCache, see the article on offloading the KV cache to RAM and NVMe.
You can store parameters in a YAML file and pass them through --config; command-line values override the file.
Multiple GPUs
If the model does not fit on one GPU, use tensor parallelism:
sglang serve Qwen/Qwen3-32B --host 127.0.0.1 --port 30000 \
--tp-size 2 --api-key "$SGLANG_API_KEY"
If the model fits, but you need higher throughput, the reference includes an example combining data parallelism --dp and tensor --tp. Which one to choose is explained in the article “LLM on Multiple GPUs”.
Metrics
With the flag --enable-metrics SGLang exposes Prometheus metrics. Based on the production metrics guide these are useful to start with:
| Metric | What it shows |
|---|---|
sglang:num_running_reqs |
Requests in progress |
sglang:num_queue_reqs |
Requests in the queue |
sglang:token_usage |
Share of memory used for tokens |
sglang:cache_hit_rate |
Prefix cache hit rate |
sglang:gen_throughput |
Generation speed, tokens per second |
sglang:time_to_first_token_seconds |
Histogram of time to first token |
sglang:inter_token_latency_seconds |
Histogram of latency between tokens |
A growing num_queue_reqs with high token_usage means there is not enough memory for the cache; a growing queue with free memory means you are hitting compute limits or the --max-running-requests limit. How to build a queue with limits at the gateway is described in the article about the LLM request queue.
Security and updates
- Set
--api-keyand do not expose port 30000 on a public interface without a reverse proxy with TLS. - If you use separate prefill and decode, update: in 2026 SGLang fixed a KV cache leak between users; details are in the article “KV Cache Leak in SGLang”.
- Pin the image version and read the release notes before upgrading.
- Store the weight cache on a separate volume with restricted access.
Common errors
- The container cannot see the GPU — NVIDIA Container Toolkit is not installed or configured, or the driver does not support CUDA 13.
- Out of memory on startup or under load — reduce
--mem-fraction-staticor--context-length. - Process crashes with no clear error — check that the container has shared memory allocated (
--ipc=host,--shm-size). - Tool calls are returned as text —
--tool-call-parseris not set for the model. - The server is accessible from the network without a password — the command uses
--host 0.0.0.0without--api-keyand without port exposure restrictions.
Frequently asked questions
How is sglang serve different from python -m sglang.launch_server? Both forms appear in the documentation; the quick start uses sglang serve.
Can SGLang run on CUDA 12? The latest image tag for CUDA 12 is v0.5.19-cu129. It does not include fixes from later releases, including security fixes.
Does SGLang support request priorities? Yes, among the --schedule-policy policies there is priority. For fairness across teams, you still need a gateway with rate limits.
Is SGLang a good fit for a single user on a workstation? It can work, but for one user Ollama or llama-server is simpler. SGLang shines in multi-user workloads.
How Vladimir Lomtev’s AI studio helps deploy SGLang
Vladimir Lomtev’s AI studio deploys LLMs on the company’s servers and supports them. For SGLang, that means:
- check driver, GPU, and model compatibility with the current version of SGLang;
- configure the server with keys, a reverse proxy, metrics, and pinned versions;
- compare SGLang and vLLM with load testing on your own requests;
- integrate the API with enterprise systems and hand the team an update procedure.
The first step is to choose a model and one real-world task, record the latency and user-count requirements, and test them on a staging server. Discuss the project.
Bottom line: SGLang starts quickly, but it requires CUDA 13
Getting SGLang up and running comes down to a single Docker command if the host has a current NVIDIA driver and Container Toolkit configured. Pin the image version, set the key and metrics, size memory for the cache, and test the server against your own workload. SGLang is strongest where requests share a lot of the same prompt prefix: agents, chat, and RAG.



