From b57b2a50bb67f139ba34ec9ef73173ac702a2d05 Mon Sep 17 00:00:00 2001 From: Tai An Date: Fri, 8 May 2026 03:21:38 -0700 Subject: [PATCH 1/2] fix(proxy): decode bytes and pass-through SSE for Google-native streamGenerateContent (#27444) --- litellm/proxy/proxy_server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index c96d0acb008b..2d25f98f8a47 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -6524,6 +6524,18 @@ async def async_data_generator( if isinstance(chunk, BaseModel): chunk = chunk.model_dump_json(exclude_none=True, exclude_unset=True) + elif isinstance(chunk, bytes): + # Some upstream streaming iterators (e.g. AsyncGoogleGenAIGenerateContentStreamingIterator + # for /v1beta/.../streamGenerateContent) yield raw SSE bytes from Gemini. + # Decode to str so the f-string below does not emit a Python b'...' literal, + # and pass already-formatted SSE through unchanged to avoid double "data:" prefix. + chunk = chunk.decode("utf-8", errors="replace") + if chunk.startswith(("data:", "event:", ":")): + try: + yield chunk if chunk.endswith("\n\n") else chunk + "\n\n" + except Exception as e: + yield f"data: {str(e)}\n\n" + continue elif isinstance(chunk, str) and chunk.startswith("data: "): error_message = chunk break From dac05ec99cbacc1def4deb9b317ebfb4cf9e6215 Mon Sep 17 00:00:00 2001 From: Tai An Date: Fri, 8 May 2026 06:15:02 -0700 Subject: [PATCH 2/2] chore(lint): silence PLR0915 on async_data_generator (matches existing convention) --- litellm/proxy/proxy_server.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 2d25f98f8a47..9585a608eca2 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -6484,7 +6484,7 @@ def _restamp_streaming_chunk_model( return chunk, model_mismatch_logged -async def async_data_generator( +async def async_data_generator( # noqa: PLR0915 response, user_api_key_dict: UserAPIKeyAuth, request_data: dict ): verbose_proxy_logger.debug("inside generator")