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.

Entity Profile

Dependency Diagram

graph TD
  50812e41_ba9a_eab9_8858_8658a4f45f3f["_prepare_options()"]
  8e4f8bb6_054a_e222_820c_5e6d00919a16["AnthropicFoundry"]
  50812e41_ba9a_eab9_8858_8658a4f45f3f -->|defined in| 8e4f8bb6_054a_e222_820c_5e6d00919a16
  1270be12_68e9_8392_215c_19c9e92c44c1["_prepare_options()"]
  1270be12_68e9_8392_215c_19c9e92c44c1 -->|calls| 50812e41_ba9a_eab9_8858_8658a4f45f3f
  1294e3e2_8154_227a_ea72_7ab214a780ad["_get_azure_ad_token()"]
  50812e41_ba9a_eab9_8858_8658a4f45f3f -->|calls| 1294e3e2_8154_227a_ea72_7ab214a780ad
  1270be12_68e9_8392_215c_19c9e92c44c1["_prepare_options()"]
  50812e41_ba9a_eab9_8858_8658a4f45f3f -->|calls| 1270be12_68e9_8392_215c_19c9e92c44c1
  style 50812e41_ba9a_eab9_8858_8658a4f45f3f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/lib/foundry.py lines 246–264

    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 = 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:
            if headers.get("api-key") is None:
                assert self.api_key is not 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 246.
What does _prepare_options() call?
_prepare_options() calls 2 function(s): _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