Anthropic Class — anthropic-sdk-python Architecture
Architecture documentation for the Anthropic class in _client.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD 0517492b_78c2_27e9_22ae_aae3b5f0e93e["Anthropic"] 4b46ed95_ff71_ea5d_7534_6929dc929bdb["SyncAPIClient"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|extends| 4b46ed95_ff71_ea5d_7534_6929dc929bdb 14d855f4_2395_cbc9_e501_5be17b6905d0["Omit"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|extends| 14d855f4_2395_cbc9_e501_5be17b6905d0 f30eca5a_2fa0_68c1_64aa_b52331a2dcc8["NotGiven"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|extends| f30eca5a_2fa0_68c1_64aa_b52331a2dcc8 3a4e7de9_0222_597c_a697_7ff97bd0dafc["_client.py"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|defined in| 3a4e7de9_0222_597c_a697_7ff97bd0dafc 8376fd1a_4cac_463e_0a29_9c402d41f70f["__init__()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 8376fd1a_4cac_463e_0a29_9c402d41f70f 35870f35_115b_61a1_6b22_8abb744029d6["completions()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 35870f35_115b_61a1_6b22_8abb744029d6 418beded_41ca_7571_2f28_5f38807bc890["messages()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 418beded_41ca_7571_2f28_5f38807bc890 93aac091_868b_aa95_5066_6a252a5dcd51["models()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 93aac091_868b_aa95_5066_6a252a5dcd51 93d034e3_14d4_1165_af6e_146349fb4955["beta()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 93d034e3_14d4_1165_af6e_146349fb4955 8d7e2c0f_1127_e23e_cf98_39a3638cdc83["with_raw_response()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 8d7e2c0f_1127_e23e_cf98_39a3638cdc83 4e4e37f8_c245_dfab_59f3_0390f78e15b1["with_streaming_response()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 4e4e37f8_c245_dfab_59f3_0390f78e15b1 c554905d_9a74_ae17_0c62_9f3303510150["qs()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| c554905d_9a74_ae17_0c62_9f3303510150 f015d6f0_65dc_6360_1a67_02cd4ce6c978["auth_headers()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| f015d6f0_65dc_6360_1a67_02cd4ce6c978 0cda2066_cc89_c34f_498f_72e73ee030d5["_api_key_auth()"] 0517492b_78c2_27e9_22ae_aae3b5f0e93e -->|method| 0cda2066_cc89_c34f_498f_72e73ee030d5
Relationship Graph
Source Code
src/anthropic/_client.py lines 53–290
class Anthropic(SyncAPIClient):
# client options
api_key: str | None
auth_token: str | None
# constants
HUMAN_PROMPT = _constants.HUMAN_PROMPT
AI_PROMPT = _constants.AI_PROMPT
def __init__(
self,
*,
api_key: str | None = None,
auth_token: str | None = None,
base_url: str | httpx.URL | None = None,
timeout: float | Timeout | None | NotGiven = not_given,
max_retries: int = DEFAULT_MAX_RETRIES,
default_headers: Mapping[str, str] | None = None,
default_query: Mapping[str, object] | None = None,
# Configure a custom httpx client.
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
http_client: httpx.Client | None = None,
# Enable or disable schema validation for data returned by the API.
# When enabled an error APIResponseValidationError is raised
# if the API responds with invalid data for the expected schema.
#
# This parameter may be removed or changed in the future.
# If you rely on this feature, please open a GitHub issue
# outlining your use-case to help us decide if it should be
# part of our public interface in the future.
_strict_response_validation: bool = False,
) -> None:
"""Construct a new synchronous Anthropic client instance.
This automatically infers the following arguments from their corresponding environment variables if they are not provided:
- `api_key` from `ANTHROPIC_API_KEY`
- `auth_token` from `ANTHROPIC_AUTH_TOKEN`
"""
if api_key is None:
api_key = os.environ.get("ANTHROPIC_API_KEY")
self.api_key = api_key
if auth_token is None:
auth_token = os.environ.get("ANTHROPIC_AUTH_TOKEN")
self.auth_token = auth_token
if base_url is None:
base_url = os.environ.get("ANTHROPIC_BASE_URL")
if base_url is None:
base_url = f"https://api.anthropic.com"
super().__init__(
version=__version__,
base_url=base_url,
max_retries=max_retries,
timeout=timeout,
http_client=http_client,
custom_headers=default_headers,
custom_query=default_query,
_strict_response_validation=_strict_response_validation,
)
self._default_stream_cls = Stream
@cached_property
def completions(self) -> Completions:
from .resources.completions import Completions
return Completions(self)
@cached_property
def messages(self) -> Messages:
from .resources.messages import Messages
return Messages(self)
@cached_property
def models(self) -> Models:
from .resources.models import Models
Domain
Defined In
Extends
Source
Frequently Asked Questions
What is the Anthropic class?
Anthropic is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_client.py.
Where is Anthropic defined?
Anthropic is defined in src/anthropic/_client.py at line 53.
What does Anthropic extend?
Anthropic extends SyncAPIClient, Omit, NotGiven.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free