(
self,
*,
cast_to: Type[ResponseT],
options: FinalRequestOptions,
response: httpx.Response,
stream: bool,
stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None,
retries_taken: int = 0,
)
| 1742 | await anyio.sleep(timeout) |
| 1743 | |
| 1744 | async def _process_response( |
| 1745 | self, |
| 1746 | *, |
| 1747 | cast_to: Type[ResponseT], |
| 1748 | options: FinalRequestOptions, |
| 1749 | response: httpx.Response, |
| 1750 | stream: bool, |
| 1751 | stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None, |
| 1752 | retries_taken: int = 0, |
| 1753 | ) -> ResponseT: |
| 1754 | if response.request.headers.get(RAW_RESPONSE_HEADER) == class="st">"true": |
| 1755 | return cast( |
| 1756 | ResponseT, |
| 1757 | LegacyAPIResponse( |
| 1758 | raw=response, |
| 1759 | client=self, |
| 1760 | cast_to=cast_to, |
| 1761 | stream=stream, |
| 1762 | stream_cls=stream_cls, |
| 1763 | options=options, |
| 1764 | retries_taken=retries_taken, |
| 1765 | ), |
| 1766 | ) |
| 1767 | |
| 1768 | origin = get_origin(cast_to) or cast_to |
| 1769 | |
| 1770 | if ( |
| 1771 | inspect.isclass(origin) |
| 1772 | and issubclass(origin, BaseAPIResponse) |
| 1773 | class="cm"># we only want to actually return the custom BaseAPIResponse class if we're |
| 1774 | class="cm"># returning the raw response, or if weclass="st">'re not streaming SSE, as if we're streaming |
| 1775 | class="cm"># SSE then `cast_to` doesn't actively reflect the type we need to parse into |
| 1776 | and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER))) |
| 1777 | ): |
| 1778 | if not issubclass(origin, AsyncAPIResponse): |
| 1779 | raise TypeError(fclass="st">"API Response types must subclass {AsyncAPIResponse}; Received {origin}") |
| 1780 | |
| 1781 | response_cls = cast(class="st">"type[BaseAPIResponse[Any]]", cast_to) |
| 1782 | return cast( |
| 1783 | class="st">"ResponseT", |
| 1784 | response_cls( |
| 1785 | raw=response, |
| 1786 | client=self, |
| 1787 | cast_to=extract_response_type(response_cls), |
| 1788 | stream=stream, |
| 1789 | stream_cls=stream_cls, |
| 1790 | options=options, |
| 1791 | retries_taken=retries_taken, |
| 1792 | ), |
| 1793 | ) |
| 1794 | |
| 1795 | if cast_to == httpx.Response: |
| 1796 | return cast(ResponseT, response) |
| 1797 | |
| 1798 | api_response = AsyncAPIResponse( |
| 1799 | raw=response, |
| 1800 | client=self, |
| 1801 | cast_to=cast(class="st">"type[ResponseT]", cast_to), class="cm"># pyright: ignore[reportUnnecessaryCast] |
no test coverage detected