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

AnthropicFoundryChatGenerator

Generate chat responses using Claude models deployed on Azure Foundry.

Key Features​

  • Connects to Claude models (Opus, Sonnet, Haiku) through your Azure Foundry resource.
  • Accepts and returns messages in ChatMessage format.
  • Supports streaming responses through a configurable callback.
  • Supports tool calling for agentic workflows.
  • Supports Anthropic server-side tools such as web search and code execution.
  • Supports Azure AD token authentication as an alternative to API keys.

Configuration​

Add Workspace-Level Integration​

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration​

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. Drag the AnthropicFoundryChatGenerator 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 Claude model name that matches your Foundry deployment (for example, claude-sonnet-4-5).
    2. Set the resource to your Azure Foundry resource name, or set endpoint to the full Foundry endpoint URL.
    3. Create a secret with your Foundry API key and set it as api_key. Use ANTHROPIC_FOUNDRY_API_KEY as the environment variable name. For instructions, see Create Secrets.
  4. Go to the Advanced tab to configure generation_kwargs, timeout, and max_retries.

Connections​

AnthropicFoundryChatGenerator 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 foundry_chat_generator.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

AnthropicFoundryChatGenerator:
type: haystack_integrations.components.generators.anthropic.chat.foundry_chat_generator.AnthropicFoundryChatGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- ANTHROPIC_FOUNDRY_API_KEY
strict: false
resource: my-foundry-resource
model: claude-sonnet-4-5
generation_kwargs:
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.anthropic.chat.foundry_chat_generator.AnthropicFoundryChatGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- ANTHROPIC_FOUNDRY_API_KEY
strict: false
resource: my-foundry-resource
model: claude-sonnet-4-5
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
api_keySecretSecret.from_env_var("ANTHROPIC_FOUNDRY_API_KEY")The Foundry API key. Can be None when using azure_ad_token_provider.
resourceOptional[str]NoneThe Azure Foundry resource name. Can also be set via the ANTHROPIC_FOUNDRY_RESOURCE environment variable. Either resource or endpoint must be provided.
endpointOptional[str]NoneThe full Foundry endpoint URL (for example, https://your-resource.openai.azure.com/anthropic). Either resource or endpoint must be provided.
modelstrclaude-sonnet-4-5The Claude model name to use, which must match your Foundry deployment.
streaming_callbackOptional[Callable]NoneA callback function for streaming responses.
generation_kwargsOptional[Dict[str, Any]]NoneAdditional generation parameters such as max_tokens, temperature, top_p, top_k, stop_sequences, and system.
ignore_tools_thinking_messagesboolTrueWhether to suppress chain-of-thought thinking messages from tool use responses.
toolsOptional[List[Tool]]NoneA list of tools the model can use.
anthropic_server_toolsOptional[List[Dict]]NoneNative Anthropic server-side tools (for example, {"type": "web_search_20250305"}).
timeoutOptional[float]NoneRequest timeout in seconds.
max_retriesOptional[int]NoneMaximum number of retries on API errors.
azure_ad_token_providerOptional[Callable]NoneA function that returns an Azure AD token for authentication. Use instead of api_key for enhanced security.

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]]NoneAdditional generation parameters to override init-time values.
toolsOptional[List[Tool]]NoneTools to make available to the model, overriding init-time tools.