← All notes

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

Sources

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

Permanent ID: iil:note:sqt4wv9p

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.},
}

Markdown

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.

All artifact files (JSON index)

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.