Home / Function/ _ensure_access_token() — anthropic-sdk-python Function Reference

_ensure_access_token() — anthropic-sdk-python Function Reference

Architecture documentation for the _ensure_access_token() function in _client.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  d2aca394_7ad5_92b5_38ec_6c25f071ab97["_ensure_access_token()"]
  a885dabd_0206_9ba5_949f_5990703d0a04["AsyncAnthropicVertex"]
  d2aca394_7ad5_92b5_38ec_6c25f071ab97 -->|defined in| a885dabd_0206_9ba5_949f_5990703d0a04
  26ddfdd3_edf1_2adc_5603_1eed5c624138["_ensure_access_token()"]
  26ddfdd3_edf1_2adc_5603_1eed5c624138 -->|calls| d2aca394_7ad5_92b5_38ec_6c25f071ab97
  562c226e_d12f_aba5_59c1_72cf16b01d1f["_prepare_request()"]
  562c226e_d12f_aba5_59c1_72cf16b01d1f -->|calls| d2aca394_7ad5_92b5_38ec_6c25f071ab97
  26ddfdd3_edf1_2adc_5603_1eed5c624138["_ensure_access_token()"]
  d2aca394_7ad5_92b5_38ec_6c25f071ab97 -->|calls| 26ddfdd3_edf1_2adc_5603_1eed5c624138
  style d2aca394_7ad5_92b5_38ec_6c25f071ab97 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/lib/vertex/_client.py lines 303–319

    async def _ensure_access_token(self) -> str:
        if self.access_token is not None:
            return self.access_token

        if not self.credentials:
            self.credentials, project_id = await asyncify(load_auth)(project_id=self.project_id)
            if not self.project_id:
                self.project_id = project_id

        if self.credentials.expired or not self.credentials.token:
            await asyncify(refresh_auth)(self.credentials)

        if not self.credentials.token:
            raise RuntimeError("Could not resolve API token from the environment")

        assert isinstance(self.credentials.token, str)
        return self.credentials.token

Subdomains

Frequently Asked Questions

What does _ensure_access_token() do?
_ensure_access_token() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/vertex/_client.py.
Where is _ensure_access_token() defined?
_ensure_access_token() is defined in src/anthropic/lib/vertex/_client.py at line 303.
What does _ensure_access_token() call?
_ensure_access_token() calls 1 function(s): _ensure_access_token.
What calls _ensure_access_token()?
_ensure_access_token() is called by 2 function(s): _ensure_access_token, _prepare_request.

Analyze Your Own Codebase

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

Try Supermodel Free