Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

VLLMChatGenerator

Generate chat responses using models served with vLLM.

Key Features

  • Works with any model served by a vLLM server using the OpenAI-compatible API.
  • Accepts and returns messages in ChatMessage format.
  • Supports streaming responses through a configurable callback.
  • Supports tool calling for agentic workflows.
  • Supports reasoning models with the extra_body parameter.
  • Uses the OpenAI-compatible API, so the same component works with any vLLM-served model.

Configuration

  1. Drag the VLLMChatGenerator component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the model to the model name served by your vLLM instance (for example, Qwen/Qwen3-4B-Instruct).
    2. Set the api_base_url to your vLLM server address. The default is http://localhost:8000/v1.
  4. Go to the Advanced tab to configure generation_kwargs, timeout, max_retries, and tools.

Connections

VLLMChatGenerator receives a list of ChatMessage objects, typically from PromptBuilder or ChatPromptBuilder. It outputs a list of reply ChatMessage objects you can connect to AnswerBuilder or other downstream components.

Source Code

To check this component's source code, open chat_generator.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  VLLMChatGenerator:
type: haystack_integrations.components.generators.vllm.VLLMChatGenerator
init_parameters:
model: Qwen/Qwen3-4B-Instruct
api_base_url: http://localhost:8000/v1
generation_kwargs:
temperature: 0.7
max_tokens: 1024

Using the Component in a Pipeline

# haystack-pipeline
components:
prompt_builder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
required_variables: "*"
template:
- role: user
content: "Answer the following question: {{ question }}"

llm:
type: haystack_integrations.components.generators.vllm.VLLMChatGenerator
init_parameters:
model: Qwen/Qwen3-4B-Instruct
api_base_url: http://localhost:8000/v1
generation_kwargs:
max_tokens: 1024

answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters:
reference_pattern: acm

connections:
- sender: prompt_builder.prompt
receiver: llm.messages
- sender: llm.replies
receiver: answer_builder.replies

max_runs_per_component: 100

metadata: {}

inputs:
query:
- answer_builder.query
- prompt_builder.question

outputs:
answers: answer_builder.answers

Parameters

Inputs

ParameterTypeDescription
messagesList[ChatMessage]A list of chat messages representing the conversation so far.

Outputs

ParameterTypeDescription
repliesList[ChatMessage]A list of generated reply messages from the model.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstr(required)The name of the model served by the vLLM instance.
api_keyOptional[Secret]Secret.from_env_var("VLLM_API_KEY", strict=False)An API key for authenticated vLLM deployments.
streaming_callbackOptional[Callable]NoneA callback function for streaming responses.
api_base_urlstrhttp://localhost:8000/v1The URL of the vLLM server's OpenAI-compatible API.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional generation parameters such as temperature, max_tokens, and top_p.
timeoutOptional[float]NoneRequest timeout in seconds.
max_retriesOptional[int]NoneMaximum number of retries on API errors.
toolsOptional[List[Tool]]NoneA list of tools the model can use for tool calling.
http_client_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the HTTP client.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
messagesList[ChatMessage]A list of chat messages representing the conversation.
streaming_callbackOptional[Callable]NoneA callback function to override the init-time streaming callback.
generation_kwargsOptional[Dict[str, Any]]NoneGeneration parameters to override init-time values.
toolsOptional[List[Tool]]NoneTools to make available to the model.