SGLang is one of the fastest open-source engines for serving large language models. It powers big production deployments, but it also runs on a single RTX card at home. If you have outgrown Ollama and want high throughput, an OpenAI-compatible API, an Anthropic-compatible API and strong structured output, SGLang is worth learning.
This guide takes you from zero to a working SGLang server.
You will install it with Docker or uv, launch your first model with the new sglang serve command, send requests, use multiple GPUs, tune memory, get JSON output, connect Claude Code, and fix the common errors.
It follows the official SGLang docs as of December 2026, after the SGLang 1.0 release and the move to CUDA 13.
- Needs: Linux, an NVIDIA GPU and a CUDA 13-compatible driver. CUDA 12 builds ended with 0.5.19.
- Docker:
docker run --gpus all --ipc=host -p 30000:30000 lmsysorg/sglang:latest sglang serve Qwen/Qwen3-0.6B --host 0.0.0.0 --port 30000 - uv:
uv pip install --prerelease=allow sglang, plus the CUDA 13 Toolkit and a compiler. - Ready when the log says
The server is fired up and ready to roll! - APIs: OpenAI at
/v1/chat/completions, Anthropic at/v1/messages, on port 30000. - Out of memory? Lower
--mem-fraction-staticor--chunked-prefill-size.
What SGLang Is and When to Use It
SGLang is an inference framework for language, vision-language and diffusion models. Its strengths are speed under load, prefix caching (RadixAttention reuses shared prompt prefixes across requests), and agent-friendly features like tool-call and reasoning parsers.
| Tool | Best for | Model format |
|---|---|---|
| Ollama | Easiest local use, any OS | GGUF |
| llama.cpp server | CPU, mixed CPU and GPU, small VRAM | GGUF |
| vLLM | High-throughput serving, wide model support | Hugging Face weights, AWQ, GPTQ, FP8 |
| SGLang | High throughput, agents, prefix-heavy workloads, structured output | Hugging Face weights, AWQ, GPTQ, FP8, FP4 |
Pick SGLang when you serve many requests at once, run agents that resend long system prompts, or want both OpenAI and Anthropic APIs from one server. Stick with Ollama or llama.cpp if you are on Windows without WSL, on a Mac, or short on VRAM.
SGLang loads full-precision or GPU-quantized weights, which need more memory than a 4-bit GGUF.
Requirements
- OS: Linux. The main instructions target Linux with NVIDIA GPUs. Other hardware, including AMD, Intel XPU, CPU servers, TPU and Apple Metal, has separate platform pages.
- GPU driver: CUDA 13-compatible. Check with
nvidia-smi. - For Docker: Docker Engine and the NVIDIA Container Toolkit. No host CUDA Toolkit or Python needed.
- For pip or uv: Python 3.11+, the full CUDA 13 Toolkit with
nvcc, a C/C++ compiler and Python development headers. Some kernels compile at runtime, so a driver alone is not enough. - VRAM: enough for the model weights plus KV cache. A 0.6B to 8B model is a good first test on 12 to 24 GB. See how much VRAM you need.
CUDA 12 users: SGLang moved to PyTorch 2.14 and CUDA 13. Version 0.5.19 is the last release with CUDA 12 support, and lmsysorg/sglang:v0.5.19-cu129 is the last CUDA 12 image. Update your driver to use current versions.
Install and Run With Docker
Docker is the recommended route because it includes Python, SGLang and every dependency.
- Install Docker and the NVIDIA Container Toolkit, then complete the toolkit’s Docker runtime configuration. Test with
docker run --rm --gpus all ubuntu nvidia-smi. - Pull the image:
docker pull lmsysorg/sglang:latest. Uselatest-runtimefor a smaller image of the same release, or a nightly tag for the newest changes. - Start the server with a Hugging Face cache mounted so weights are kept between runs:
HF_CACHE_DIR="$HOME/.cache/huggingface" docker run --rm --gpus all --ipc=host --shm-size 32g \ -p 30000:30000 \ -v "$HF_CACHE_DIR:/root/.cache/huggingface" \ lmsysorg/sglang:latest \ sglang serve Qwen/Qwen3-0.6B --host 0.0.0.0 --port 30000 - Wait for the ready message. The first launch can take several minutes to download weights, compile kernels and capture CUDA graphs. When you see
The server is fired up and ready to roll!, it is ready.
For gated models such as Llama, export HF_TOKEN on the host and add --env HF_TOKEN before the image name. --ipc=host and --shm-size give the processes the shared memory they need; without them, multi-GPU runs can hang.
For a long-running service, the repo ships a docker/compose.yaml. Copy it, set your model and run docker compose up -d.
Install With uv (No Docker)
- Install build tools:
sudo apt-get install -y build-essential curl ca-certificates - Install the CUDA 13 Toolkit from NVIDIA’s repository using a versioned package such as
cuda-toolkit-13-0. Ubuntu’s ownnvidia-cuda-toolkitmay be too old. - Point to it and check:
export CUDA_HOME=/usr/local/cuda-13.0 export PATH="$CUDA_HOME/bin:$PATH" nvcc --version - Install uv and create an environment with uv’s managed Python, which includes development headers:
curl -LsSf https://astral.sh/uv/install.sh | sh source "$HOME/.local/bin/env" uv venv --python 3.12 --managed-python source .venv/bin/activate - Install SGLang:
uv pip install --prerelease=allow sglang. The flag matters on uv older than 0.12.0, which otherwise silently installs the old 0.5.9 because some dependencies only publish pre-releases. - Start the server:
sglang serve Qwen/Qwen3-0.6B --host 0.0.0.0 --port 30000
sglang serve is the new launcher. The older form python -m sglang.launch_server --model-path ... still appears in many examples and accepts the same arguments.
Send Your First Request
SGLang serves an OpenAI-compatible API. Use the same model ID you launched:
curl http://localhost:30000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen3-0.6B",
"messages": [{"role": "user", "content": "What is the capital of France?"}]
}'
The answer is in choices[0].message.content. From Python, point the OpenAI SDK at the server:
from openai import OpenAI
client = OpenAI(base_url="http://localhost:30000/v1", api_key="none")
r = client.chat.completions.create(
model="Qwen/Qwen3-0.6B",
messages=[{"role": "user", "content": "Explain RadixAttention in one line"}],
)
print(r.choices[0].message.content)
To chat in a browser, add the server to Open WebUI as an OpenAI connection with the URL http://your-server:30000/v1. Our Open WebUI models guide shows where to add it.
Key Server Arguments
| Argument | What it does |
|---|---|
--host, --port |
Bind address and port. Host defaults to 127.0.0.1; port 30000 in the docs |
--api-key |
Require a key. Set it before binding to 0.0.0.0 |
--served-model-name |
The model name clients send |
--context-length |
Maximum context length |
--tp (--tp-size) |
Tensor parallel across GPUs |
--dp |
Data parallel replicas for throughput |
--mem-fraction-static |
Share of GPU memory for weights plus KV cache |
--chunked-prefill-size |
Prefill chunk size; lower saves memory on long prompts |
--max-running-requests |
Cap concurrent requests |
--quantization fp8 |
Quantize FP16 weights to FP8 on load |
--kv-cache-dtype fp8_e4m3 |
FP8 KV cache to fit longer contexts |
--reasoning-parser, --tool-call-parser |
Split thinking and parse tool calls for the model family |
--enable-metrics |
Prometheus metrics |
--config config.yaml |
Load arguments from a YAML file; CLI flags override it |
A YAML config keeps long commands tidy:
model-path: Qwen/Qwen3-8B
host: 0.0.0.0
port: 30000
tensor-parallel-size: 2
enable-metrics: true
The SGLang Cookbook lists verified launch commands per model and GPU, which is the fastest way to get flags right for a new model.
Use Multiple GPUs
- Tensor parallel splits one model across GPUs, for models too big for one card:
sglang serve Qwen/Qwen3-32B --tp 2 - Data parallel runs copies for more throughput when the model fits on one GPU:
--dp 2. You can combine them:--dp 2 --tp 2uses four GPUs. - If you see
peer access is not supported between these two devices, add--enable-p2p-check. This is common on consumer cards without NVLink. - Pick GPUs with
CUDA_VISIBLE_DEVICES=0,1.
Tune Memory and Throughput
SGLang plans memory as weights + KV cache pool + CUDA graph buffers + activations. --mem-fraction-static sets how much of the GPU goes to weights plus KV cache.
- Find the log line just before the server is ready. It shows
max_total_num_tokens,context_lenandavailable_gpu_mem. - Aim for 5 to 8 GB of available memory for activations. If it shows 10 to 20 GB, raise
--mem-fraction-staticfor a bigger KV cache. If it is very low, lower it to avoid OOM later. - Adjust in steps of 0.01 until you find the highest value that stays stable under your workload.
- Watch the decode log under load.
token usageabove 0.9 means good KV use. If it stays low while requests queue, lower--schedule-conservativenessto about 0.3.
On a single 16 GB or 24 GB card, FP8 weights (--quantization fp8) and an FP8 KV cache can double how much fits. Check the quantization docs for which methods your GPU supports; for example, plain gptq is removed on NVIDIA in favor of gptq_marlin.
Structured Output
SGLang can constrain output to a JSON schema, a regular expression or an EBNF grammar. The default backend is XGrammar; you can switch with --grammar-backend outlines or --grammar-backend llguidance.
r = client.chat.completions.create(
model="Qwen/Qwen3-8B",
messages=[{"role": "user", "content": "Give me a city and its country as JSON"}],
response_format={
"type": "json_schema",
"json_schema": {"name": "place", "schema": {
"type": "object",
"properties": {"city": {"type": "string"}, "country": {"type": "string"}},
"required": ["city", "country"]}},
},
)
XGrammar’s EBNF uses the same GBNF format as llama.cpp, so grammars from our llama.cpp JSON output guide carry over.
Use SGLang With Claude Code
Every SGLang server also exposes an Anthropic-compatible /v1/messages endpoint, with no extra flag. That means Claude Code can use your local model. Launch the model with its reasoning and tool-call parsers, then set these before starting claude:
export ANTHROPIC_BASE_URL="http://127.0.0.1:30000"
export ANTHROPIC_AUTH_TOKEN="dummy"
export API_TIMEOUT_MS="3000000"
export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1
export CLAUDE_CODE_ATTRIBUTION_HEADER=0
The SGLang docs say CLAUDE_CODE_ATTRIBUTION_HEADER=0 is needed for good prefix-cache reuse. Local models are far weaker than Claude at agentic coding, so test on small tasks first. For more on these variables, see our Claude Code environment variables guide and running Claude Code with local models.
Troubleshooting
CUDA out of memory
If it happens during prefill, lower --chunked-prefill-size to 4096 or 2048. During decoding, lower --max-running-requests. In both cases you can lower --mem-fraction-static to 0.8 or 0.7.
CUDA_HOME or nvcc not found
The pip install needs the full CUDA 13 Toolkit. Install it, set CUDA_HOME and add its bin to PATH. Or use Docker.
Missing Python.h
Your Python lacks development headers. Use uv’s managed Python or install python3.12-dev.
uv installed SGLang 0.5.9
Add --prerelease=allow or upgrade uv to 0.12.0 or newer.
Illegal memory access
Often a disguised OOM. Apply the memory fixes above; if it persists, report it on GitHub with your launch command.
The server hangs at startup
Check avail mem in the log. If it is very low, decrease --mem-fraction-static, --cuda-graph-max-bs-decode or --chunked-prefill-size. In Docker, make sure you passed --ipc=host or a large --shm-size.
Different answers at temperature 0
Dynamic batching and prefix caching cause small differences. Add --enable-deterministic-inference for repeatable output.
FAQ
Is SGLang faster than vLLM?
It depends on the model and workload. SGLang is especially strong with shared prefixes, agents and structured output. Benchmark both on your own traffic.
Does SGLang work on Windows?
The official instructions target Linux. On Windows, use WSL 2 with Docker and NVIDIA GPU support, or choose Ollama or llama.cpp.
Can SGLang run GGUF models?
SGLang is built around Hugging Face weights and GPU quantization formats like FP8, AWQ and GPTQ. For GGUF, llama.cpp or Ollama is the better fit.
What port does SGLang use?
The docs use port 30000. Set it with --port, and bind with --host 0.0.0.0 to accept other machines.
Does SGLang still support CUDA 12?
No. Current releases need CUDA 13. Version 0.5.19 was the last with CUDA 12.
What is the difference between sglang serve and launch_server?
sglang serve is the newer command. python -m sglang.launch_server is the older entry point found in many guides. Both take the same server arguments.



