From 7346ca42655f83fd9c2e0d25f0db15f4fc5664f1 Mon Sep 17 00:00:00 2001 From: CaroyalKnight <95287887+CaroyalKnight@users.noreply.github.com> Date: Thu, 11 Jun 2026 09:24:51 +0800 Subject: [PATCH 1/2] fix: Support both "data:" and "data: " --- google/genai/_api_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/google/genai/_api_client.py b/google/genai/_api_client.py index e6202815e..a3d180225 100644 --- a/google/genai/_api_client.py +++ b/google/genai/_api_client.py @@ -362,10 +362,10 @@ def _iter_response_stream(self) -> Iterator[str]: data_buffer = [] continue - # In streaming mode, the response of JSON is prefixed with "data: " which + # In streaming mode, the response of JSON is prefixed with either "data:" or "data: " which # we must strip before parsing. - if line.startswith('data: '): - data_buffer.append(line[len('data: '):]) + if line.startswith('data:'): + data_buffer.append(line[len('data:'):].lstrip()) continue # When API returns an error message, it comes line by line. So we buffer From 4d9f6953a0f5210c9f0844d67ac03ef96c5d28f2 Mon Sep 17 00:00:00 2001 From: CaroyalKnight <95287887+CaroyalKnight@users.noreply.github.com> Date: Sat, 13 Jun 2026 10:26:50 +0800 Subject: [PATCH 2/2] fix: Adjust compatibility for other instances of "data:" and "data: " --- google/genai/_api_client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/google/genai/_api_client.py b/google/genai/_api_client.py index e92615b6a..2fa2e727a 100644 --- a/google/genai/_api_client.py +++ b/google/genai/_api_client.py @@ -412,10 +412,10 @@ async def _aiter_response_stream(self) -> AsyncIterator[str]: yield '\n'.join(data_buffer) data_buffer = [] continue - # In streaming mode, the response of JSON is prefixed with "data: " + # In streaming mode, the response of JSON is prefixed with either "data:" or "data: " # which we must strip before parsing. - if line.startswith('data: '): - data_buffer.append(line[len('data: '):]) + if line.startswith('data:'): + data_buffer.append(line[len('data:'):].lstrip()) continue # When API returns an error message, it comes line by line. So we buffer @@ -465,10 +465,10 @@ async def _aiter_response_stream(self) -> AsyncIterator[str]: data_buffer = [] continue - # In streaming mode, the response of JSON is prefixed with "data: " + # In streaming mode, the response of JSON is prefixed with either "data:" or "data: " # which we must strip before parsing. - if line.startswith('data: '): - data_buffer.append(line[len('data: '):]) + if line.startswith('data:'): + data_buffer.append(line[len('data:'):].lstrip()) continue # When API returns an error message, it comes line by line. So we