Skip to content
18 changes: 9 additions & 9 deletions google/genai/_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down