AnthropicLLM Class — langchain Architecture
Architecture documentation for the AnthropicLLM class in llms.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD c95a497f_938f_2be9_842e_087a0766cf00["AnthropicLLM"] b2c7d2a5_0852_93df_c3e1_828c36a88999["LLM"] c95a497f_938f_2be9_842e_087a0766cf00 -->|extends| b2c7d2a5_0852_93df_c3e1_828c36a88999 e9e02443_a77e_7c58_a321_32aae5e1fcd0["_AnthropicCommon"] c95a497f_938f_2be9_842e_087a0766cf00 -->|extends| e9e02443_a77e_7c58_a321_32aae5e1fcd0 5e204490_6740_303b_67ac_683d6d4a20d2["llms.py"] c95a497f_938f_2be9_842e_087a0766cf00 -->|defined in| 5e204490_6740_303b_67ac_683d6d4a20d2 a155775f_1bc7_54a1_89ba_f14e195409d7["raise_warning()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| a155775f_1bc7_54a1_89ba_f14e195409d7 9c941e92_ccb7_b4b5_b71e_85b2325b85c1["_llm_type()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 9c941e92_ccb7_b4b5_b71e_85b2325b85c1 6b8ddb35_e60f_4db4_ff73_bbb5c8753f95["lc_secrets()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 6b8ddb35_e60f_4db4_ff73_bbb5c8753f95 83514774_400c_90a0_9b94_ae25feda5eda["is_lc_serializable()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 83514774_400c_90a0_9b94_ae25feda5eda 7a90009e_d516_3dbe_36b9_f48ba03ea65f["_identifying_params()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 7a90009e_d516_3dbe_36b9_f48ba03ea65f 04a7c2f7_487c_1b1a_34cf_68d2a12e8f7d["_get_ls_params()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 04a7c2f7_487c_1b1a_34cf_68d2a12e8f7d 04edfbcc_f913_d95a_6261_c2a81f9f570e["_format_messages()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 04edfbcc_f913_d95a_6261_c2a81f9f570e e1e4f815_3e2a_75f8_675e_9a5e7f0f868a["_call()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| e1e4f815_3e2a_75f8_675e_9a5e7f0f868a 3db6ff31_b27e_401a_32a5_ee47b2c82f12["convert_prompt()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 3db6ff31_b27e_401a_32a5_ee47b2c82f12 40512e45_7b9d_dbee_2106_59fc9edca16c["_acall()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| 40512e45_7b9d_dbee_2106_59fc9edca16c cb1cae7d_4a5d_cfbf_994a_88075fe175e2["_stream()"] c95a497f_938f_2be9_842e_087a0766cf00 -->|method| cb1cae7d_4a5d_cfbf_994a_88075fe175e2
Relationship Graph
Source Code
libs/partners/anthropic/langchain_anthropic/llms.py lines 134–433
class AnthropicLLM(LLM, _AnthropicCommon):
"""Anthropic text completion large language model (legacy LLM).
To use, you should have the environment variable `ANTHROPIC_API_KEY`
set with your API key, or pass it as a named parameter to the constructor.
Example:
```python
from langchain_anthropic import AnthropicLLM
model = AnthropicLLM(model="claude-sonnet-4-5")
```
"""
model_config = ConfigDict(
populate_by_name=True,
arbitrary_types_allowed=True,
)
@model_validator(mode="before")
@classmethod
def raise_warning(cls, values: dict) -> Any:
"""Raise warning that this class is deprecated."""
warnings.warn(
"This Anthropic LLM is deprecated. "
"Please use `from langchain_anthropic import ChatAnthropic` "
"instead",
stacklevel=2,
)
return values
@property
def _llm_type(self) -> str:
"""Return type of llm."""
return "anthropic-llm"
@property
def lc_secrets(self) -> dict[str, str]:
"""Return a mapping of secret keys to environment variables."""
return {"anthropic_api_key": "ANTHROPIC_API_KEY"}
@classmethod
def is_lc_serializable(cls) -> bool:
"""Whether this class can be serialized by langchain."""
return True
@property
def _identifying_params(self) -> dict[str, Any]:
"""Get the identifying parameters."""
return {
"model": self.model,
"max_tokens": self.max_tokens,
"temperature": self.temperature,
"top_k": self.top_k,
"top_p": self.top_p,
"model_kwargs": self.model_kwargs,
"streaming": self.streaming,
"default_request_timeout": self.default_request_timeout,
"max_retries": self.max_retries,
}
def _get_ls_params(
self,
stop: list[str] | None = None,
**kwargs: Any,
) -> LangSmithParams:
"""Get standard params for tracing."""
params = super()._get_ls_params(stop=stop, **kwargs)
identifying_params = self._identifying_params
if max_tokens := kwargs.get(
"max_tokens",
identifying_params.get("max_tokens"),
):
params["ls_max_tokens"] = max_tokens
return params
def _format_messages(self, prompt: str) -> list[dict[str, str]]:
"""Convert prompt to Messages API format."""
messages = []
# Handle legacy prompts that might have HUMAN_PROMPT/AI_PROMPT markers
Extends
Source
Frequently Asked Questions
What is the AnthropicLLM class?
AnthropicLLM is a class in the langchain codebase, defined in libs/partners/anthropic/langchain_anthropic/llms.py.
Where is AnthropicLLM defined?
AnthropicLLM is defined in libs/partners/anthropic/langchain_anthropic/llms.py at line 134.
What does AnthropicLLM extend?
AnthropicLLM extends LLM, _AnthropicCommon.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free