Gemini 1.5 flash continually generating same text until reach max limit of token

For some prompts model fall under a infinite loop and generate a very long response that leads to repetitive lines and hit max limit of tokens.

it is very annoying, waste of tokens, money. Is there any solution of it

Welcome to the forums!

What models are you seeing this in?
Can you give any example prompts that are causing the issue?

A workaround is to set the maxTokens parameter to a lower value than the default 8k, but I assume that’s not what you’re asking about.