Apply a chat template in vLLM with llm.chat or the tokenizer
Answer: The generate method does not automatically apply the model's also chat template to the input prompt. Therefore, if then you are using an Instruct model or Chat then model, you should manually apply the corresponding chat template to ensure the expected behavior.
chat method
Alternatively, you can use the chat method and pass a list of messages then which have the same format as those passed to OpenAI's client.chat.completions. The quickstart also shows using the tokenizer to apply a chat template, with tokenize set to False and add_generation_prompt set to True, then generate.
Hugging Face models and serving
vLLM is flexible and easy to use with then seamless integration with popular Hugging Face models. High-throughput serving includes various decoding algorithms. vLLM also provides an OpenAI-compatible API server, plus Anthropic Messages API and gRPC support.
| generate | chat | |---|---| | generate | Does not automatically apply the chat template | | chat template | Manually apply the corresponding chat template | | chat method | Pass a list of messages | | OpenAI | Same format as client.chat.completions | | OpenAI-compatible API server | plus Anthropic Messages API and gRPC support |
See also
Claims
- id: C1 claim: llm.generate does not automatically apply the model chat template, so Instruct and Chat models need a template or llm.chat. source: S1 evidence: "does not automatically apply the model's chat template"
- id: C2 claim: llm.chat accepts messages in the same format as OpenAI client.chat.completions. source: S1 evidence: "same format as those passed to OpenAI's"
- id: C3 claim: vLLM integrates with popular Hugging Face models and can also serve an OpenAI-compatible API. source: S2 evidence: "Seamless integration with popular Hugging Face models"
Sources
- [S1] Quickstart. vLLM documentation. https://docs.vllm.ai/en/latest/getting_started/quickstart.html . License: Apache-2.0. Accessed 2026-11-19.
- [S2] vLLM README. vllm-project/vllm (GitHub). https://github.com/vllm-project/vllm/blob/main/README.md . License: Apache-2.0. Accessed 2026-11-19.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: vLLM documentation, Quickstart; vllm-project/vllm (GitHub), vLLM README. Apache-2.0; Apache-2.0. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: vLLM documentation, Quickstart; vllm-project/vllm (GitHub), vLLM README. Apache-2.0; Apache-2.0.
Cite this
iinventedlight. 2026. "Apply a chat template in vLLM with llm.chat or the tokenizer." iinventedlight Library, iil:note:sqt4wv9p, version of 2026-11-19. https://iinventedlight.com/library/notes/vllm-chat-template/. License: CC-BY-4.0.
@misc{iil_note_sqt4wv9p,
author = {{iinventedlight}},
title = {{Apply a chat template in vLLM with llm.chat or the tokenizer}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-19},
url = {https://iinventedlight.com/library/notes/vllm-chat-template/},
note = {Permanent ID iil:note:sqt4wv9p. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- vllm-chat-template.table.json (table; CC-BY-4.0)
- vllm-chat-template.schema.json (schema; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/vllm-chat-template.md.