cd /news/large-language-models/gemini-requests-ending-with-a-model-… · home › topics › large-language-models › article
[ARTICLE · art-171159] src=evalshift.dev ↗ pub= topic=large-language-models verified=true sentiment=· neutral

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.

by read12 min views3 publishedNov 17, 2026
Gemini "Requests ending with a model turn are not supported": the cause and the fix
Image: Evalshift (auto-discovered)

← all posts

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 lastnon-empty turn.
  • +Replace prefill with system_instruction or structured output. If you prefilled{ to force JSON orTranslation: 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 eachfunctionCall the model made, including a cancelled one, in auser turn with the call'sid andname .

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 ↗ 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 ↗ 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 andgemini-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 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 trailingmodel 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 atMAX_TOKENS , some code appends the partial answer as amodel turn and calls again so the model continues from it. That is a prefill too.
  3. +An empty last user turn. Google checks the lastnon-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 themodel 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'sfunctionCall 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 thatmodel 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 amodel 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:

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:

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:

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 ↗ 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:

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, /docs/captures, /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 #

── more in #large-language-models 4 stories · sorted by recency
── more on @google 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/gemini-requests-endi…] indexed:0 read:12min 2026-11-17 · —