MCPcopy Create free account
hub / github.com/anomalyco/opencode-sdk-python / AsyncBinaryAPIResponse

Class AsyncBinaryAPIResponse

src/opencode_ai/_response.py:499–522  ·  view source on GitHub ↗

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(

Source from the content-addressed store, hash-verified

497
498
499class AsyncBinaryAPIResponse(AsyncAPIResponse[bytes]):
500 """Subclass of APIResponse providing helpers for dealing with binary data.
501
502 Note: If you want to stream the response data instead of eagerly reading it
503 all at once then you should use `.with_streaming_response` when making
504 the API request, e.g. `.with_streaming_response.get_binary_response()`
505 """
506
507 async def write_to_file(
508 self,
509 file: str | os.PathLike[str],
510 ) -> None:
511 """Write the output to the given file.
512
513 Accepts a filename or any path-like object, e.g. pathlib.Path
514
515 Note: if you want to stream the data to the file instead of writing
516 all at once then you should use `.with_streaming_response` when making
517 the API request, e.g. `.with_streaming_response.get_binary_response()`
518 """
519 path = anyio.Path(file)
520 async with await path.open(mode="wb") as f:
521 async for data in self.iter_bytes():
522 await f.write(data)
523
524
525class StreamedBinaryAPIResponse(APIResponse[bytes]):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected