This is a legacy class as it will be replaced by `APIResponse` and `AsyncAPIResponse` in the `_response.py` file in the next major release. For the sync client this will mostly be the same with the exception of `content` & `text` will be methods instead of properties. In the asy
| 43 | |
| 44 | |
| 45 | class LegacyAPIResponse(Generic[R]): |
| 46 | """This is a legacy class as it will be replaced by `APIResponse` |
| 47 | and `AsyncAPIResponse` in the `_response.py` file in the next major |
| 48 | release. |
| 49 | |
| 50 | For the sync client this will mostly be the same with the exception |
| 51 | of `content` & `text` will be methods instead of properties. In the |
| 52 | async client, all methods will be async. |
| 53 | |
| 54 | A migration script will be provided & the migration in general should |
| 55 | be smooth. |
| 56 | """ |
| 57 | |
| 58 | _cast_to: type[R] |
| 59 | _client: BaseClient[Any, Any] |
| 60 | _parsed_by_type: dict[type[Any], Any] |
| 61 | _stream: bool |
| 62 | _stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None |
| 63 | _options: FinalRequestOptions |
| 64 | |
| 65 | http_response: httpx.Response |
| 66 | |
| 67 | retries_taken: int |
| 68 | """The number of retries made. If no retries happened this will be `0`""" |
| 69 | |
| 70 | def __init__( |
| 71 | self, |
| 72 | *, |
| 73 | raw: httpx.Response, |
| 74 | cast_to: type[R], |
| 75 | client: BaseClient[Any, Any], |
| 76 | stream: bool, |
| 77 | stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None, |
| 78 | options: FinalRequestOptions, |
| 79 | retries_taken: int = 0, |
| 80 | ) -> None: |
| 81 | self._cast_to = cast_to |
| 82 | self._client = client |
| 83 | self._parsed_by_type = {} |
| 84 | self._stream = stream |
| 85 | self._stream_cls = stream_cls |
| 86 | self._options = options |
| 87 | self.http_response = raw |
| 88 | self.retries_taken = retries_taken |
| 89 | |
| 90 | @property |
| 91 | def request_id(self) -> str | None: |
| 92 | return self.http_response.headers.get("x-request-id") # type: ignore[no-any-return] |
| 93 | |
| 94 | @overload |
| 95 | def parse(self, *, to: type[_T]) -> _T: ... |
| 96 | |
| 97 | @overload |
| 98 | def parse(self) -> R: ... |
| 99 | |
| 100 | def parse(self, *, to: type[_T] | None = None) -> R | _T: |
| 101 | """Returns the rich python representation of this response's data. |
| 102 |
no outgoing calls