How to run vLLM as an OpenAI-compatible server (and swap it into your app)

TechTech

How to run vLLM as an OpenAI-compatible server (and swap it into your app)

Colorful code on a terminal screen above a backlit keyboard
Photo by Markus Spiske on Pexels

vLLM can serve open models behind the same API shape as OpenAI. Here's the quickstart, how to point your app at it, and the security catch in the docs.

In this article
  1. What "OpenAI-compatible" means
  2. Step 1: install
  3. Step 2: start the server
  4. Step 3: point your app at it
  5. The security catch most tutorials skip
  6. Will my GPU fit the model?

If your app already talks to the OpenAI API, you can often point it at your own model with one changed line. vLLM is the most common way to do that. Here's the short version, based on vLLM's own docs.

What "OpenAI-compatible" means

vLLM provides an HTTP server that implements OpenAI's API. Same paths, same request and response shape. Your code sends the same JSON; it just goes to your server instead.

Supported endpoints include:

  • /v1/chat/completions and /v1/completions
  • /v1/responses
  • /v1/embeddings
  • /v1/audio/transcriptions and /v1/audio/translations

Not every model supports every endpoint. Chat needs a model with a chat template, for example.

Step 1: install

The quickstart targets Linux and Python 3.11 to 3.14, and recommends uv:

uv venv --python 3.12 --seed
source .venv/bin/activate
uv pip install vllm --torch-backend=auto

The docs also list AMD, Intel, Google TPU and Ascend options, and vLLM-Metal for Apple Silicon Macs.

Step 2: start the server

vllm serve Qwen/Qwen2.5-1.5B-Instruct

By default it listens on http://localhost:8000. Use --host and --port to change that. The server hosts one model at a time. Models download from Hugging Face by default.

Check it's up:

curl http://localhost:8000/v1/models

Step 3: point your app at it

With the official OpenAI Python client, it's just the base URL and key, as in vLLM's docs:

from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8000/v1",
    api_key="token-abc123",
)

completion = client.chat.completions.create(
    model="NousResearch/Meta-Llama-3-8B-Instruct",
    messages=[{"role": "user", "content": "Hello!"}],
)
print(completion.choices[0].message)

For that example, the docs start the server with vllm serve NousResearch/Meta-Llama-3-8B-Instruct --dtype auto --api-key token-abc123.

Already using a gateway? The same idea works behind a proxy layer. (If you use LiteLLM, read our LiteLLM supply-chain post first.)

The security catch most tutorials skip

vLLM's docs put this in a warning box: "Do not rely on --api-key alone to secure vLLM."

The --api-key flag (or VLLM_API_KEY) only checks requests under /v1, /v2 and /inference. Other endpoints on the same server, notably /invocations, aren't authenticated and expose the same inference. The docs recommend hardening like a reverse proxy.

Practical rules:

  • Bind to localhost or a private network.
  • Put a reverse proxy with real auth in front if anything outside needs access.
  • Treat the server like a database: not on the public internet.

Our vibe-coding security checklist covers the same habits for the rest of your stack.

Will my GPU fit the model?

That's the real limit. See how much VRAM you need, or rent a GPU if yours is too small. Big models on small machines are a different game; see running a model bigger than your RAM.

FAQ

What is vLLM?

An open-source engine for running large language models with high throughput. It can run offline batch jobs or serve models over HTTP.

Does vLLM work with the OpenAI Python SDK?

Yes. vLLM's docs show using the official OpenAI Python client with base_url set to http://localhost:8000/v1 and your own API key.

Is --api-key enough to secure vLLM?

No. vLLM's docs warn that --api-key only covers endpoints under /v1, /v2 and /inference. Others, including /invocations, aren't authenticated. Put it behind a reverse proxy.

What hardware does vLLM need?

The quickstart targets Linux with Python 3.11 to 3.14 and lists NVIDIA, AMD, Intel, Google TPU and Ascend options, plus vLLM-Metal for Apple Silicon. Your model also has to fit in GPU memory.

Sources

  1. vLLM docs, Quickstarthttps://docs.vllm.ai/en/stable/getting_started/quickstart/
  2. vLLM docs, OpenAI-Compatible Serverhttps://docs.vllm.ai/en/stable/serving/online_serving/openai_compatible_server/

Newsletter

The Codema publication. Consent is required. You are not subscribed until you confirm from the email, and nothing is stored if email delivery is not connected.