Serving an Open-Weight Model with vLLM's OpenAI-Compatible API
You have code written against the OpenAI SDK and a GPU box, and you'd like to run an open-weight model without rewriting the client. That's the job vLLM does best: one command starts a server that speaks the OpenAI API, and your existing code only needs a different base_url.
This walkthrough goes from install to an authenticated endpoint your app can call, using the vLLM docs as of November 2026. If you only want a model on your laptop for tinkering, Ollama is usually the easier pick; our local LLM guide compares the options. vLLM is for when you're serving real traffic from a GPU.
Check the machine first
The quickstart lists the requirements: Linux, Python 3.11 to 3.14, and a supported accelerator. NVIDIA GPUs install straight from pip or uv. AMD needs ROCm 7.0, Python 3.14 and glibc 2.35 or newer, and installs from vLLM's own wheel index. Intel GPUs, Google TPUs and Ascend NPUs have separate guides, and the page notes Apple Silicon runs through a separate vLLM-Metal project.
The recommended NVIDIA install, verbatim from the quickstart:
uv venv --python 3.14 --seed
source .venv/bin/activate
uv pip install vllm --torch-backend=auto
vllm download-kernels
Use exactly these lines rather than a bare pip install from memory; the install steps have changed across releases.
Start the server
vllm serve Qwen/Qwen2.5-1.5B-Instruct
That's the quickstart's example model, small enough to start on most GPUs. vLLM downloads the weights from Hugging Face on first run and listens on http://localhost:8000 by default; --host and --port change that. To pull from ModelScope instead, the quickstart says to set VLLM_USE_MODELSCOPE=True before starting.
Check it's up:
curl http://localhost:8000/v1/models
Call it from code you already have
The OpenAI-compatible server page shows the client side. Point the official SDK at your server:
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="token-abc123",
)
completion = client.chat.completions.create(
model="Qwen/Qwen2.5-1.5B-Instruct",
messages=[
{"role": "user", "content": "Classify this sentiment: vLLM is wonderful!"},
],
)
print(completion.choices[0].message.content)
The model must match the name the server was started with. That's the most common first error: code still says the hosted model name, the server only knows the Hugging Face ID.
Or with plain curl, as in the quickstart:
curl http://localhost:8000/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{
"model": "Qwen/Qwen2.5-1.5B-Instruct",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"}
]
}'
Our curl for API testing post has the flags worth knowing when you start timing these requests.
What "OpenAI-compatible" covers
The online serving index lists the endpoints. The ones most apps use:
| Endpoint | Use |
|---|---|
/v1/chat/completions | chat models, the one you'll use most |
/v1/completions | raw text completion |
/v1/responses | the Responses API shape |
/v1/embeddings | embedding models |
/v1/models | list what's loaded |
/health, /metrics | load balancer checks and monitoring |
The same page also lists Anthropic-style /v1/messages, rerank and scoring endpoints, audio transcription, and tokenizer endpoints. Not every endpoint works with every model: an embedding endpoint needs an embedding model.
Compatibility has edges. vLLM accepts some sampling parameters that OpenAI doesn't, and the docs say to pass those through extra_body, for example extra_body={"top_k": 50}. In the Python SDK that looks like this:
completion = client.chat.completions.create(
model="Qwen/Qwen2.5-1.5B-Instruct",
messages=[{"role": "user", "content": "Name three prime numbers."}],
extra_body={"top_k": 50},
)
Keep these extras in one place in your code, though. If you later switch the same code back to a hosted provider, an unknown parameter is exactly the kind of thing that gets rejected.
Message formats have a wrinkle too. OpenAI's API lets content be a plain string or a list of typed parts, and chat templates differ in which they expect. The serving page says vLLM detects which format a template wants and converts automatically, and that you can override the detection with --chat-template-content-format if it guesses wrong. Going the other way, assume a hosted-only OpenAI feature isn't there until you've checked the docs.
The two settings that surprise people
Chat templates. A chat endpoint needs the model's chat template to turn messages into a prompt. The serving docs are blunt: without one, the server can't process chat and every chat request errors. Most instruct models ship a template in their tokenizer config. If yours doesn't, pass one with --chat-template ./path-to-chat-template.jinja.
Default sampling parameters. By default vLLM applies the model's generation_config.json from its Hugging Face repo, which can override sampling defaults like temperature. If your outputs look different from what the same model gives elsewhere, that's a likely reason. Start the server with --generation-config vllm to turn that off and use vLLM's own defaults.
Put a lock on it
The OpenAI-compatible page's example adds two flags:
vllm serve NousResearch/Meta-Llama-3-8B-Instruct \
--dtype auto \
--api-key token-abc123
--api-key (or the VLLM_API_KEY environment variable) makes the server require that key. The quickstart says multiple keys are accepted, which helps with rotation. But read the warning on the serving page: the key only authenticates some endpoints, and the docs say outright not to rely on --api-key alone to secure vLLM. /health and /health_generate aren't covered, for instance.
In practice that means:
- Bind to localhost or a private network, not
0.0.0.0on a public IP. - Put a reverse proxy in front for TLS and real auth. If you're on a single VPS, our Hetzner deployment guide shows the Caddy pattern, and the VPS hardening checklist covers the firewall side.
- Never enable development mode (
VLLM_SERVER_DEV_MODE=1) on anything reachable; the docs mark its endpoints as not for production.
Is self-hosting worth it
Honest answer: it depends on utilisation. A GPU you pay for by the hour costs the same whether it's serving requests or idle, while hosted APIs charge per token. If your traffic is bursty or small, an inference provider is often cheaper and certainly simpler; see LLM inference providers compared. Self-hosting with vLLM makes sense when you need a specific open-weight model, data can't leave your network, or traffic is steady enough to keep the GPU busy.
Before you point production at it:
- Start the exact model you'll ship and confirm
/v1/modelslists it. - Run your real prompts and compare against your current provider.
- Decide on
--generation-config vllmor the model's defaults, on purpose. - Lock the network down; treat
--api-keyas one layer, not the wall. - Scrape
/metricsfrom day one so you can see GPU queueing before users do.
Written by AIDToolStack Editorial
Researched from official documentation, specifications and vendor pages, listed under Sources below. Last checked November 2026.