| 549 | |
| 550 | |
| 551 | class AsyncAnthropic(AsyncAPIClient): |
| 552 | # client options |
| 553 | api_key: str | None |
| 554 | auth_token: str | None |
| 555 | webhook_key: str | None |
| 556 | credentials: AccessTokenProvider | None |
| 557 | _token_cache: TokenCache | None |
| 558 | _custom_auth: AccessTokenAuth | None |
| 559 | |
| 560 | # constants |
| 561 | HUMAN_PROMPT = _constants.HUMAN_PROMPT |
| 562 | AI_PROMPT = _constants.AI_PROMPT |
| 563 | |
| 564 | def __init__( |
| 565 | self, |
| 566 | *, |
| 567 | api_key: str | None = None, |
| 568 | auth_token: str | None = None, |
| 569 | credentials: AccessTokenProvider | None = None, |
| 570 | config: Mapping[str, Any] | None = None, |
| 571 | profile: str | None = None, |
| 572 | webhook_key: str | None = None, |
| 573 | base_url: str | httpx.URL | None = None, |
| 574 | timeout: float | Timeout | None | NotGiven = not_given, |
| 575 | max_retries: int = DEFAULT_MAX_RETRIES, |
| 576 | default_headers: Mapping[str, str] | None = None, |
| 577 | default_query: Mapping[str, object] | None = None, |
| 578 | # Configure a custom httpx client. |
| 579 | # We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`. |
| 580 | # See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details. |
| 581 | http_client: httpx.AsyncClient | None = None, |
| 582 | middleware: Sequence[MiddlewareInput] | None = None, |
| 583 | # Enable or disable schema validation for data returned by the API. |
| 584 | # When enabled an error APIResponseValidationError is raised |
| 585 | # if the API responds with invalid data for the expected schema. |
| 586 | # |
| 587 | # This parameter may be removed or changed in the future. |
| 588 | # If you rely on this feature, please open a GitHub issue |
| 589 | # outlining your use-case to help us decide if it should be |
| 590 | # part of our public interface in the future. |
| 591 | _strict_response_validation: bool = False, |
| 592 | _token_cache: TokenCache | None | NotGiven = not_given, |
| 593 | ) -> None: |
| 594 | """Construct a new async AsyncAnthropic client instance. |
| 595 | |
| 596 | Credentials are resolved in the following order (first match wins): |
| 597 | |
| 598 | 1. Explicit constructor arguments — ``api_key=``, ``auth_token=``, |
| 599 | ``credentials=``, ``config=``, or ``profile=``. When any of these |
| 600 | is passed, environment variables are not consulted for credentials. |
| 601 | 2. ``ANTHROPIC_API_KEY`` / ``ANTHROPIC_AUTH_TOKEN`` environment |
| 602 | variables. |
| 603 | 3. ``ANTHROPIC_PROFILE`` environment variable — loads the named |
| 604 | profile from ``<config_dir>/configs/<profile>.json``. |
| 605 | 4. Workload identity federation environment variables — |
| 606 | ``ANTHROPIC_IDENTITY_TOKEN[_FILE]`` + |
| 607 | ``ANTHROPIC_FEDERATION_RULE_ID`` + ``ANTHROPIC_ORGANIZATION_ID``. |
| 608 | 5. The active profile on disk — the profile named by |
no outgoing calls