Random WebSocket closures after sendToolResponse() on Gemini Live API
Has anyone else run into this?
When I send tool responses via sendToolResponse(), the Gemini Live WebSocket sometimes just dies — either with code 1011 (“Internal error occurred”) or 1008 (“Requested entity was not found”). It doesn’t happen every time, just randomly after a tool call finishes.
The worst part is the error messages are totally opaque. No clue whether it’s the payload size, format, encoding, tool call ID mismatch, or something else. Debugging this is basically guesswork.
I confirmed that this only happens with gemini-2.5-flash-native-audio-preview-09-2025 Downgrading to gemini-live-2.5-flash-preview solves that issue. Unfortunately this model has relatively poor perfomance in other ways.
What’s happening
Actual behavior:
-
Tool runs fine
-
Response gets sanitized and formatted
-
I call
sendToolResponse({ functionResponses }) -
WebSocket closes immediately with 1011 or 1008
-
No extra info, no logs, nothing useful
Expected behavior:
Either it should accept the response, or at least tell me why it’s unhappy, like “too large,” “bad format,” or “invalid tool ID.”
Setup details
-
Model:
gemini-2.5-flash-native-audio-preview-09-2025 -
Using
responseModalities: [Modality.AUDIO]andoutputAudioTranscription: {} -
Tools defined as an array of objects with
functionDeclarations
Response format:
{
functionResponses: [
{
id: "uuid-string",
name: "tool-name",
response: {
output: "string-response-content" // plain string, not JSON
}
}
]
}
Size handling:
-
Max 8k chars for some tools, 3k for others
-
Newlines collapsed, whitespace normalized
-
Warn if over 10k chars but still send
What I’ve noticed
-
Totally random — not linked to specific tools or sizes
-
Long responses might fail more often, but not always
-
Both 1011 and 1008 happen under the same conditions
-
1008 sounds like a bad tool call ID, but I double-checked and the IDs always match
Open questions
-
Any hidden limits on characters or encoding in the
outputfield? -
Should the
outputbe plain text only, or is JSON-stringified data okay? -
What exactly triggers 1008 (“Requested entity was not found”)?
-
And most importantly — why does it happen randomly?
Honestly, the API’s error output could be way more friendly here. Right now it just feels like shooting in the dark. Anyone figured out what’s actually causing this?