Skip to main content

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: AnthropicChatGenerator receives chat messages from ChatPromptBuilder.
    • OutputAdapter: AnthropicChatGenerator can send generated replies to OutputAdapter configured to convert them into a list of strings that DeepsetAnswerBuilder can accept.

Inputs

ParameterTypeDefaultDescription
messagesList[ChatMessage]A list of ChatMessage objects representing the input messages.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for the model.
streaming_callbackOptional[StreamingCallbackT]NoneAn optional callback function to handle streaming chunks.
toolsOptional[Union[List[Tool], Toolset]]NoneA list of tool objects or a toolset that the model can use. Each tool must have a unique name.

Outputs

ParameterTypeDefaultDescription
repliesList[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

  1. Click your profile icon in the top right corner and choose Integrations.
    Integrations menu screenshot
  2. Click Connect next to the provider.
  3. 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:

ParameterTypeDefaultDescription
api_keySecretSecret.from_env_var('ANTHROPIC_API_KEY')The Anthropic API key.
modelstrclaude-sonnet-4-20250514The name of the Anthropic model to use.
streaming_callbackOptional[Callable[[StreamingChunk], None]]NoneAn optional callback function to handle streaming chunks.
system_promptOptional[str]NoneAn optional system prompt to use for generation.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for generation.
timeoutOptional[float]NoneThe timeout for request.
max_retriesOptional[int]NoneThe 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.

ParameterTypeDefaultDescription
promptstrThe prompt with instructions for the model.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional keyword arguments for generation. For a complete list, see Anthropic API documentation.
streaming_callbackOptional[Callable[[StreamingChunk], None]]NoneAn optional callback function to handle streaming chunks.