#26755 [Bug]: Gemini CLI error when calling to LiteLLM - "Please ensure that function response turn comes immediately after a function call turn"
# [Bug]: Gemini `generateContent` returns 400 when payload violates `functionCall` → `functionResponse` ordering
## Check for existing issues
- [x] I have searched the existing issues and checked that my issue is not a duplicate.
---
## What happened?
When calling Gemini models through the LiteLLM proxy's `/v1beta/models/{model}:generateContent` endpoint, requests fail with a **400 Bad Request** if the `contents` array does not strictly follow Gemini's tool-calling sequence rules.
Gemini requires that:
1. A `functionResponse` part **must** appear in a `user` turn that comes **immediately after** a `model` turn containing the matching `functionCall`. 2. Two consecutive turns with the same `role` (e.g. two `user` turns in a row) are not permitted when one of them carries a `functionResponse`.
When these rules are violated — which can happen organically in agentic workflows where tool history accumulates across multiple turns — Gemini rejects the request with:
``` "Please ensure that function response turn comes immediately after a function call turn." ```
LiteLLM forwards this 400 directly to the client without normalizing the message sequence, so any client that builds Gem…