AnthropicChatGenerator
Use Anthropic's chat completion models.
Basic Information
- Type:
haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator - Components it can connect with:
ChatPromptBuilder:AnthropicChatGeneratorreceives chat messages fromChatPromptBuilder.OutputAdapter:AnthropicChatGeneratorcan send generated replies toOutputAdapterconfigured to convert them into a list of strings thatDeepsetAnswerBuildercan accept.
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| messages | List[ChatMessage] | A list of ChatMessage objects representing the input messages. | |
| generation_kwargs | Optional[Dict[str, Any]] | None | Additional keyword arguments for the model. |
| streaming_callback | Optional[StreamingCallbackT] | None | An optional callback function to handle streaming chunks. |
| tools | Optional[Union[List[Tool], Toolset]] | None | A list of tool objects or a toolset that the model can use. Each tool must have a unique name. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| replies | List[ChatMessage] | A list of generated replies. |
Overview
For a list of Anthropic models you can use, see Anthropic Models.
You can customize how the text is generated by passing parameters to the Anthropic API. Use the generation_kwargs parameter to do this. Any parameter that works with anthropic.Message.create will work here too. For a complete list of parameters, see Anthropic API documentation.
Authentication
To use this component, connect deepset with Anthropic first. You'll need an Anthropic API key to do this.
Connection Instructions
- Click your profile icon in the top right corner and choose Integrations.

- Click Connect next to the provider.
- Enter your API key and submit it.
Usage Example
Initializing the Component
components:
AnthropicGenerator:
type: haystack_integrations.components.generators.anthropic.generator.AnthropicGenerator
init_parameters:
Using the Component in a Pipeline
This is a RAG pipeline that uses Claude Sonnet 4:
Parameters
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | Secret | Secret.from_env_var('ANTHROPIC_API_KEY') | The Anthropic API key. |
| model | str | claude-sonnet-4-20250514 | The name of the Anthropic model to use. |
| streaming_callback | Optional[Callable[[StreamingChunk], None]] | None | An optional callback function to handle streaming chunks. |
| system_prompt | Optional[str] | None | An optional system prompt to use for generation. |
| generation_kwargs | Optional[Dict[str, Any]] | None | Additional keyword arguments for generation. |
| timeout | Optional[float] | None | The timeout for request. |
| max_retries | Optional[int] | None | The maximum number of retries if a request fails. |
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.
| Parameter | Type | Default | Description |
|---|---|---|---|
| prompt | str | The prompt with instructions for the model. | |
| generation_kwargs | Optional[Dict[str, Any]] | None | Additional keyword arguments for generation. For a complete list, see Anthropic API documentation. |
| streaming_callback | Optional[Callable[[StreamingChunk], None]] | None | An optional callback function to handle streaming chunks. |
Was this page helpful?