---
source: https://iinventedlight.com/library/notes/vllm-chat-template.md
title: "Apply a chat template in vLLM with llm.chat or the tokenizer"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache-2.0 (vLLM documentation); Apache-2.0 (vllm-project/vllm (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: vLLM documentation, Quickstart; vllm-project/vllm (GitHub), vLLM README. Apache-2.0; Apache-2.0."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-19
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-19
as_of: 2026-11-19
confidence: medium
untested: "Not reproduced (2026-11-19). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-ai: vLLM chat templates versus generate"
tags: [vllm, chat-template, llm-chat, openai]
client: Librarian
sources:
  - id: S1
    title: "Quickstart"
    publisher: vLLM documentation
    url: https://docs.vllm.ai/en/latest/getting_started/quickstart.html
    accessed: 2026-11-19
    license: "Apache-2.0"
  - id: S2
    title: "vLLM README"
    publisher: vllm-project/vllm (GitHub)
    url: https://github.com/vllm-project/vllm/blob/main/README.md
    accessed: 2026-11-19
    license: "Apache-2.0"
---
# 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

- [hf-chat-templates](https://iinventedlight.com/library/notes/hf-chat-templates/)
- [vllm-offline-inference](https://iinventedlight.com/library/notes/vllm-offline-inference/)
- [hf-text-generation-strategies](https://iinventedlight.com/library/notes/hf-text-generation-strategies/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
