Skip to content

gemini-3.8-flash: 400 'Requests ending with a model turn are not supported' after a model turn #47034

Closed

Description

@shuqingzai

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

  1. Configure the Google/Gemini provider and select gemini-3.8-flash.
  2. Run a normal session and let the model finish its answer (complete a model turn).
  3. On the next prompt, the stream returns 400 Requests ending with a model turn are not supported.
  4. 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"
          }
        }
      }
    }
  }
}

Activity

  1. github-actions commented on Sep 3, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Since you've already identified #45359 as the same root cause, this issue may be tracked there. A maintainer will review whether this should be merged into that issue or tracked separately (e.g., to cover gemini-3.8-flash specifically).

  2. rekram1-node commented on Sep 3, 2026

    @rekram1-node
    Collaborator

    can u export session? opencode export > session.json

  3. gabriel-macherini commented on Sep 3, 2026

    @gabriel-macherini

    same problem. looks like the model try to think and fails on that. Or maybe is related with high demand right now.

  4. esafak commented on Sep 4, 2026

    @esafak
    Contributor

    is the session file safe to share here or should I pm you in DIscord?

  5. gabriel-macherini commented on Sep 9, 2026

    @gabriel-macherini

    I got a free tier from from my bank. This account is named Google AI Plus (400 GB). This gives you the right to generate an API key, but this key is restrict request for 5 per minute. So the thing works until you ask for something that need several request tools and breaks. This is not true when you are using the antigravity app. there you can make as many calls you want, but the quota still very low. So i just want to give some head ups about this because I did some digging. Maybe worth let some others opencode users know about this. Anyway, I love opencode, keep updating it!

  6. rekram1-node commented on Sep 29, 2026

    @rekram1-node
    Collaborator
  7. shuqingzai commented on Sep 29, 2026

    @shuqingzai
    Author

    fixed on opencode v2: https://opencode.ai/v2/docsOpenCode v2 已修复: https://opencode.ai/v2/docs

    Hi @rekram1-node

    Will v1 be updated simultaneously, or is it just v2? The v2 ecosystem isn't mature yet, and many users haven't switched over to it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions