From 9f916636e156ab31e0707ce95285b0ca7f0dc4a3 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 20 Nov 2024 13:18:51 -0800 Subject: [PATCH] fix get_response_body --- .../pass_through_endpoints/pass_through_endpoints.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index 548d07689..7b9e17842 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -45,11 +45,11 @@ router = APIRouter() pass_through_endpoint_logging = PassThroughEndpointLogging() -def get_response_body(response: httpx.Response): +def get_response_body(response: httpx.Response) -> Optional[dict]: try: return response.json() except Exception: - return response.text + return None async def set_env_variables_in_header(custom_headers: Optional[dict]) -> Optional[dict]: @@ -519,10 +519,12 @@ async def pass_through_request( # noqa: PLR0915 content = await response.aread() ## LOG SUCCESS - passthrough_logging_payload["response_body"] = get_response_body(response) + response_body: Optional[dict] = get_response_body(response) + passthrough_logging_payload["response_body"] = response_body end_time = datetime.now() await pass_through_endpoint_logging.pass_through_async_success_handler( httpx_response=response, + response_body=response_body, url_route=str(url), result="", start_time=start_time,