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

to_custom_streamed_response_wrapper() — anthropic-sdk-python Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  71704806_f10e_ef1b_aafe_385b7cbe8672["to_custom_streamed_response_wrapper()"]
  2e9c15bb_de03_aa91_93be_0e05db0a552e["_response.py"]
  71704806_f10e_ef1b_aafe_385b7cbe8672 -->|defined in| 2e9c15bb_de03_aa91_93be_0e05db0a552e
  afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7["get()"]
  71704806_f10e_ef1b_aafe_385b7cbe8672 -->|calls| afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7
  style 71704806_f10e_ef1b_aafe_385b7cbe8672 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/anthropic/_response.py lines 727–749

def to_custom_streamed_response_wrapper(
    func: Callable[P, object],
    response_cls: type[_APIResponseT],
) -> Callable[P, ResponseContextManager[_APIResponseT]]:
    """Higher order function that takes one of our bound API methods and an `APIResponse` class
    and wraps the method to support streaming and returning the given response class directly.

    Note: the given `response_cls` *must* be concrete, e.g. `class BinaryAPIResponse(APIResponse[bytes])`
    """

    @functools.wraps(func)
    def wrapped(*args: P.args, **kwargs: P.kwargs) -> ResponseContextManager[_APIResponseT]:
        extra_headers: dict[str, Any] = {**(cast(Any, kwargs.get("extra_headers")) or {})}
        extra_headers[RAW_RESPONSE_HEADER] = "stream"
        extra_headers[OVERRIDE_CAST_TO_HEADER] = response_cls

        kwargs["extra_headers"] = extra_headers

        make_request = functools.partial(func, *args, **kwargs)

        return ResponseContextManager(cast(Callable[[], _APIResponseT], make_request))

    return wrapped

Subdomains

Calls

Frequently Asked Questions

What does to_custom_streamed_response_wrapper() do?
to_custom_streamed_response_wrapper() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_response.py.
Where is to_custom_streamed_response_wrapper() defined?
to_custom_streamed_response_wrapper() is defined in src/anthropic/_response.py at line 727.
What does to_custom_streamed_response_wrapper() call?
to_custom_streamed_response_wrapper() calls 1 function(s): get.

Analyze Your Own Codebase

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

Try Supermodel Free