Get 'No generation chunks were returned' when use gemini-2.5-flash-preview-05-20

Hi, I am using gemini-2.5-flash-preview-05-20.
But sometimes it doesn’t return any data
My usage example is as follows:

from langchain.chat_models.base import init_chat_model
gemini = init_chat_model(model="gemini-2.5-flash-preview-05-20",model_provider="google_genai")
prompt = ChatPromptTemplate.from_messages(
            [
                SystemMessagePromptTemplate.from_template("xxx"),
            ]
chain = prompt | gemini
async for chunk in chain.astream({"history": history}, config=langfuse_handler_config):
    logger.info(f"Response chunk : {chunk.content}")

Most of the time it works normally
Occasionally, it throws an exception message stating ‘No generation chunks were returned’
For requests that throw exceptions, I retry and it returns chunks normally
I added debugging logs at the location of the RPC request calling the Gemini API, and everything is normal
How should I solve this problem? Or where else can I check?
Also, I would like to know if my usage method can control the token of thoughts

1 Like

Welcome to the forum!

It sounds like you’re encountering an intermittent issue where Gemini isn’t returning any generation chunks. This points to network glitches or instability. Have you noticed any unusual network behavior on your end when these errors occur?

No.
I think it may not be caused by network issues
I tried Gemini-2.5-flash-preview-04-17 and it had no issues

Could you please let me know if anything was changed when the error happened compared to when it worked?