Using gemini live API, I’m sending text data as per documentation:
await session.send_client_content( turns={"role": "user", "parts": [{"text": message}]}, turn_complete=True )
However, occasionally (5 out of 10 times) I’m getting invalid payload error when receiving data from gemini:
async for response in session.receive():
I am catching websocket ConnectionClosedError and logging it:
received 1007 invalid frame payload data) Request contains an invalid argument.; then sent 1007 (invalid frame payload data)
Request contains an invalid argument.
what am I doing wrong? The error also does not mentions which argument is invalid.
Is anyone else facing similar issue?
I am also facing the same issue. The conversation works for the first interaction but it throws this error from the next turn
This just started happening to me too, here’s the relevant excerpt from my logs:
received event LiveServerMessage { setupComplete: {} }
received event LiveServerMessage { serverContent: { outputTranscription: {} } }
received event LiveServerMessage {
serverContent: { outputTranscription: { finished: true } }
}
live onclose clean? true code 1007 reason Request contains an invalid argument.
Latest JS SDK, no recent changes to my connection params or what I send to the model.
Did you ever resolve this?
I still haven’t found why is this happening or how to resolve this.
For model: gemini-live-2.5-flash-preview-native-audio
I found this : if response_modalities
contains TEXT, this error will occur.
If response_modalities only contain AUDIO, this error will not happen.
If you use python google-genai, response_modalities
is in genai.types.LiveConnectConfig, and will be used as client.aio.live.connect’s param, config
.
if you use native websocket, the response_modalities will be send at first:
{
“setup”: {
“model”: MODEL,
“generation_config”: {
“response_modalities”: [“AUDIO”],
},
}
}
found the correct way to get both text and audio output from gemini-2.5-flash-preview-native-audio-dialog
.
Working Solution
Don’t use response_modalities=["AUDIO", "TEXT"]
- this causes errors.
Instead, use output_audio_transcription
:
python
config = types.LiveConnectConfig(
response_modalities=["AUDIO"], # Audio only here
output_audio_transcription=types.AudioTranscriptionConfig() # This enables text
)
Then handle both outputs in your receive loop:
python
async for response in session.receive():
# Text transcription
if response.server_content and response.server_content.output_transcription:
text = response.server_content.output_transcription.text
display_subtitles(text) # Perfect for subtitles!
# Audio data
if response.server_content and response.server_content.model_turn:
for part in response.server_content.model_turn.parts:
if part.audio and part.audio.data:
play_audio(part.audio.data)
Hope this helps others facing the same issue!