GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Using reasoning models with OpenRouter provider yields "provider error" due rewritten reasoning blocks. · Issue #14716 · anomalyco/opencode

Using reasoning models with OpenRouter provider yields "provider error" due rewritten reasoning blocks. #14716

New issue
Copy link
New issue
Copy link
Closed
Closed
Using reasoning models with OpenRouter provider yields "provider error" due rewritten reasoning blocks.#14716
Copy link
Assignees
rekram1-node

Description

@simonhj
simonhj
opened on Feb 22, 2026
Issue body actions

Description

Recently opencode become neigh-on unusable with OpenRouter for me. Most sessions end in a provider error.

It essentially breaks openrouter as provider for me, so its likely something related to my setup, but I can't figure out what.

From the logs the underlying error (using the repro below) is

  {
    "type": "error",
    "error": {
      "type": "invalid_request_error",
      "message": "messages.1.content.6: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they
  were in the original response."
    },
    "request_id": "req_011CYKKYMLyQjjKY8MRfvLHk"
  }

Me and Codex did some digging and it seems that tool Parts have duplicated reasoning attached to them in the session.

The following diff solves the issue for me, but it feels a bit like treating the symptom. If its a good approach, lemme know I can turn it into a PR.

diff --git a/packages/opencode/src/session/message-v2.ts b/packages/opencode/src/session/message-v2.ts
index 178751a22..b5d41b8dd 100644
--- a/packages/opencode/src/session/message-v2.ts
+++ b/packages/opencode/src/session/message-v2.ts
@@ -488,6 +488,24 @@ export namespace MessageV2 {
   })
   export type WithParts = z.infer<typeof WithParts>

+  function metadata(input: Record<string, any> | undefined): Record<string, any> | undefined {
+    if (!input) return input
+
+    const prune = ["reasoning", "reasoning_content", "reasoning_details"]
+    const result: Record<string, any> = Object.fromEntries(
+      Object.entries(input)
+        .map(([provider, value]) => {
+          if (typeof value !== "object" || value === null || Array.isArray(value)) return [provider, value]
+          const next = Object.fromEntries(Object.entries(value).filter(([key]) => !prune.includes(key)))
+          if (Object.keys(next).length === 0) return undefined
+          return [provider, next]
+        })
+        .filter((entry): entry is [string, unknown] => !!entry),
+    )
+    if (Object.keys(result).length === 0) return undefined
+    return result
+  }
+
   export function toModelMessages(input: WithParts[], model: Provider.Model): ModelMessage[] {
     const result: UIMessage[] = []
     const toolNames = new Set<string>()
@@ -608,7 +626,7 @@ export namespace MessageV2 {
             assistantMessage.parts.push({
               type: "text",
               text: part.text,
-              ...(differentModel ? {} : { providerMetadata: part.metadata }),
+              ...(differentModel ? {} : { providerMetadata: metadata(part.metadata) }),
             })
           if (part.type === "step-start")
             assistantMessage.parts.push({
@@ -645,7 +663,7 @@ export namespace MessageV2 {
                 toolCallId: part.callID,
                 input: part.state.input,
                 output,
-                ...(differentModel ? {} : { callProviderMetadata: part.metadata }),
+                ...(differentModel ? {} : { callProviderMetadata: metadata(part.metadata) }),
               })
             }
             if (part.state.status === "error")
@@ -655,7 +673,7 @@ export namespace MessageV2 {
                 toolCallId: part.callID,
                 input: part.state.input,
                 errorText: part.state.error,
-                ...(differentModel ? {} : { callProviderMetadata: part.metadata }),
+                ...(differentModel ? {} : { callProviderMetadata: metadata(part.metadata) }),
               })
             // Handle pending/running tool calls to prevent dangling tool_use blocks
             // Anthropic/Claude APIs require every tool_use to have a corresponding tool_result
@@ -666,7 +684,7 @@ export namespace MessageV2 {
                 toolCallId: part.callID,
                 input: part.state.input,
                 errorText: "[Tool execution was interrupted]",
-                ...(differentModel ? {} : { callProviderMetadata: part.metadata }),
+                ...(differentModel ? {} : { callProviderMetadata: metadata(part.metadata) }),
               })
           }

Plugins

None

OpenCode version

1.2.10

Steps to reproduce

In a git clone of the opencode repo the following repros the bug for me:

opencode run -m "openrouter/anthropic/claude-opus-4.6" "Read-only investigation. Use at least 10 tool calls (glob, grep, read) across packages
/opencode/src/session and packages/opencode/src/provider. Find every place where reasoning or provider metadata might be rewritten, dropped, trimmed, or remapped. Return a compact table with file, function, and risk. Do not edit files." --thinking true --variant high

Screenshot and/or share link

No response

Operating System

WSL2 on windows 11

Terminal

Windows Terminal

Reacted by Sam Clark, Luke Fallon, Nigel Baillie and Weston-Ktech

Activity

  1. simonhj
    added
    bugSomething isn't working
    on Feb 22, 2026
  2. github-actions
    assigned
    thdxr
    on Feb 22, 2026
  3. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    windows
    on Feb 22, 2026
  4. github-actions commented on Feb 22, 2026

    @github-actions
    github-actionsBot
    on Feb 22, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • HuggingFace provider: reasoning_details not stripped from conversation history for Kimi-K2.5 #13002: Same root cause — reasoning/thinking metadata being passed back in conversation history causing API errors. That issue covers HuggingFace provider with reasoning_details, while this one affects OpenRouter with Anthropic thinking/redacted_thinking blocks. The proposed fix in this issue targets both.
  5. austinphilp commented on Feb 24, 2026

    @austinphilp
    austinphilp
    on Feb 24, 2026
    More actions

    Adding a repro from macOS (darwin) with OpenCode 1.2.10:

    Model/Provider: openrouter/anthropic/claude-opus-4.6
    Thinking: high
    Mode: interactive TUI (fresh session)

    Steps

    1. Start TUI with Claude Opus 4.6 + thinking high
    2. Run any skill (e.g. shortcut-api)
    3. Next turn fails with invalid_request_error

    Error
    messages.1.content.4: thinking or redacted_thinking blocks in the latest assistant message cannot be modified

    Notes

    • The same prompt works via opencode run ... (one-shot).
    • Disabling thinking makes the issue go away.

    Sanitized log excerpt

    ERROR service=llm providerID=openrouter modelID=anthropic/claude-opus-4.6 error={
      "error": {
        "name": "AI_APICallError",
        "statusCode": 400,
        "responseBody": "{\"error\":{\"message\":\"Provider returned error\",\"code\":400,\"metadata\":{\"raw\":\"{\\\"type\\\":\\\"error\\\",\\\"error\\\":{\\\"type\\\":\\\"invalid_request_error\\\",\\\"message\\\":\\\"messages.1.content.4: `thinking` or `redacted_thinking` blocks in the latest assistant message cannot be modified. These blocks must remain as they were in the original response.\\\"}\\\"}\"}}"
      }
    }
    

    I also parsed the request payload from the debug output: the previous assistant message is sent as a plain string (no thinking/redacted_thinking parts) even though the session export shows it included reasoning metadata. Looks like interactive history serialization is dropping the thinking block.

    Happy to provide more logs/session export if helpful.

  6. han-nah-dev commented on Feb 27, 2026

    @han-nah-dev
    han-nah-dev
    on Feb 27, 2026
    More actions

    Same issue here. Same cause as well.

  7. rekram1-node
    assigned
    rekram1-node
    and unassigned
    thdxr
    on Mar 11, 2026
  8. thdxr
    removed
    bugSomething isn't working
    windows
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  9. rekram1-node commented on May 22, 2026

    @rekram1-node
    rekram1-node
    on May 22, 2026
    Member
    More actions

    several openrouter bugs have been fixed, havent seen further reports of this

  10. rekram1-node
    closed this as completedon May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rekram1-node
    rekram1-node

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.