anomalyco / anomalyco/opencode
gemini-3.8-flash: 400 'Requests ending with a model turn are not supported' after a model turn
@kitlangton is already working on this.
Since Sep 3, 2026.
- Dominant language
- TypeScript
- Stars
- 209k
- Forks
- 27.5k
- Avg merge
- 7h 2m
- Merged PRs (30d)
- 384
Description
Description
Using Google Gemini 3.8 Flash via the Gemini API (https://aiplatform.googleapis.com/v1beta1/.../models/gemini-3.8-flash:streamGenerateContent?alt=sse), the request fails with 400 INVALID_ARGUMENT:
Requests ending with a model turn are not supported.
isRetryable: false, so the session hard-fails (a session.error event is emitted, session ses_f99077bd3ffekifM3UhsAgnIpk, project 2acd036c175137252d8b8a07a3ea82d0fe0658a3) and the only way to continue is to type a new prompt.
The cause is the projected conversation history being sent with the last contents entry as a model (assistant) turn. Gemini rejects any request whose contents ends with a model role. This surfaces after the model finishes answering / thinking, and the history is reloaded with an assistant-only tail — e.g. on the next prompt, after an interrupted stream, or via a continue/auto-continue path.
Same root cause as the already-open #45359 (reproduced on gemini-3.7-flash); it also reproduces on gemini-3.8-flash.
Plugins
Unknown / not provided in the error payload.
OpenCode version
Unknown from the error payload (please confirm).
Steps to reproduce
- Configure the Google/Gemini provider and select
gemini-3.8-flash. - Run a normal session and let the model finish its answer (complete a model turn).
- On the next prompt, the stream returns 400
Requests ending with a model turn are not supported. - Only typing a fresh prompt lets the conversation continue.
Screenshot and/or share link
No response — see the error payload below.
Operating System
Unknown from the error payload.
Terminal
Unknown from the error payload.
Error payload
{
"directory": "/workspace/xxx",
"project": "2acd036c175137252d8b8a07a3ea82d0fe0658a3",
"payload": {
"id": "evt_067152aee001TL0iqoRHGvPa9n",
"type": "session.error",
"properties": {
"sessionID": "ses_f99077bd3ffekifM3UhsAgnIpk",
"error": {
"name": "APIError",
"data": {
"message": "Requests ending with a model turn are not supported.",
"statusCode": 400,
"isRetryable": false,
"responseHeaders": {
"alt-svc": "h3=\":443\"; ma=2592000,h3-29=\":443\"; ma=2592000",
"content-length": "142",
"content-type": "text/event-stream",
"date": "Thu, 03 Sep 2026 11:43:55 GMT",
"server": "scaffolding on HTTPServer2",
"vary": "Origin, X-Origin, Referer",
"x-content-type-options": "nosniff",
"x-frame-options": "SAMEORIGIN",
"x-xss-protection": "0"
},
"responseBody": "{\n \"error\": {\n \"code\": 400,\n \"message\": \"Requests ending with a model turn are not supported.\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n",
"metadata": {
"url": "https://aiplatform.googleapis.com/v1beta1/projects/XXXX/locations/global/publishers/google/models/gemini-3.8-flash:streamGenerateContent?alt=sse"
}
}
}
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.