Skip to content

[FEATURE]: compatibility flag to suppress reasoning replay on assistant messages #62595

Open

Description

@RigaOnTheRocks

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Custom openai-compatible providers pointed at api.mistral.ai fail from the second assistant turn onward. Mistral rejects any reasoning field on replayed assistant messages, and @ai-sdk/openai-compatible always echoes one back.

HTTP 422
{"detail":[{"type":"extra_forbidden","loc":["body","messages",2,"assistant","reasoning_content"],"msg":"Extra inputs are not permitted","input":""}]}

Turn 1 succeeds. Turn 2 fails, because turn 1's assistant message now carries reasoning_content.

Repro

{
  "provider": {
    "mistral-custom": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Mistral (custom)",
      "options": { "baseURL": "https://api.mistral.ai/v1" },
      "models": { "deepseek-v4-1-flash-1017": { "name": "DeepSeek V4.1 Flash" } }
    }
  }
}
S="ses_repro$(date +%s)"
opencode run --session "$S" --model mistral-custom/deepseek-v4-1-flash-1017 "Reply: TURN1"  # ok
opencode run --session "$S" --model mistral-custom/deepseek-v4-1-flash-1017 "Reply: TURN2"  # 422

Why the existing knobs don't cover it

compatibility.reasoningField only selects the field name (reasoning | reasoning_content | reasoning_text | string). There is no way to say "don't send reasoning at all". Renaming doesn't help either — Mistral rejects unknown fields with extra_forbidden, so reasoning fails the same way as reasoning_content.

compatibility.requireReasoning: false doesn't help: it governs whether reasoning is required, not whether it is sent.

Proposal

Add compatibility.sendReasoning: boolean, default true. When false, omit reasoning from replayed assistant messages entirely.

This matters beyond Mistral: any strict OpenAI-compatible gateway fronting reasoning models has the same problem, and those users can't fall back to the built-in mistral provider because their endpoint isn't Mistral.

Workaround today: use the built-in mistral provider (@ai-sdk/mistral), which never sends the field. Only applies when the endpoint is actually api.mistral.ai.

Environment: opencode v2.2.6, macOS 26.7.1, iTerm2

Activity

  1. opencodejr commented on Nov 7, 2026

    @opencodejr
    Contributor

    Thanks for the clear write-up and the repro!

    In short, you're asking for a compatibility option (e.g. compatibility.sendReasoning: false) so OpenCode stops sending any reasoning field on earlier assistant messages. That would make strict OpenAI-compatible endpoints like api.mistral.ai work with reasoning models. The maintainers will consider it.

    A note on why you get the empty field: OpenCode switches requireReasoning on by default for any model whose ID contains deepseek. So deepseek-v4-1-flash-1017 gets an empty reasoning_content: "" even when the endpoint is Mistral, which matches the "input": "" in your 422. Setting "requireReasoning": false in the model's compatibility should drop the empty field. But when the model does return reasoning text, it is always sent back, and no setting turns that off yet.

    Until then, you can work around it with a small local plugin that removes reasoning fields from earlier assistant messages before the request goes out. Save this as .opencode/plugins/strip-reasoning.ts in your project (or in the plugins/ folder of your global OpenCode config directory). Change providerID to your provider's ID if it isn't mistral-custom:

    import { Plugin } from "@opencode/plugin"
    
    const FIELDS = ["reasoning_content", "reasoning", "reasoning_text", "reasoning_details"]
    
    export default Plugin.define({
      id: "strip-reasoning-replay",
      setup: async (ctx) => {
        await ctx.session.hook(
          "http.request",
          async (event) => {
            if (event.request.method !== "POST") return
            const body = await event.request.clone().json().catch(() => undefined)
            if (!body || !Array.isArray(body.messages)) return
            let changed = false
            for (const message of body.messages) {
              if (message?.role !== "assistant") continue
              for (const field of FIELDS) {
                if (field in message) {
                  delete message[field]
                  changed = true
                }
              }
            }
            if (!changed) return
            const headers = new Headers(event.request.headers)
            headers.delete("content-length")
            event.request = new Request(event.request, { headers, body: JSON.stringify(body) })
          },
          { providerID: "mistral-custom" },
        )
      },
    })

    This code type-checks against the v2 plugin API, but I haven't run it against Mistral, so please let us know if it doesn't fix the 422.

    Related issues:

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

Metadata

Metadata

Assignees

No one assigned

    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