vLLM OpenAI Compatible API: Self-Host or Use Hosted
vLLM can serve any supported open-weight model over the same HTTP routes the OpenAI SDK expects. This guide shows the server command, the client code, the pitfalls, and the point where a hosted endpoint is the easier choice.
Key points
- vllm serve starts an OpenAI-style server with /v1/chat/completions and /v1/models on port 8000 by default.
- Client code only needs a base URL, a key and a model name, so the same script works against local vLLM or a hosted endpoint.
- Self-hosting means you own GPU memory, tool-call parsers, concurrency tuning and updates.
- The hosted option here uses model ID uncensored at $0.15 per 1M input and $0.50 per 1M output tokens.

What the vLLM OpenAI-compatible server actually is
The short version of the vllm openai compatible api question: vLLM is an inference engine, and it includes a web server that copies the routes and JSON shapes of the OpenAI API. You start it with one command, it loads a model onto your GPU, and from then on any client that can talk to OpenAI can talk to your machine instead. The routes you care about are POST /v1/chat/completions, POST /v1/completions and GET /v1/models.
That compatibility is the whole point. Your application does not import anything from vLLM. It uses the normal OpenAI SDK, LangChain, a roleplay front end or plain curl, and the only things that change are the base URL, the API key and the model name. This is also why you can move between a local server and a hosted one without rewriting code, which the later sections use.
Before you start, be clear about what you are signing up for. vLLM does not include a model. You pick an open-weight model from a public model hub, check its licence, and make sure it fits in your GPU memory. Weights for a mid-size model can take tens of gigabytes, and the server also reserves memory for the key-value cache that holds each active conversation. If the weights alone fill the GPU, there is no room left for requests.
Start the server
Install vLLM into a clean Python environment on a machine with a supported GPU and recent drivers, then launch the server. Replace YOUR_MODEL with the Hugging Face repository name of a model you are allowed to use.
pip install vllm
vllm serve YOUR_MODEL \
--host 0.0.0.0 \
--port 8000 \
--api-key local-secret \
--max-model-len 16384 \
--gpu-memory-utilization 0.90
Each flag earns its place. --api-key makes the server require an Authorization: Bearer header; without it, anyone who can reach the port can use your GPU. --max-model-len caps the context length, and lowering it is the quickest way to free memory when the server fails to start with an out-of-memory error. --gpu-memory-utilization sets the share of GPU memory vLLM may claim. On a machine with several GPUs you add --tensor-parallel-size 2 (or the number you have) to split the model across them.
The first launch downloads the weights, so expect a wait. When the log says the application startup is complete, check the server from another terminal:
curl http://localhost:8000/v1/models \
-H "Authorization: Bearer local-secret"
The response lists the model name the server exposes. Copy that string exactly; it is the value your clients must send as model. A mismatch here is the most common reason for a 404 on the first request.
Call it with the OpenAI SDK
The script below reads its settings from environment variables. By default it points at the hosted endpoint with model uncensored. To run it against your own vLLM server, set the three variables shown in the comment.
import os
from openai import OpenAI
# Local vLLM: export LLM_BASE_URL=http://localhost:8000/v1
# export LLM_API_KEY=local-secret
# export LLM_MODEL=YOUR_MODEL
client = OpenAI(
base_url=os.environ.get("LLM_BASE_URL", "https://api.qwencoder.top/v1"),
api_key=os.environ.get("LLM_API_KEY", "YOUR_API_KEY"),
)
resp = client.chat.completions.create(
model=os.environ.get("LLM_MODEL", "uncensored"),
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain what a KV cache is in two sentences."},
],
temperature=0.7,
stream=False,
)
print(resp.choices[0].message.content)
print(resp.usage)
Streaming works the same way on both sides: pass stream=True and iterate over the chunks. The same goes for plain curl:
curl https://api.qwencoder.top/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "uncensored",
"messages": [{"role": "user", "content": "Say hello in five words."}],
"stream": true
}'Tool calling and JSON output on a self-hosted server
Plain chat is easy. Structured features take more care. In vLLM, tool calling is not on by default: you start the server with --enable-auto-tool-choice and a --tool-call-parser that matches the model family, because each family writes tool calls in its own text format and the parser turns that text back into the tool_calls field. Pick the wrong parser and the model will emit tool calls that your client sees as ordinary text.
JSON output is similar. vLLM supports constrained decoding for JSON through the OpenAI-style response_format field, but the details depend on the version you installed, so test with your own schema before you depend on it. Read the release notes when you upgrade; these options have changed names and behaviour between versions.
On the hosted endpoint you do not manage any of this. Tool calling (tools, tool_choice, streamed tool_calls, results sent back as role: "tool") and JSON mode (response_format: {"type":"json_object"}) are part of the service. The API docs list the supported parameters, and temperature, top_p, stop, seed and the penalties are passed through to the model.
Self-hosting or hosted: how to decide
Neither option wins in general. The table compares the points that actually change your week.
| Question | Your own vLLM server | Hosted endpoint (this site) |
|---|---|---|
| Hardware | You buy or rent GPUs and keep drivers working | None; you send HTTPS requests |
| Model choice | Any model you can fit and are licensed to run | One model, ID uncensored |
| Cost shape | Fixed hardware or rental cost, whether used or idle | $0.15 per 1M input, $0.50 per 1M output, prepaid |
| Context window | You choose it, limited by memory | 100,000 tokens, prompt plus completion |
| Concurrency | Whatever your GPU memory and batch settings allow | 8 at once and 300 per minute on a full key |
| Upgrades | Yours: vLLM versions, parsers, model revisions | Handled by the provider |
| Control | Total, including custom weights and fine-tunes | Text chat only; no fine-tuning |
Run vLLM yourself when you need a specific model, a fine-tune, an air-gapped setup, or when your volume is high and steady enough that owned hardware stays busy. Use a hosted endpoint when your traffic is bursty, when you are still prototyping, or when nobody on the team wants to be on call for a GPU box. Many teams do both: a hosted key for development and a local server for one workload that needs custom weights.
If you want numbers for the hosted side, the pricing page has the per-token rates and top-up rules. A request with 2,000 input tokens and 500 output tokens costs $0.0003 plus $0.00025, which is $0.00055.
Point your existing vLLM client at the hosted API
If you already wrote code against a local vLLM server, moving it is three changes: the base URL, the key and the model name. With the OpenAI SDK you can even skip code edits by using environment variables, since the Python and Node SDKs read OPENAI_BASE_URL and OPENAI_API_KEY.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.qwencoder.top/v1",
apiKey: process.env.API_KEY,
});
const stream = await client.chat.completions.create({
model: "uncensored",
messages: [{ role: "user", content: "List three uses of a KV cache." }],
stream: true,
stream_options: { include_usage: true },
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}
To get a key, sign up on the API key page with Google or with email and password. New users can claim $0.50 of trial credit with one click there; it needs no payment method, lasts 7 days and is limited to one per person. Trial keys run at 2 concurrent requests and 60 requests per minute. Full keys get 8 concurrent and 300 per minute. Top-ups on this site are paid by crypto (USDT on TRC20, USDC on Base), in whole amounts from $20 to $500.
One difference to plan for: a hosted service enforces limits that your own server does not. Over a limit you get HTTP 429 with the code rate_limited or concurrency, and during temporary overload a 429 with a Retry-After: 5 header. A streamed request holds its concurrency slot until the stream ends, so a stuck stream counts against you. Add a retry with a short sleep and cap your worker pool at eight.
Troubleshooting the usual failures
404 on /v1/chat/completions
Check that the base URL ends in /v1 and that you did not add the path twice. The SDK appends /chat/completions itself. On local vLLM, also verify the model name against /v1/models.
401 or 403
The key in the Authorization: Bearer header does not match. For local vLLM it must equal the --api-key value. For the hosted API, copy the key again from your account and make sure no whitespace came along.
Out-of-memory when vLLM starts
Lower --max-model-len, lower --gpu-memory-utilization slightly, choose a smaller or quantised model, or add GPUs with --tensor-parallel-size. Close other processes that hold GPU memory first.
Requests hang under load
Locally, you have more concurrent requests than the KV cache can hold, so the server queues them. Hosted, you may be at the concurrency cap. In both cases put a limiter in your client rather than firing every request at once.
More guides
Questions and answers
Does vLLM provide an OpenAI-compatible API out of the box?
Yes. Running vllm serve starts an HTTP server with OpenAI-style routes such as /v1/chat/completions and /v1/models, so the standard OpenAI SDKs work after you change the base URL.
Do I need a GPU to use an OpenAI-compatible API?
Only if you run the model yourself. A hosted endpoint speaks the same protocol, and you only send HTTPS requests from any machine.
Which model name should I send to the hosted API here?
Send uncensored as the model value, with the base URL https://api.qwencoder.top/v1 and your key in the Authorization header.
Is the hosted API the same as running vLLM?
No. It is a managed service that runs one open-weight model for you. You get the same request format but no control over the model, weights or server flags.
Your key is one form away
Create an account, copy the key, change the base URL. That is the whole setup.