MCPcopy
hub / github.com/openai/openai-python / _process_response

Method _process_response

src/openai/_base_client.py:1133–1199  ·  src/openai/_base_client.py::SyncAPIClient._process_response
(
        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,
    )

Source from the content-addressed store, hash-verified

1131 time.sleep(timeout)
1132
1133 def _process_response(
1134 self,
1135 *,
1136 cast_to: Type[ResponseT],
1137 options: FinalRequestOptions,
1138 response: httpx.Response,
1139 stream: bool,
1140 stream_cls: type[Stream[Any]] | type[AsyncStream[Any]] | None,
1141 retries_taken: int = 0,
1142 ) -> ResponseT:
1143 if response.request.headers.get(RAW_RESPONSE_HEADER) == class="st">"true":
1144 return cast(
1145 ResponseT,
1146 LegacyAPIResponse(
1147 raw=response,
1148 client=self,
1149 cast_to=cast_to,
1150 stream=stream,
1151 stream_cls=stream_cls,
1152 options=options,
1153 retries_taken=retries_taken,
1154 ),
1155 )
1156
1157 origin = get_origin(cast_to) or cast_to
1158
1159 if (
1160 inspect.isclass(origin)
1161 and issubclass(origin, BaseAPIResponse)
1162 class="cm"># we only want to actually return the custom BaseAPIResponse class if we're
1163 class="cm"># returning the raw response, or if weclass="st">'re not streaming SSE, as if we're streaming
1164 class="cm"># SSE then `cast_to` doesn't actively reflect the type we need to parse into
1165 and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
1166 ):
1167 if not issubclass(origin, APIResponse):
1168 raise TypeError(fclass="st">"API Response types must subclass {APIResponse}; Received {origin}")
1169
1170 response_cls = cast(class="st">"type[BaseAPIResponse[Any]]", cast_to)
1171 return cast(
1172 ResponseT,
1173 response_cls(
1174 raw=response,
1175 client=self,
1176 cast_to=extract_response_type(response_cls),
1177 stream=stream,
1178 stream_cls=stream_cls,
1179 options=options,
1180 retries_taken=retries_taken,
1181 ),
1182 )
1183
1184 if cast_to == httpx.Response:
1185 return cast(ResponseT, response)
1186
1187 api_response = APIResponse(
1188 raw=response,
1189 client=self,
1190 cast_to=cast(class="st">"type[ResponseT]", cast_to), class="cm"># pyright: ignore[reportUnnecessaryCast]

Callers 1

requestMethod · 0.95

Calls 6

parseMethod · 0.95
LegacyAPIResponseClass · 0.85
extract_response_typeFunction · 0.85
APIResponseClass · 0.85
get_originFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected