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

BinaryAPIResponse Class — anthropic-sdk-python Architecture

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

Entity Profile

Dependency Diagram

graph TD
  05ceaa32_22bc_1d4b_0106_148d5206e33f["BinaryAPIResponse"]
  2e9c15bb_de03_aa91_93be_0e05db0a552e["_response.py"]
  05ceaa32_22bc_1d4b_0106_148d5206e33f -->|defined in| 2e9c15bb_de03_aa91_93be_0e05db0a552e
  deb631da_c08f_054c_d5f9_873fa302a083["write_to_file()"]
  05ceaa32_22bc_1d4b_0106_148d5206e33f -->|method| deb631da_c08f_054c_d5f9_873fa302a083

Relationship Graph

Source Code

src/anthropic/_response.py lines 514–536

class BinaryAPIResponse(APIResponse[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()`
    """

    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()`
        """
        with open(file, mode="wb") as f:
            for data in self.iter_bytes():
                f.write(data)

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free