_AnthropicCommon Class — langchain Architecture
Architecture documentation for the _AnthropicCommon class in llms.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD e9e02443_a77e_7c58_a321_32aae5e1fcd0["_AnthropicCommon"] f5a29046_740d_1358_3615_8cc689b26ca9["BaseLanguageModel"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|extends| f5a29046_740d_1358_3615_8cc689b26ca9 5e204490_6740_303b_67ac_683d6d4a20d2["llms.py"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|defined in| 5e204490_6740_303b_67ac_683d6d4a20d2 f2d4da33_e4ea_a017_9c7b_36bcb53793bc["build_extra()"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|method| f2d4da33_e4ea_a017_9c7b_36bcb53793bc eeb60890_f14d_d489_0d0f_6ec5030c0bd9["validate_environment()"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|method| eeb60890_f14d_d489_0d0f_6ec5030c0bd9 d925f9a9_3773_8ab0_9d7b_6be976b01e6c["_default_params()"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|method| d925f9a9_3773_8ab0_9d7b_6be976b01e6c 04aa4618_554e_4c92_9798_081b1af10aa1["_identifying_params()"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|method| 04aa4618_554e_4c92_9798_081b1af10aa1 5b0cfa0b_130d_960a_411e_cc97a2c28a93["_get_anthropic_stop()"] e9e02443_a77e_7c58_a321_32aae5e1fcd0 -->|method| 5b0cfa0b_130d_960a_411e_cc97a2c28a93
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/llms.py lines 25–131
class _AnthropicCommon(BaseLanguageModel):
client: Any = None
async_client: Any = None
model: str = Field(default="claude-sonnet-4-5", alias="model_name")
"""Model name to use."""
max_tokens: int = Field(default=1024, alias="max_tokens_to_sample")
"""Denotes the number of tokens to predict per generation."""
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."""
streaming: bool = False
"""Whether to stream the results."""
default_request_timeout: float | None = None
"""Timeout for requests to Anthropic Completion API. Default is 600 seconds."""
max_retries: int = 2
"""Number of retries allowed for requests sent to the Anthropic Completion API."""
anthropic_api_url: str | None = Field(
alias="base_url",
default_factory=from_env(
"ANTHROPIC_API_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 from
`ANTHROPIC_API_URL`. If not set, the default value `https://api.anthropic.com`
will be used.
"""
anthropic_api_key: SecretStr = Field(
alias="api_key",
default_factory=secret_from_env("ANTHROPIC_API_KEY", default=""),
)
"""Automatically read from env var `ANTHROPIC_API_KEY` if not provided."""
HUMAN_PROMPT: str | None = None
AI_PROMPT: str | None = None
count_tokens: Callable[[str], int] | None = None
model_kwargs: dict[str, Any] = Field(default_factory=dict)
@model_validator(mode="before")
@classmethod
def build_extra(cls, values: dict) -> Any:
all_required_field_names = get_pydantic_field_names(cls)
return _build_model_kwargs(values, all_required_field_names)
@model_validator(mode="after")
def validate_environment(self) -> Self:
"""Validate that api key and python package exists in environment."""
self.client = anthropic.Anthropic(
base_url=self.anthropic_api_url,
api_key=self.anthropic_api_key.get_secret_value(),
timeout=self.default_request_timeout,
max_retries=self.max_retries,
)
self.async_client = anthropic.AsyncAnthropic(
base_url=self.anthropic_api_url,
api_key=self.anthropic_api_key.get_secret_value(),
timeout=self.default_request_timeout,
max_retries=self.max_retries,
)
# Keep for backward compatibility but not used in Messages API
self.HUMAN_PROMPT = getattr(anthropic, "HUMAN_PROMPT", None)
self.AI_PROMPT = getattr(anthropic, "AI_PROMPT", None)
Extends
Source
Frequently Asked Questions
What is the _AnthropicCommon class?
_AnthropicCommon is a class in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/llms.py.
Where is _AnthropicCommon defined?
_AnthropicCommon is defined in libs/partners/anthropic/langchain_anthropic/llms.py at line 25.
What does _AnthropicCommon extend?
_AnthropicCommon extends BaseLanguageModel.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free