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

_prepare_options() — anthropic-sdk-python Function Reference

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

Function python AnthropicClient AsyncAPI calls 3 called by 1

Entity Profile

Dependency Diagram

graph TD
  3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e["_prepare_options()"]
  ba122576_d069_c004_c1f5_107e86c806e6["AsyncAnthropicFoundry"]
  3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e -->|defined in| ba122576_d069_c004_c1f5_107e86c806e6
  c229995a_1a64_24ac_1990_cfdf81e8b762["_prepare_options()"]
  c229995a_1a64_24ac_1990_cfdf81e8b762 -->|calls| 3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e
  6b4d264c_08ec_fed6_7189_00072941c374["_get_azure_ad_token()"]
  3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e -->|calls| 6b4d264c_08ec_fed6_7189_00072941c374
  c229995a_1a64_24ac_1990_cfdf81e8b762["_prepare_options()"]
  3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e -->|calls| c229995a_1a64_24ac_1990_cfdf81e8b762
  1d13db30_ba0e_56d4_6555_7a3db10b4ac2["_get_azure_ad_token()"]
  3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e -->|calls| 1d13db30_ba0e_56d4_6555_7a3db10b4ac2
  style 3c44a9b5_cb0f_61cb_1e6e_87ddd11b043e fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/lib/foundry.py lines 425–443

    async def _prepare_options(self, options: FinalRequestOptions) -> FinalRequestOptions:
        headers: dict[str, str | Omit] = {**options.headers} if is_given(options.headers) else {}

        options = model_copy(options)
        options.headers = headers

        azure_ad_token = await self._get_azure_ad_token()
        if azure_ad_token is not None:
            if headers.get("Authorization") is None:
                headers["Authorization"] = f"Bearer {azure_ad_token}"
        elif self.api_key is not None:
            assert self.api_key is not None
            if headers.get("api-key") is None:
                headers["api-key"] = self.api_key
        else:
            # should never be hit
            raise ValueError("Unable to handle auth")

        return options

Subdomains

Called By

Frequently Asked Questions

What does _prepare_options() do?
_prepare_options() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/lib/foundry.py.
Where is _prepare_options() defined?
_prepare_options() is defined in src/anthropic/lib/foundry.py at line 425.
What does _prepare_options() call?
_prepare_options() calls 3 function(s): _get_azure_ad_token, _get_azure_ad_token, _prepare_options.
What calls _prepare_options()?
_prepare_options() is called by 1 function(s): _prepare_options.

Analyze Your Own Codebase

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

Try Supermodel Free