python-genai: Live API Error: ConnectionClosedError - "Invalid Frame Payload Data"

Description

The live API has stopped working since yesterday and now throws an error during use for "response_modalities" = ["TEXT"]. Previously, it was functioning without any issues.

Environment details

  • Programming language: Python
  • OS: Linux Mint 21.2 (but the issue happens on other operating systems as well)
  • Language runtime version: Python 3.13.1
  • Package version: google-genai 0.5.0

Steps to Reproduce

Use the file from this repository: gemini-2/live_api_starter.py.

  1. Add GOOGLE_API_KEY.
  2. Change DEFAULT_MODE = "screen".
  3. Update CONFIG = {"generation_config": {"response_modalities": ["TEXT"]}}.
  4. Run the file.

Enter the following commands:

  • First, type: “What do you see on my screen?” (this works and returns a valid response).
  • Then, type: “What do you see on my screen now?”.
  • Observe the error.

Observed Behavior

The following error occurs during the second interaction:

ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception)
  +-+---------------- 1 ----------------
    Traceback (most recent call last):
      File "/projects/test/gemini_realtime_test.py", line 207, in receive_audio
        async for response in turn:
        ...<4 lines>...
                print(text, end="")
      File "/.venv/lib/python3.13/site-packages/google/genai/live.py", line 129, in receive
        while result := await self._receive():
                        ^^^^^^^^^^^^^^^^^^^^^
      File "/.venv/lib/python3.13/site-packages/google/genai/live.py", line 197, in _receive
        raw_response = await self._ws.recv(decode=False)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "/.venv/lib/python3.13/site-packages/websockets/asyncio/connection.py", line 313, in recv
        raise self.protocol.close_exc from self.recv_exc
    websockets.exceptions.ConnectionClosedError: received 1007 (invalid frame payload data) Request trace id: d9d7aa6c895b1708, [ORIGINAL ERROR] generic::invalid_argument: Image tensors read from serialized content ; then sent 1007 (invalid frame payload data) Request trace id: d9d7aa6c895b1708, [ORIGINAL ERROR] generic::invalid_argument: Image tensors read from serialized content

Expected Behavior

The second question should also return a valid response without errors, as it did before yesterday.

Additional Information

Error Code: 1007 (invalid frame payload data) Request Trace ID: d9d7aa6c895b1708

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (1 by maintainers)

Most upvoted comments

Hey Guys I experimented same issue with this, tried a lot of different solutions and nothing, after that I figured it out stuff that this companies done, so it’s a country problem, this is available only for some counties, for that reason gives error, so I started a VPN connection to US and starting working without any issue, so, not model issue, not code issue, not 3rd party issue (my case livekit) it’s google stopping request outside the US or some others selected countries, as always complicating development life. USE VPN should solve the problem 😉

Is it possible that this regression has returned?

If I have response modality TEXT, I get an error 1007 for Invalid Frame Payload Data.

Without text modality it works.

@RichardSieg Yes, when this issue was originally created, they seemed to have fixed it for the latest model available then (ie, gemini-2.0-flash-exp [as you can see the commented L35 here), but the underlying issue still persists for the latest/newer model(s).

Has anyone been able to find a workaround for this? I am still facing this error.

(PS - PFA a minimal reproducible example)

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
:author: pk13055
:brief: Analyze screen activity using Gemini AIO Live API - Batch Analysis
"""
import asyncio
import base64
import logging
import os
import sys

import pyautogui
from google import genai
from google.genai import types

GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")

# Set up logging
logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s - %(levelname)s - %(message)s",
    handlers=[
        logging.FileHandler("screen_analysis.log"),
        logging.StreamHandler(sys.stdout),
    ],
)


async def main():
    config = {
        "response_modalities": ["TEXT"],
    }
    client = genai.Client(api_key=GEMINI_API_KEY)
    # MODEL = "gemini-2.0-flash-exp"
    MODEL = "gemini-2.0-flash-live-001"
    async with client.aio.live.connect(model=MODEL, config=config) as session:
        payload = base64.b64encode(pyautogui.screenshot().tobytes())
        logging.info(f"Payload size: {len(payload.decode()) // 1024} kB")
        await session.send_client_content(
            turns=types.Content(
                role="user",
                parts=[
                    types.Part.from_bytes(
                        data=payload,
                        mime_type="image/jpeg",
                    ),
                    types.Part(
                        text="Generate a summary of the user activity based on the screenshot provided"
                    ),
                ],
            ),
        )
        logging.info("Screenshot and prompt sent")
        async for response in session.receive():
            if response.text is not None:
                print(response.text, end="")
            print()


if __name__ == "__main__":
    asyncio.run(main())

Looking into it.