Home / Class/ AsyncBinaryAPIResponse Class — anthropic-sdk-python Architecture

AsyncBinaryAPIResponse Class — anthropic-sdk-python Architecture

Architecture documentation for the AsyncBinaryAPIResponse class in _response.py from the anthropic-sdk-python codebase.

Entity Profile

Dependency Diagram

graph TD
  bbd3ea26_8d54_610d_41cb_3ac713029b47["AsyncBinaryAPIResponse"]
  2e9c15bb_de03_aa91_93be_0e05db0a552e["_response.py"]
  bbd3ea26_8d54_610d_41cb_3ac713029b47 -->|defined in| 2e9c15bb_de03_aa91_93be_0e05db0a552e
  e9237435_4608_fcc5_c600_9a3c756b13ef["write_to_file()"]
  bbd3ea26_8d54_610d_41cb_3ac713029b47 -->|method| e9237435_4608_fcc5_c600_9a3c756b13ef

Relationship Graph

Source Code

src/anthropic/_response.py lines 539–562

class AsyncBinaryAPIResponse(AsyncAPIResponse[bytes]):
    """Subclass of APIResponse providing helpers for dealing with binary data.

    Note: If you want to stream the response data instead of eagerly reading it
    all at once then you should use `.with_streaming_response` when making
    the API request, e.g. `.with_streaming_response.get_binary_response()`
    """

    async def write_to_file(
        self,
        file: str | os.PathLike[str],
    ) -> None:
        """Write the output to the given file.

        Accepts a filename or any path-like object, e.g. pathlib.Path

        Note: if you want to stream the data to the file instead of writing
        all at once then you should use `.with_streaming_response` when making
        the API request, e.g. `.with_streaming_response.get_binary_response()`
        """
        path = anyio.Path(file)
        async with await path.open(mode="wb") as f:
            async for data in self.iter_bytes():
                await f.write(data)

Frequently Asked Questions

What is the AsyncBinaryAPIResponse class?
AsyncBinaryAPIResponse is a class in the anthropic-sdk-python codebase, defined in src/anthropic/_response.py.
Where is AsyncBinaryAPIResponse defined?
AsyncBinaryAPIResponse is defined in src/anthropic/_response.py at line 539.

Analyze Your Own Codebase

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

Try Supermodel Free