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