class_docstr: Provides the core interface to iterate over a synchronous stream response.
class_docstr_tok: ["Provides","the","core","interface","to","iterate","over","a","synchronous","stream","response","."]
code: def __stream__(self) -> Iterator[_T]:
      cast_to = cast(Any, self._cast_to)
      response = self.response
      process_data = self._client._process_response_data
      iterator = self._iter_events()
  
      for sse in iterator:
          if sse.data.startswith("[DONE]"):
              break
  
          if sse.event is None:
              data = sse.json()
              if is_mapping(data) and data.get("error"):
                  raise APIError(
                      message="An error occurred during streaming",
                      request=self.response.request,
                      body=data["error"],
                  )
  
              yield process_data(
                  data=data, cast_to=cast_to, response=response
              )
  
      # Ensure the entire stream is consumed
      for _sse in iterator:
          ...
  
imports: from __future__ import annotations
  import json
  from types import TracebackType
  from typing import TYPE_CHECKING, Any, Generic, TypeVar, Iterator, AsyncIterator, cast
  from typing_extensions import Self, override
  import httpx
  from ._utils import is_mapping
  from ._exceptions import APIError
label_desc: Use image node_id 5 for calling the Stream obj's underlying member method code with example usage: obj.__stream__() without return types