ChatAnthropic Class — langchain Architecture
Architecture documentation for the ChatAnthropic class in chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 977b57b2_5d0e_bcf4_a43e_b52857105005["ChatAnthropic"] 48aa29b8_65e7_522f_a445_a441eeb6baff["BaseChatModel"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|extends| 48aa29b8_65e7_522f_a445_a441eeb6baff de5a7878_b3fe_95d7_2575_7f534546dc1e["AIMessage"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|extends| de5a7878_b3fe_95d7_2575_7f534546dc1e 41bdea1f_6468_a045_76c0_070b322a6627["AnthropicTool"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|extends| 41bdea1f_6468_a045_76c0_070b322a6627 a85819c7_917d_4c71_2864_a19e68947340["chat_models.py"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|defined in| a85819c7_917d_4c71_2864_a19e68947340 c5432613_232d_1520_36f1_9193b181f001["_llm_type()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| c5432613_232d_1520_36f1_9193b181f001 0cb71105_b19e_e868_e50d_46d670658c14["lc_secrets()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 0cb71105_b19e_e868_e50d_46d670658c14 5b23f9e5_3a6b_11fd_f33f_ff4c4cd54974["is_lc_serializable()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 5b23f9e5_3a6b_11fd_f33f_ff4c4cd54974 efeee124_fc4a_e4d2_8af8_d48a6767e5aa["get_lc_namespace()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| efeee124_fc4a_e4d2_8af8_d48a6767e5aa 549261b4_2b16_0f9c_363b_c410ae449eb7["_identifying_params()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 549261b4_2b16_0f9c_363b_c410ae449eb7 b39f6f12_4d1b_6a96_1a02_49d36d18f0eb["_get_ls_params()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| b39f6f12_4d1b_6a96_1a02_49d36d18f0eb 63ba6ba9_c5fe_8164_078a_4bb8bff79792["set_default_max_tokens()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 63ba6ba9_c5fe_8164_078a_4bb8bff79792 287b73a2_6bd7_70bb_d83c_02dbf2b82412["build_extra()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 287b73a2_6bd7_70bb_d83c_02dbf2b82412 95ebec43_620f_5368_a20c_acafbcbcc193["_set_model_profile()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| 95ebec43_620f_5368_a20c_acafbcbcc193 f97d56b2_67b5_b4c7_387a_0ac9008fed9f["_client_params()"] 977b57b2_5d0e_bcf4_a43e_b52857105005 -->|method| f97d56b2_67b5_b4c7_387a_0ac9008fed9f
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/chat_models.py lines 741–1793
class ChatAnthropic(BaseChatModel):
"""Anthropic (Claude) chat models.
See the [LangChain docs for `ChatAnthropic`](https://docs.langchain.com/oss/python/integrations/chat/anthropic)
for tutorials, feature walkthroughs, and examples.
See the [Claude Platform docs](https://platform.claude.com/docs/en/about-claude/models/overview)
for a list of the latest models, their capabilities, and pricing.
Example:
```python
# pip install -U langchain-anthropic
# export ANTHROPIC_API_KEY="your-api-key"
from langchain_anthropic import ChatAnthropic
model = ChatAnthropic(
model="claude-sonnet-4-5-20250929",
# temperature=,
# max_tokens=,
# timeout=,
# max_retries=,
# base_url="...",
# Refer to API reference for full list of parameters
)
```
Note:
Any param which is not explicitly supported will be passed directly to
[`Anthropic.messages.create(...)`](https://platform.claude.com/docs/en/api/python/messages/create)
each time to the model is invoked.
"""
model_config = ConfigDict(
populate_by_name=True,
)
model: str = Field(alias="model_name")
"""Model name to use."""
max_tokens: int | None = Field(default=None, alias="max_tokens_to_sample")
"""Denotes the number of tokens to predict per generation.
If not specified, this is set dynamically using the model's `max_output_tokens`
from its model profile.
See docs on [model profiles](https://docs.langchain.com/oss/python/langchain/models#model-profiles)
for more information.
"""
temperature: float | None = None
"""A non-negative float that tunes the degree of randomness in generation."""
top_k: int | None = None
"""Number of most likely tokens to consider at each step."""
top_p: float | None = None
"""Total probability mass of tokens to consider at each step."""
default_request_timeout: float | None = Field(None, alias="timeout")
"""Timeout for requests to Claude API."""
# sdk default = 2: https://github.com/anthropics/anthropic-sdk-python?tab=readme-ov-file#retries
max_retries: int = 2
"""Number of retries allowed for requests sent to the Claude API."""
stop_sequences: list[str] | None = Field(None, alias="stop")
"""Default stop sequences."""
anthropic_api_url: str | None = Field(
alias="base_url",
default_factory=from_env(
["ANTHROPIC_API_URL", "ANTHROPIC_BASE_URL"],
default="https://api.anthropic.com",
),
)
"""Base URL for API requests. Only specify if using a proxy or service emulator.
If a value isn't passed in, will attempt to read the value first from
`ANTHROPIC_API_URL` and if that is not set, `ANTHROPIC_BASE_URL`.
"""
Source
Frequently Asked Questions
What is the ChatAnthropic class?
ChatAnthropic is a class in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/chat_models.py.
Where is ChatAnthropic defined?
ChatAnthropic is defined in libs/partners/anthropic/langchain_anthropic/chat_models.py at line 741.
What does ChatAnthropic extend?
ChatAnthropic extends BaseChatModel, AIMessage, AnthropicTool.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free