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

_maybe_override_cast_to() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  b55917f0_4e1e_bd62_1265_81021799d2f5["_maybe_override_cast_to()"]
  842ce0be_ea56_b939_960f_13eb61230daf["BaseClient"]
  b55917f0_4e1e_bd62_1265_81021799d2f5 -->|defined in| 842ce0be_ea56_b939_960f_13eb61230daf
  2cb1e2bf_1a02_d5ea_42a9_c0def162363a["request()"]
  2cb1e2bf_1a02_d5ea_42a9_c0def162363a -->|calls| b55917f0_4e1e_bd62_1265_81021799d2f5
  c21c2971_d83f_0afc_9811_0642b34cfcd3["request()"]
  c21c2971_d83f_0afc_9811_0642b34cfcd3 -->|calls| b55917f0_4e1e_bd62_1265_81021799d2f5
  style b55917f0_4e1e_bd62_1265_81021799d2f5 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_base_client.py lines 624–639

    def _maybe_override_cast_to(self, cast_to: type[ResponseT], options: FinalRequestOptions) -> type[ResponseT]:
        if not is_given(options.headers):
            return cast_to

        # make a copy of the headers so we don't mutate user-input
        headers = dict(options.headers)

        # we internally support defining a temporary header to override the
        # default `cast_to` type for use with `.with_raw_response` and `.with_streaming_response`
        # see _response.py for implementation details
        override_cast_to = headers.pop(OVERRIDE_CAST_TO_HEADER, not_given)
        if is_given(override_cast_to):
            options.headers = headers
            return cast(Type[ResponseT], override_cast_to)

        return cast_to

Subdomains

Called By

Frequently Asked Questions

What does _maybe_override_cast_to() do?
_maybe_override_cast_to() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_base_client.py.
Where is _maybe_override_cast_to() defined?
_maybe_override_cast_to() is defined in src/anthropic/_base_client.py at line 624.
What calls _maybe_override_cast_to()?
_maybe_override_cast_to() is called by 2 function(s): request, request.

Analyze Your Own Codebase

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

Try Supermodel Free