Google gemini-2.5-flash responses can throw several errors that are fatal to the worker
I've experienced both of these errors in the middle of a conversation. Both shut down the conversation and prevent further progress.
livekit.agents._exceptions.APIStatusError: gemini llm: client error (status_code=400, request_id=d18a6998476a, body=Please ensure that single turn requests end with a user role or the role field is empty.INVALID_ARGUMENT)
livekit.agents._exceptions.APIConnectionError: gemini llm: error generating content No candidates in the response (status_code=-1, request_id=bd1f1400344a, body=None)
I have seen the same
Same here even with flash-2.0. I cannot use session.generate_reply with any of the google models
This bug needs to be fixed as it causes applications to stop working completely and cannot be recovered. Sometimes, Google returns a None value in response.parts. According to some forums, this is due to content moderation, although subsequent requests work correctly.
could anyone share a repro? what sequence of actions would cause this to occur?
@davidzhao
You can try with a simple setup — GEMINI API keys have a free tier. You can also use Groq Whisper free tier and any TTS model.
It's difficult to reproduce the issue because Google sometimes returns None, but after that, the conversation seems to work fine. Trying with sensitive prompts might help to reproduce the problem.
The first Please ensure that single turn requests end with a user role should be already fixed in https://github.com/livekit/agents/pull/2183,
for the second No candidates in the response, probably we should just ignore the empty response instead of raising the error.
@longcw
Correct. Ignoring the No candidates in the response is the correct approach. I modified some lines of the original gemini plugin in my codebase to ignore the empty response
also experiencing this issue. it's especially bad for longer calls since this causes the entire call to fail, even with fallback adapters in place
{"message": "no candidates in the response: sdk_http_response=HttpResponse(\n headers=
The agent has stopped responding in the middle of the conversation, I am using the latest scripts only with the above fixes. Can anyone help me to resolve this issue?
"level": "WARNING"
if (
not response.candidates
or not response.candidates[0].content
or not response.candidates[0].content.parts
):
logger.warning(f"no candidates in the response: {response}")
continue
this is a warning and the conversation is allowed to continue. unfortunately if Gemini doesn't send back any responses, there's nothing we could do.
"level": "WARNING"if ( not response.candidates or not response.candidates[0].content or not response.candidates[0].content.parts ): logger.warning(f"no candidates in the response: {response}") continuethis is a warning and the conversation is allowed to continue. unfortunately if Gemini doesn't send back any responses, there's nothing we could do.
Thank you for your response. It seems to be working with Gemini 2.0 Flash instead of 2.5 Flash, based on the tests I’ve run so far—but I’m still not completely sure.
2025-09-18 04:17:28,022 - WARNING livekit.plugins.google - no candidates in the response: sdk_http_response=HttpResponse(
headers=
i am consistenly seeing this problem with gemini 2.5 flash but not in 2.0 flash