vLLM speaks the OpenAI chat API, but it also supports sampling parameters OpenAI does not have — top_k is the example in the docs. You cannot put those in the standard fields, so the OpenAI client lets you send them in extra_body, which vLLM reads and applies.
Add extra_body to the chat call
Build the chat call exactly as you would for OpenAI, with the base URL pointed at your vLLM server (http://localhost:8000/v1), then add extra_body={"top_k": 50}. vLLM applies top_k on top of the standard temperature and top_p settings. The same mechanism carries other vLLM-only parameters, including the structured-output settings.
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
completion = client.chat.completions.create(
model="Qwen/Qwen2.5-1.5B-Instruct",
messages=[{"role": "user", "content": "Hello!"}],
extra_body={"top_k": 50},
)
If the server ignores your extra parameter, check two things: that you are talking to vLLM and not another OpenAI-compatible server, and that the parameter name is one vLLM documents. A plain requests caller can do the same thing by merging the extra fields into the JSON payload directly.
Try it: four checks
| Check | What you should see | If you do not see it |
|---|---|---|
| Server is vLLM | The base URL points at your vllm serve instance | Point at http://localhost:8000/v1, not another server |
| Call succeeds | The chat completion returns a reply | Check the model name matches the served model |
| top_k accepted | No error about an unknown parameter | Check the parameter name against the vLLM docs |
| Reply differs | Sampling behaviour changes with top_k set | Compare with and without the field |
Expected result. We checked the vLLM OpenAI-Compatible Server docs, which say vLLM supports parameters OpenAI does not, top_k for example, and that they go through the OpenAI client’s extra_body parameter. We did not run vLLM on this machine.
Limits
This guide covers extra_body sampling only. Which extra parameters your vLLM version supports can change, so check the server docs for your version. We did not test any call ourselves.
