From acf350a2fb39ad9593028081d73f2dd54edbaba3 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Wed, 20 Nov 2024 15:15:21 -0800 Subject: [PATCH] fix check for streaming response --- .../pass_through_endpoints.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py index 7b9e17842..8be241458 100644 --- a/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py +++ b/litellm/proxy/pass_through_endpoints/pass_through_endpoints.py @@ -478,10 +478,9 @@ async def pass_through_request( # noqa: PLR0915 json=_parsed_body, ) - if ( - response.headers.get("content-type") is not None - and response.headers["content-type"] == "text/event-stream" - ): + verbose_proxy_logger.debug("response.headers= %s", response.headers) + + if _is_streaming_response(response) is True: try: response.raise_for_status() except httpx.HTTPStatusError as e: @@ -621,6 +620,13 @@ def create_pass_through_route( return endpoint_func +def _is_streaming_response(response: httpx.Response) -> bool: + _content_type = response.headers.get("content-type") + if _content_type is not None and "text/event-stream" in _content_type: + return True + return False + + async def initialize_pass_through_endpoints(pass_through_endpoints: list): verbose_proxy_logger.debug("initializing pass through endpoints")