Skip to content

[Bug] JSONDecodeError “Extra data” during generate_content_stream streaming (python-genai 1.21.1, Python 3.12) #1024

Closed

Description

@jimmy0251

✨ What happened?

I’m hitting this exception when using LiveKit’s livekit-plugins-google LLM integration ( https://github.com/livekit/agents/tree/main/livekit-plugins/livekit-plugins-google ), which in turn depends on googleapis/python-genai for streaming Gemini responses.

While streaming responses with GenerativeModel.generate_content_stream() (used via livekit-plugins-google), the client occasionally raises a json.decoder.JSONDecodeError: Extra data which bubbles up as an APIConnectionError:

Full traceback
Traceback (most recent call last):
  File "/home/appuser/.local/lib/python3.12/site-packages/livekit/plugins/google/llm.py", line 332, in _run
    async for response in stream:
  File "/home/appuser/.local/lib/python3.12/site-packages/google/genai/models.py", line 7484, in async_generator
    async for chunk in response:
  File "/home/appuser/.local/lib/python3.12/site-packages/google/genai/models.py", line 6394, in async_generator
    async for response_dict in response_stream:
  File "/home/appuser/.local/lib/python3.12/site-packages/google/genai/_api_client.py", line 1040, in async_generator
    async for chunk in response:
  File "/home/appuser/.local/lib/python3.12/site-packages/google/genai/_api_client.py", line 243, in __anext__
    return await self.segment_iterator.__anext__()
  File "/home/appuser/.local/lib/python3.12/site-packages/google/genai/_api_client.py", line 303, in async_segments
    yield json.loads(chunk)
  File "/usr/local/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.12/json/decoder.py", line 341, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 3 column 1 (char 407)

During handling of the above, another exception occurred:

livekit.agents._exceptions.APIConnectionError: gemini llm: error generating content Extra data: line 3 column 1 (char 407) (body=None, retryable=False)


Activity

  1. added
    type: bug
    priority: p2
    on Jun 24, 2025
  2. simplegr33n commented on Jun 26, 2025

    @simplegr33n

    Also seeing this issue. Using the latest livekit-agents and livekit-plugins-google but reverting the google-genai dependency to 1.17.0 resolves this issue for now for me. (Haven't tested versions after this yet so not sure when the regression occured)

  3. nilnor commented on Jun 26, 2025

    @nilnor

    Yes, thank you @jimmy0251 for opening the issue, this seems to be another issue in the ongoing Gemini reliability saga. Personally I'm using Agno with streaming, but it comes down to the python-genai library (agno code: await self.get_client().aio.models.generate_content_stream(..)) where get_client returns a google.genai.Client.

  4. sasha-gitg commented on Jun 26, 2025

    @sasha-gitg
    Member

    Please provide the Gemini model IDs that you are using when encountering this issue.

  5. nilnor commented on Jun 26, 2025

    @nilnor

    Please provide the Gemini model IDs that you are using when encountering this issue.

    gemini-2.5-pro, and also encountered this with gemini-2.5-flash-preview-05-20 unless my mind plays tricks on me.

  6. simplegr33n commented on Jun 26, 2025

    @simplegr33n

    gemini-2.5-flash-preview-05-20 for me. No issues on v1.20.0

  7. mbrian23 commented on Jun 27, 2025

    @mbrian23

    Same issue here—using the ADK (1.5.0) with google-genai (1.22.0) as a dependency

  8. self-assigned this
    on Jun 27, 2025
  9. sasha-gitg commented on Jun 27, 2025

    @sasha-gitg
    Member

    If using aiohttp, this PR may fix this issue - working on getting it in: https://github.com/googleapis/python-genai/pull/1048/files

  10. XinyueZ commented on Jun 27, 2025

    @XinyueZ

    An official release is needed as this is a critical issue causing significant disruptions.

  11. XinyueZ commented on Jun 27, 2025

    @XinyueZ

    @sasha-gitg fixing worked on my side

  12. janasangeetha commented on Jun 30, 2025

    @janasangeetha

    Hey users,
    We have similar issue #1010. Please follow up on the same!
    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

priority: p2type: bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions