Gemini "Requests ending with a model turn are not supported": the cause and the fix Google's Gemini API now returns a 400 INVALID_ARGUMENT error with the message "Requests ending with a model turn are not supported" when the last non-empty turn in a request's contents has the role model, starting with Gemini 3.6 Flash and Gemini 3.5 Flash-Lite and applying to all later models including Gemini 3.8 Flash and the Gemini 4 models. The change breaks prefill code that worked on Gemini 2.5 and 3.5 Flash, and on October 8, 2026 the API began routing gemini-3.5-flash requests to gemini-3.6-flash, so unchanged code started failing; on December 1, 2026 gemini-2.5-pro routes to gemini-3.8-flash and gemini-2.5-flash routes to gemini-3.5-flash-lite, both of which reject prefill. Google's migration guide directs developers to end every request on a non-empty user turn, replace prefill with system_instruction or structured output, and send a function response for every functionCall, including cancelled ones, before the next request. ← all posts https://www.evalshift.dev/blog Gemini "Requests ending with a model turn are not supported": the cause and the fix Gemini 3.6 Flash and later return a 400 when a request ends on a model turn. Why prefill stopped working, five causes in agent loops, and the fix. Gemini returns 400 INVALID ARGUMENT with the message "Requests ending with a model turn are not supported." when the last non-empty turn in contents has the role model . Starting with Gemini 3.6 Flash and Gemini 3.5 Flash-Lite, Google no longer supports prefilling a model turn, and the rule applies to every later Gemini model too, Gemini 3.8 Flash and the Gemini 4 models included. Code that worked on Gemini 2.5 or 3.5 Flash breaks on the first request. The fix takes three changes: - + End every request on a user turn that has content. That turn is the user's text or the function responses for the model's last function calls. An empty user turn does not count: Google checks the last non-empty turn. - + Replace prefill with system instruction or structured output. If you prefilled { to force JSON or Translation: to suppress a preamble, Google's migration guide names those two as the replacements. - + Close every function call before the next request. Send a function response for each functionCall the model made, including a cancelled one, in a user turn with the call's id and name . You may not have changed anything in your code. On October 8, 2026 the Gemini API started routing requests for gemini-3.5-flash to gemini-3.6-flash , so prefill code that never changed its model string began returning this error. On December 1, 2026 the Gemini API does the same to gemini-2.5-pro routed to gemini-3.8-flash and gemini-2.5-flash routed to gemini-3.5-flash-lite . Both targets reject prefill. The rest of this post covers the exact error, the five ways an agent loop ends up sending a model turn last, code for each fix, and Claude's version of the same 400. Facts were checked against Google's and Anthropic's docs on November 17, 2026. The error On the Gemini API, and on Vertex AI now documented as Gemini Enterprise Agent Platform , the response body is: { "error": { "code": 400, "message": "Requests ending with a model turn are not supported.", "status": "INVALID ARGUMENT" } } It is a client error, so retrying the same request fails the same way. One voice-agent framework reported its agent going silent because it wrapped this 400 as a retryable connection error and resent the same history in a loop. Treat it as a bug in the request, not as an outage. Why Gemini rejects a request that ends on a model turn Google's Gemini 3.6 migration guide ↗ https://aistudio.google.com/docs/whats-new-gemini-3.6 prefilled-model-turn-validation lists it as one of two API changes that start with Gemini 3.6 Flash and Gemini 3.5 Flash-Lite and "apply to these models and all future Gemini model releases": prefilling model turns is no longer supported, and if the last non-empty turn is a model turn, the API returns a 400 . The Gemini 3.8 Flash checklist repeats it as "Remove prefilled model turns and ensure the final user turn contains non-empty text." Vertex's Gemini 3.8 Flash guide ↗ https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/guides/gemini-3-8-flash says history payloads cannot end with a model role turn. Prefill was a common technique. You end contents with a partial model turn, and the model continues from it: { "contents": {"role": "user", "parts": {"text": "Translate 'Hello world' to Spanish."} }, {"role": "model", "parts": {"text": "Translation:"} } } Gemini 2.5 and the 3.x models before 3.6 Flash accept this request, and Gemini 3.6 Flash and every later model reject it. Here is which model IDs fall on which side, and the reroutes that move a model ID across without a code change: | Model ID you call | Prefill / model turn last | Notes | |---|---|---| | gemini-2.5-pro , gemini-2.5-flash on the Gemini API | Accepted until December 1, 2026 | From December 1 these route to gemini-3.8-flash and gemini-3.5-flash-lite and get the 400 | | gemini-3.5-flash on the Gemini API | 400 since October 8, 2026 | Routed to gemini-3.6-flash | | gemini-3.6-flash , gemini-3.5-flash-lite | 400 | The models the rule started with | | gemini-3.7-flash on the Gemini API | 400 | Routed to gemini-3.8-flash since October 8, 2026 | | gemini-3.8-flash , gemini-4- | 400 | "All future Gemini model releases" | The reroutes are why this error spikes without a deploy. The Gemini model deprecation checklist https://www.evalshift.dev/blog/gemini-model-deprecation-migration-checklist has the full list of dates for both surfaces. Five ways an agent loop ends on a model turn Most reports of this error come from agent frameworks, not from code that prefills on purpose. Before you change anything, print the role and part types of the last three entries in contents for a failing request. One of these five patterns is almost always the cause. 1. + Deliberate prefill. A trailing model turn with { , json , Answer: or a persona opener, added to force a format. This is the case Google's guide describes. 2. + Continuation after a cut-off answer. When a response stops at MAX TOKENS , some code appends the partial answer as a model turn and calls again so the model continues from it. That is a prefill too. 3. + An empty last user turn. Google checks the last non-empty turn, and its 3.8 Flash guide says empty turns are dropped or fail validation. A user turn with "" , only whitespace, or a part your SDK serializes to nothing leaves the model turn before it last. The voice-agent report above was this case. The user interrupted the agent mid-reply, the interruption produced an empty user message, it was dropped, and the request ended on the partial reply. 4. + An unanswered function call. The model's functionCall turn is appended to history, but the tool was cancelled, timed out or never ran, so no function response follows it. The next request ends on that model turn. Several framework issues trace the error to detached or cancelled tool calls. 5. + History rebuilt in the wrong order. History reloaded from a database sorted by a timestamp that went backwards, trimmed to fit the context window from the wrong end, or merged from two sessions can put a model turn last. One coding agent hit it after a backward clock step made stored message IDs non-monotonic. Framework issues on GitHub describe two more triggers, but Google's docs don't: a function response that is only an image, and a user turn that mixes a functionResponse part with a text part. Google's 3.8 Flash checklist tells you to place multimodal assets inside the function response payload. If your tools return images, check that first. Fix 1: end every request on a non-empty user turn Check the request before sending it, and fail in your own code with a message that points at the bug, instead of getting a 400 from Google. With the google-genai SDK: php from google.genai import types def has content part: types.Part - bool: if part.text is not None: return bool part.text.strip return any part.function call, part.function response, part.inline data, part.file data def check ends on user turn contents: list types.Content - None: """Raise if Gemini 3.6+ would reject this history with a 400.""" for content in reversed contents : if any has content p for p in content.parts or : if content.role = "user": raise ValueError f"history ends on a {content.role r} turn; " "Gemini 3.6 Flash and later reject prefilled model turns" return raise ValueError "history has no non-empty turn" Call it right before client.models.generate content ... . Then fix the cause the check reports. Don't make the error go away by appending a filler user turn such as "Continue.": that changes what the model is answering, and it hides causes 3 to 5, which are bugs in your history handling. The exception is continuing a cut-off answer cause 2 . There you do want the model to go on, so say so in a real user turn, for example "Your previous answer stopped mid-sentence. Continue from the last complete sentence without repeating it." Or raise max output tokens and skip the continuation. Fix 2: replace prefill with system instruction or structured output Prefill had two jobs: suppress the preamble and force a format. Google's guide gives a replacement for each. To suppress a preamble, say so in system instruction : python from google import genai client = genai.Client response = client.models.generate content model="gemini-3.8-flash", contents="Translate 'Hello world' to Spanish.", config={"system instruction": "Output only the translation, with no introductory text."}, To force JSON, use structured output instead of a prefilled { . The schema is enforced by the API, which a prefill never guaranteed: python from pydantic import BaseModel class Verdict BaseModel : label: str confidence: float response = client.models.generate content model="gemini-3.8-flash", contents=f"Classify this support ticket: {ticket text}", config={ "response mime type": "application/json", "response json schema": Verdict.model json schema , }, verdict = Verdict.model validate json response.text If you prefilled a persona opener or a few words to steer the tone, that moves into system instruction too. Removing a prefill changes the output even when the request succeeds, so compare the old and new answers on real inputs before you ship see the last section . Fix 3: close every function call before the next request In the function-calling loop, a turn that ends with a functionCall must be followed by a user turn that carries a function response for each call, with the call's id and name . Google's 3.8 Flash checklist requires both fields on every FunctionResponse in generateContent . Append the model's turn exactly as returned, because Gemini 3 models expect their thought signatures back in function-calling history. Google's changelog lists thought signature validation among the breaking changes for the December 1 reroutes. response = client.models.generate content model="gemini-3.8-flash", contents=contents, config=config model turn = response.candidates 0 .content contents.append model turn as returned, thought signatures included calls = p.function call for p in model turn.parts if p.function call if calls: parts = for call in calls: try: result = {"result": run tool call.name, call.args } except ToolCancelled: result = {"error": "The tool call was cancelled before it finished."} parts.append types.Part.from function response name=call.name, response=result, id=call.id contents.append types.Content role="user", parts=parts A cancelled or failed tool still gets a function response, with the error in it. The model can then explain the failure or try something else, and the history never ends on the model's call. If the user interrupted, add their new message as text in that same user turn after the function responses, or as the next user turn. Don't drop it. Claude returns the same kind of 400 If you route the same agent to Claude, the equivalent rule is older. Anthropic's API errors page ↗ https://platform.claude.com/docs/en/api/errors prefill-not-supported says Claude 4.6 and later models, and Claude Mythos Preview, do not support prefilling the assistant message. A request whose last message is a prefilled assistant turn returns a 400 invalid request error : { "type": "error", "error": { "type": "invalid request error", "message": "This model does not support assistant message prefill. The conversation must end with a user message." } } Anthropic's replacements match Google's: structured outputs, instructions in the system prompt, or output config.format . The check from fix 1 carries over. The last message must have the role user , and in Claude's tool loop that is the message carrying the tool result blocks. The difference is that Claude 4.5 and earlier still accept prefill. Gemini enforces the rule on every model from 3.6 Flash on, and the reroutes move older model IDs onto it. Test the fix before December 1 The 400 is the easy part, because it fails on the first request. The quieter problem is the request that now succeeds: a translation that gained a preamble once the prefill was gone, a JSON route whose schema now forces a field the prompt used to leave out, an agent that picks a different tool after its cancelled call reads as an error. You only see those by running the same real inputs before and after the change and diffing the outputs and tool calls. Disclosure: I'm the founder of EvalShift, which does that diff. The capture SDK wraps the google-genai client and records real agent runs, tool calls included, and compare replays them against another model: python from google import genai from evalshift import capture from evalshift.adapters.genai import wrap genai client = wrap genai genai.Client each generate content inside a capture records one call TOOLS = ... the tools the agent is offered, or for none @capture.agent suite="support", redact=True, tools=TOOLS no-op unless EVALSHIFT CAPTURE=1 def handle ticket message : ... pip install "evalshift google-genai " EVALSHIFT CAPTURE=1 python my agent.py record production-shaped runs evalshift capture sync recorded runs - golden suite evalshift compare --suite-name support --to gemini-3.8-flash Run it while gemini-2.5-pro or gemini-2.5-flash still answers as itself, before December 1, so the baseline is the model you actually shipped on. Docs: /docs/sdk-adapters https://www.evalshift.dev/docs/sdk-adapters , /docs/captures https://www.evalshift.dev/docs/captures , /docs/migration-policy https://www.evalshift.dev/docs/migration-policy . FAQ What does "Requests ending with a model turn are not supported" mean? The last non-empty entry in your request's contents has the role model . Gemini 3.6 Flash, Gemini 3.5 Flash-Lite and every later Gemini model reject that with a 400 INVALID ARGUMENT , because Google no longer supports prefilling a model turn. End the request on a non-empty user turn: the user's text, or the function responses for the model's last function calls. Why did the error start without a code change? Google reroutes deprecated model IDs on the Gemini API. Since October 8, 2026, requests for gemini-3.5-flash go to gemini-3.6-flash and requests for gemini-3.7-flash go to gemini-3.8-flash . From December 1, 2026, the Gemini API routes gemini-2.5-pro to gemini-3.8-flash and gemini-2.5-flash to gemini-3.5-flash-lite . Every target rejects a request that ends on a model turn. Does adding an empty user turn fix it? No. Google checks the last non-empty turn, and empty turns are dropped or fail validation. The final user turn has to contain text or function responses. How do I force JSON output on Gemini without prefill? Use structured output. Set response mime type to application/json and pass a JSON schema in response json schema . The API enforces the schema, which a prefilled { never did. For format rules that a schema can't express, use system instruction . Does Claude support prefill? Not from Claude 4.6 on. Claude 4.6 and later models return a 400 invalid request error saying "This model does not support assistant message prefill. The conversation must end with a user message." Claude 4.5 and earlier models still accept it. Keep reading - + Gemini model deprecation: dates, replacements and a migration checklist https://www.evalshift.dev/blog/gemini-model-deprecation-migration-checklist — every Gemini retirement and reroute date, and the other request changes for Gemini 3.8 Flash. - + LLM drift https://www.evalshift.dev/blog/llm-drift — how a model can change under a model ID you never edited, the reroutes above included. - + What actually breaks when you switch LLMs https://www.evalshift.dev/blog/what-breaks-when-you-switch-llms — the regressions that don't fail as loudly as a 400. - + How to catch LLM regressions before a model upgrade ships https://www.evalshift.dev/blog/llm-regression-testing-model-upgrade — replaying real traffic on the old and new model, step by step.