_process_response() — anthropic-sdk-python Function Reference
Architecture documentation for the _process_response() function in _base_client.py from the anthropic-sdk-python codebase.
Entity Profile
Dependency Diagram
graph TD ae4395b9_e9e7_d7f2_e944_36fea3691100["_process_response()"] 3224f719_8046_78c8_59e1_47301a46ddd4["AsyncAPIClient"] ae4395b9_e9e7_d7f2_e944_36fea3691100 -->|defined in| 3224f719_8046_78c8_59e1_47301a46ddd4 68dab0d8_6666_69f9_2947_acd899897b96["_process_response()"] 68dab0d8_6666_69f9_2947_acd899897b96 -->|calls| ae4395b9_e9e7_d7f2_e944_36fea3691100 c21c2971_d83f_0afc_9811_0642b34cfcd3["request()"] c21c2971_d83f_0afc_9811_0642b34cfcd3 -->|calls| ae4395b9_e9e7_d7f2_e944_36fea3691100 68dab0d8_6666_69f9_2947_acd899897b96["_process_response()"] ae4395b9_e9e7_d7f2_e944_36fea3691100 -->|calls| 68dab0d8_6666_69f9_2947_acd899897b96 02577dbd_844f_c3ef_09b1_c927dbc9a604["extract_response_type()"] ae4395b9_e9e7_d7f2_e944_36fea3691100 -->|calls| 02577dbd_844f_c3ef_09b1_c927dbc9a604 afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7["get()"] ae4395b9_e9e7_d7f2_e944_36fea3691100 -->|calls| afc80c40_7ec9_e8a7_8063_f2ab74bc2ee7 cd4d4a4e_4ea8_4346_3324_a03f797485c7["parse()"] ae4395b9_e9e7_d7f2_e944_36fea3691100 -->|calls| cd4d4a4e_4ea8_4346_3324_a03f797485c7 style ae4395b9_e9e7_d7f2_e944_36fea3691100 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/anthropic/_base_client.py lines 1805–1871
async def _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,
) -> ResponseT:
if response.request.headers.get(RAW_RESPONSE_HEADER) == "true":
return cast(
ResponseT,
LegacyAPIResponse(
raw=response,
client=self,
cast_to=cast_to,
stream=stream,
stream_cls=stream_cls,
options=options,
retries_taken=retries_taken,
),
)
origin = get_origin(cast_to) or cast_to
if (
inspect.isclass(origin)
and issubclass(origin, BaseAPIResponse)
# we only want to actually return the custom BaseAPIResponse class if we're
# returning the raw response, or if we're not streaming SSE, as if we're streaming
# SSE then `cast_to` doesn't actively reflect the type we need to parse into
and (not stream or bool(response.request.headers.get(RAW_RESPONSE_HEADER)))
):
if not issubclass(origin, AsyncAPIResponse):
raise TypeError(f"API Response types must subclass {AsyncAPIResponse}; Received {origin}")
response_cls = cast("type[BaseAPIResponse[Any]]", cast_to)
return cast(
"ResponseT",
response_cls(
raw=response,
client=self,
cast_to=extract_response_type(response_cls),
stream=stream,
stream_cls=stream_cls,
options=options,
retries_taken=retries_taken,
),
)
if cast_to == httpx.Response:
return cast(ResponseT, response)
api_response = AsyncAPIResponse(
raw=response,
client=self,
cast_to=cast("type[ResponseT]", cast_to), # pyright: ignore[reportUnnecessaryCast]
stream=stream,
stream_cls=stream_cls,
options=options,
retries_taken=retries_taken,
)
if bool(response.request.headers.get(RAW_RESPONSE_HEADER)):
return cast(ResponseT, api_response)
return await api_response.parse()
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does _process_response() do?
_process_response() is a function in the anthropic-sdk-python codebase, defined in src/anthropic/_base_client.py.
Where is _process_response() defined?
_process_response() is defined in src/anthropic/_base_client.py at line 1805.
What does _process_response() call?
_process_response() calls 4 function(s): _process_response, extract_response_type, get, parse.
What calls _process_response()?
_process_response() is called by 2 function(s): _process_response, request.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free