vLLM’s offline API has two ways to generate: llm.generate takes raw prompt strings, and llm.chat takes message lists in the same shape as the OpenAI chat API. Use llm.chat when your inputs are conversations, because it applies the model’s chat template for you instead of leaving that to your code.
Build message lists and call llm.chat
Create the engine once with LLM(model="Qwen/Qwen2.5-1.5B-Instruct") and a SamplingParams object, for example temperature 0.8 and top_p 0.95. Build one list of messages per conversation — each a list of {"role": ..., "content": ...} dicts — and pass the whole list to llm.chat. The outputs come back as RequestOutput objects in the same order, and each reply text is at output.outputs[0].text.
from vllm import LLM, SamplingParams
llm = LLM(model="Qwen/Qwen2.5-1.5B-Instruct")
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
messages_list = [[{"role": "user", "content": "Tell me a joke."}]]
outputs = llm.chat(messages_list, sampling_params)
print(outputs[0].outputs[0].text)
Note the contrast the docs draw: llm.generate does not automatically apply the model’s chat template, so an instruct model fed through generate needs the template applied by hand with a tokenizer. llm.chat does that step for you. By default the server also applies generation_config.json from the model repository unless you pass generation_config="vllm" when creating the engine.
Try it: four checks
| Check | What you should see | If you do not see it |
|---|---|---|
| Engine loads | LLM(model=…) finishes loading the model | Check the model name and the GPU memory |
| Outputs ordered | One output per message list, in order | Count the outputs against the inputs |
| Reply text present | outputs[0].outputs[0].text holds the reply | Read the RequestOutput shape in the docs |
| Template applied | The reply reads like a chat answer, not a raw completion | Use llm.chat, not llm.generate, for chats |
Expected result. We checked the vLLM Quickstart, which gives the LLM and SamplingParams imports, the temperature 0.8 and top_p 0.95 example, the llm.chat call with message lists, the outputs[0].outputs[0].text field, and the note that llm.generate does not apply the chat template. We did not run vLLM on this machine.
Limits
This guide covers offline chat batching only. Online serving through vllm serve is a separate setup, and sampling parameters can also come from the model’s generation_config.json. We did not test the code ourselves.
![Schematic diagram with four steps: create the LLM engine once, build one message list per conversation, call llm.chat on the whole batch, then read each reply from outputs[0].outputs[0].text.](https://newtoolradar.com/wp-content/uploads/2026/11/run-vllm-chat-offline-llm-chat-method-1024x700.png)