Home / Class/ AsyncAnthropic Class — anthropic-sdk-python Architecture

AsyncAnthropic Class — anthropic-sdk-python Architecture

Architecture documentation for the AsyncAnthropic class in _client.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  0fd89929_7b38_b43a_7bae_43e09dda2e19["AsyncAnthropic"]
  3224f719_8046_78c8_59e1_47301a46ddd4["AsyncAPIClient"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|extends| 3224f719_8046_78c8_59e1_47301a46ddd4
  14d855f4_2395_cbc9_e501_5be17b6905d0["Omit"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|extends| 14d855f4_2395_cbc9_e501_5be17b6905d0
  f30eca5a_2fa0_68c1_64aa_b52331a2dcc8["NotGiven"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|extends| f30eca5a_2fa0_68c1_64aa_b52331a2dcc8
  3a4e7de9_0222_597c_a697_7ff97bd0dafc["_client.py"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|defined in| 3a4e7de9_0222_597c_a697_7ff97bd0dafc
  ad028bc7_3383_8ab7_b1ea_0a2e79641f55["__init__()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| ad028bc7_3383_8ab7_b1ea_0a2e79641f55
  bc468eab_4acf_d302_ebc2_94361dd4a2b2["completions()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| bc468eab_4acf_d302_ebc2_94361dd4a2b2
  198639eb_affd_c6d2_3a83_f2db840965c4["messages()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 198639eb_affd_c6d2_3a83_f2db840965c4
  f9e86e0f_08e2_932c_b998_cf4c0d3c0ab8["models()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| f9e86e0f_08e2_932c_b998_cf4c0d3c0ab8
  14a6ecec_bd3e_cf79_b0e2_0e451e32e3c0["beta()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 14a6ecec_bd3e_cf79_b0e2_0e451e32e3c0
  d25d98df_be8e_c6ce_bf58_36410704597a["with_raw_response()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| d25d98df_be8e_c6ce_bf58_36410704597a
  397b2530_338a_24af_21ee_70e0432d93e6["with_streaming_response()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 397b2530_338a_24af_21ee_70e0432d93e6
  50e2201d_725a_9ff0_57d0_c1c1b0984a64["qs()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 50e2201d_725a_9ff0_57d0_c1c1b0984a64
  905f7d41_7124_787a_a278_bc0962135699["auth_headers()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 905f7d41_7124_787a_a278_bc0962135699
  4cb11939_b240_710b_502e_6d86bc75a72c["_api_key_auth()"]
  0fd89929_7b38_b43a_7bae_43e09dda2e19 -->|method| 4cb11939_b240_710b_502e_6d86bc75a72c

Relationship Graph

Source Code

src/anthropic/_client.py lines 293–524

class AsyncAnthropic(AsyncAPIClient):
    # 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 `DefaultAsyncHttpxClient` 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/#asyncclient) for more details.
        http_client: httpx.AsyncClient | 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 async AsyncAnthropic 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 = AsyncStream

    @cached_property
    def completions(self) -> AsyncCompletions:
        from .resources.completions import AsyncCompletions

        return AsyncCompletions(self)

    @cached_property
    def messages(self) -> AsyncMessages:
        from .resources.messages import AsyncMessages

        return AsyncMessages(self)

    @cached_property
    def models(self) -> AsyncModels:
        from .resources.models import AsyncModels

Frequently Asked Questions

What is the AsyncAnthropic class?
AsyncAnthropic is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_client.py.
Where is AsyncAnthropic defined?
AsyncAnthropic is defined in src/anthropic/_client.py at line 293.
What does AsyncAnthropic extend?
AsyncAnthropic extends AsyncAPIClient, Omit, NotGiven.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free