Gemini API: Missing Line Breaks After Extended Usage

Hi everyone,

I’m experiencing an odd issue with the Gemini API (via OpenAI-compatible API) and wanted to check if others are encountering this or might have a solution.

Problem:

  • Initially, everything works fine with correct formatting
  • After some time/when the conversation gets longer, some line breaks suddenly are missing
  • For example the model omits likebreaks before and after codeblocks

Technical Details:

  • Model used: gemini-exp-1206
  • Access via OpenAI-compatible API
  • Default settings for temperature etc.

Observations:

  • Responses are correct content-wise, just missing many linebreaks.

The strange thing is I cannot see this in the AI Studio

  • When I tell Gemini the issue, it sometimes fixes itself. Therefore I am not sure if it is the model or encoding or something else.

Has anyone experienced something similar or knows of a workaround? Could this be a bug in the API implementation?

This for example never happens with the Open AI API or Anthropic API, it has to be something with the Gemini API or the model.

Thanks for your help!

Best regards,
Michaek

Having exactly the same issue, using Gemini API. I tried forcing line breaks in the prompt, but after some time it just forget about it. Anyone found a solution?

1 Like

Hi @federico.dec Welcome to the community
Could you please specify which model you are currently utilizing? Could you kindly provide details regarding the approximate token count at which this occurs, along with a reproducible set of steps so we can investigate this on our end?
Thank you

Hi,
I’m using Gemini 2.5 Flash within GPT Chatbot ptchatbot solution which is integrated through Gemini API.
There is a prompt contanining instructions including a style section mentioning to add line breaks between sentences.
It works for the first 3-4 messages but then just forget about it.
You can see it in the example screenshot (in the first it works well, in the second one forgets line breaks):

Same here, looks like formating issue