How to Serve an Open Model with vLLM in 30 Minutes
Why vLLM instead of a chat app
If you have already run a model on your own machine — for example with the Ollama setup in our earlier tutorial — the next step is sharing it with real software. A chat window serves one person; an API serves every app, script, and teammate you point at it. vLLM loads one open-weight model onto your GPU and exposes it behind an API that speaks the same protocol as OpenAI's, so existing tools work with only a changed base URL.
This tutorial takes you from an empty environment to a working server running Qwen3-8B, an 8.2-billion-parameter open model with a native 32,768-token context. You will verify the server with a small model first, then swap in the real one, call it from curl and Python, and lock it down with an API key.
![]() |
| Source: NewsCarpenter illustration. A client app talks to the vLLM server's OpenAI-compatible API, </i>which runs the model on the GPU. |
What you need before you start
vLLM is a serving engine, not a desktop chat app. The official quickstart lists Linux and Python 3.11 to 3.14, and in practice you want a real NVIDIA GPU: the CUDA build is the well-trodden path.
- GPU: one NVIDIA card with enough VRAM. Qwen3-8B's weights alone need roughly 16 GB in bfloat16 (8.2B x 2 bytes), plus room for the KV cache. A 24 GB card is comfortable.
- Disk: at least 30 GB free. The 8B weights are about 16 GB, and the install pulls large CUDA packages.
- Software: Python 3.12,
uv(the environment manager the vLLM docs recommend), and a healthy GPU, confirmed with:
nvidia-smi No GPU, or only a small one? Serve the tiny smoke-test model in Step 2 and stop there, or stay with Ollama on CPU. vLLM earns its keep when concurrent requests arrive.
Step 1: Install vLLM in a clean environment
Never install vLLM into your system Python: it bundles its own PyTorch and CUDA kernels, and mixing them with an existing install causes strange errors. Create a dedicated environment:
uv venv --python 3.12 --seed source .venv/bin/activate uv pip install vllm --torch-backend=auto vllm download-kernels The --torch-backend=auto flag picks the PyTorch build matching your CUDA driver. Verify the install:
python -c "import vllm; print(vllm.__version__)" vllm serve --help | head -n 40 Step 2: Smoke-test the server with a small model
Start with Qwen2.5-1.5B-Instruct from the official quickstart, so a failure is cheap to diagnose. Run the server in one terminal and leave it there:
vllm serve Qwen/Qwen2.5-1.5B-Instruct Once it reports running on port 8000, list the models from a second terminal:
curl http://localhost:8000/v1/models If that returns JSON naming your model, ask it something:
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "Qwen/Qwen2.5-1.5B-Instruct", "messages": [{"role": "user", "content": "Tell me a joke."}]}' Stop this server with Ctrl+C once the smoke test passes.
Step 3: Serve Qwen3-8B
Qwen3-8B has 36 layers and a native 32,768-token context, per its Hugging Face model card. It also has a thinking mode: by default it reasons inside a <think> block before answering. The model card's deployment example enables reasoning support in vLLM, and this tutorial follows it:
vllm serve Qwen/Qwen3-8B \ --enable-reasoning --reasoning-parser deepseek_r1 \ --host 127.0.0.1 --port 8000 \ --api-key change-me-to-a-long-random-secret Binding to 127.0.0.1 keeps the server reachable only from your own machine. The --api-key flag makes it require that key in an Authorization: Bearer header, so nothing else on your network can burn your GPU. And --enable-reasoning with the deepseek_r1 parser surfaces the thinking trace as a separate reasoning_content field instead of mixing it into the answer.
First startup downloads about 16 GB of weights. Confirm the server with the key:
curl http://localhost:8000/v1/models -H "Authorization: Bearer change-me-to-a-long-random-secret" Step 4: Call it from curl and Python
Chat completions work exactly like the OpenAI API:
curl http://localhost:8000/v1/chat/completions -H "Content-Type: application/json" -H "Authorization: Bearer change-me-to-a-long-random-secret" -d '{"model": "Qwen/Qwen3-8B", "messages": [{"role": "user", "content": "Explain PagedAttention in two sentences. /no_think"}], "temperature": 0.7, "top_p": 0.8, "max_tokens": 200}' The /no_think suffix is Qwen3's soft switch: it disables thinking for that turn, which suits short factual answers. For hard reasoning, leave it off and use the card's thinking-mode sampling (temperature 0.6, top_p 0.95, top_k 20); never use greedy decoding in thinking mode, which the card warns causes degradation and repetition.
In Python, only the base URL changes:
from openai import OpenAI client = OpenAI(base_url="http://localhost:8000/v1", api_key="change-me-to-a-long-random-secret") response = client.chat.completions.create(model="Qwen/Qwen3-8B", messages=[{"role": "user", "content": "Write a haiku about a GPU. /no_think"}], temperature=0.7, max_tokens=100) print(response.choices[0].message.content) This drop-in compatibility is the real payoff: any tool that talks to OpenAI can now talk to your local model. Open-weight decision models for agents are one example of what teams build on a self-hosted endpoint like this.
Step 5: Tune for your workload
Two knobs matter first. For long documents, Qwen3 supports up to 131,072 tokens with YaRN rope scaling, enabled with --rope-scaling '{"rope_type":"yarn","factor":4.0,"original_max_position_embeddings":32768}' plus --max-model-len 131072 — only when you genuinely need long context, since static YaRN scaling can slightly hurt short-text quality. Second, by default vLLM applies the sampling defaults from the model's own generation_config.json; add --generation-config vllm to force vLLM's defaults instead.
Beyond your own machine, put a reverse proxy with TLS in front of vLLM, rotate the API key, and never expose port 8000 directly. vLLM is an inference engine, not a hardened public gateway.
Troubleshooting
- Out of memory on startup. The 8B weights plus KV cache exceed your VRAM. Go back to the 1.5B model, shorten the context with
--max-model-len 4096, or use a quantized checkpoint. - Port 8000 already in use. An old server is still running. Stop it, or pick another port with
--port 8001. - 401 or empty replies. You started the server with
--api-keybut forgot theAuthorization: Bearerheader. The key must match exactly. - Endless repetition in thinking mode. You are probably using greedy decoding (temperature 0). Use the thinking-mode sampling above: temperature 0.6, top_p 0.95, top_k 20.
Where to go next
You now have a private, OpenAI-compatible endpoint running an open model on your own GPU. Point a chat UI at it, or wire it into an agent or retrieval pipeline.

Comments
Post a Comment