Skip to content

"Provider returned error" with openrouter/openai/gpt-5.1-codex #4608

Closed

Description

@jdanbrown

Description

Image

Here's the error from above with --print-logs:

Here's a formatted version of the big error={...} json blob from --print-logs:

Here's my config:

$ opencode debug config
{
  "$schema": "https://opencode.ai/config.json",
  "theme": "jdanbrown",
  "keybinds": {
    "leader": "ctrl+o",
    "app_exit": "ctrl+d,<leader>q",
    "editor_open": "<leader>e",
    "theme_list": "<leader>t",
    "sidebar_toggle": "<leader>b",
    "status_view": "<leader>s",
    "session_export": "<leader>x",
    "session_new": "<leader>n",
    "session_list": "<leader>l",
    "session_timeline": "<leader>g",
    "session_share": "none",
    "session_unshare": "none",
    "session_interrupt": "ctrl+c",
    "session_compact": "<leader>c",
    "messages_page_up": "pageup",
    "messages_page_down": "pagedown",
    "messages_half_page_up": "ctrl+alt+u",
    "messages_half_page_down": "ctrl+alt+d",
    "messages_first": "ctrl+alt+a",
    "messages_last": "ctrl+alt+e",
    "messages_copy": "<leader>y",
    "messages_undo": "<leader>u",
    "messages_redo": "<leader>r",
    "messages_toggle_conceal": "<leader>h",
    "model_list": "<leader>m,ctrl+j",
    "model_cycle_recent": "f2",
    "model_cycle_recent_reverse": "shift+f2",
    "command_list": "ctrl+_",
    "agent_list": "<leader>a",
    "agent_cycle": "tab",
    "agent_cycle_reverse": "shift+tab",
    "input_clear": "ctrl+c",
    "input_forward_delete": "ctrl+d",
    "input_paste": "ctrl+v",
    "input_submit": "return",
    "input_newline": "shift+enter,alt+enter",
    "history_previous": "up,ctrl+p",
    "history_next": "down,ctrl+n",
    "session_child_cycle": "<leader>right",
    "session_child_cycle_reverse": "<leader>left"
  },
  "tui": {
    "scroll_speed": 2
  },
  "share": "manual",
  "autoupdate": false,
  "model": "openrouter/anthropic/claude-haiku-4.5",
  "small_model": "openrouter/google/gemini-2.5-flash",
  "provider": {
    "openrouter": {
      "models": {
        "anthropic/claude-sonnet-4.5@thinking-32k": {
          "id": "anthropic/claude-sonnet-4.5",
          "options": {
            "reasoning": {
              "effort": "high"
            }
          }
        }
      }
    }
  },
  "mcp": {
    "context7": {
      "type": "remote",
      "url": "https://mcp.context7.com/mcp",
      "headers": {
        "CONTEXT7_API_KEY": ...
      }
    }
  },
  "formatter": {
    "swiftformat": {
      "command": [
        "swiftformat",
        "$FILE"
      ],
      "extensions": [
        ".swift"
      ]
    }
  },
  "instructions": [],
  "permission": {
    "bash": {
      "*": "ask",
      "git status": "allow",
      "git diff": "allow",
      "git log": "allow"
    }
  },
  "agent": {},
  "mode": {},
  "plugin": [],
  "command": {},
  "username": "danb"
}

OpenCode version

1.0.85

Steps to reproduce

(above)

Screenshot and/or share link

No response

Operating System

macOS 15.5

Terminal

VS Code terminal

Activity

  1. added
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 21, 2025
  2. jdanbrown commented on Nov 21, 2025

    @jdanbrown
    ContributorAuthor

    Same error if I comment out the "mcp": { ... } block in my config.

  3. jdanbrown commented on Nov 21, 2025

    @jdanbrown
    ContributorAuthor

    Same error with empty config, too.

  4. jdanbrown commented on Nov 21, 2025

    @jdanbrown
    ContributorAuthor

    Same error with openrouter/openai/gpt-5.1-codex-mini.

  5. jdanbrown commented on Nov 21, 2025

    @jdanbrown
    ContributorAuthor

    Does not error with openai/gpt-5.1-codex (i.e. without openrouter).

  6. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    Hmmm

  7. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    I have a fix for this, that's really weird tho I think the openrouter ai sdk has a bug maybe

  8. self-assigned this
    on Nov 21, 2025
  9. removed
    opentuiThis relates to changes in v1.0, now that opencode uses opentui
    on Nov 21, 2025
  10. jdanbrown commented on Nov 21, 2025

    @jdanbrown
    ContributorAuthor
  11. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    yeah it's related to their ai sdk doing something

  12. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    or we are doing something wrong w it

  13. rekram1-node commented on Nov 21, 2025

    @rekram1-node
    Contributor

    Talked w/ openrouter they are fixing it

  14. jhkim2goqual commented on Nov 23, 2025

    @jhkim2goqual

    I’ve been running into the same issue when using OpenCode with OpenRouter + OpenAI models (e.g. openrouter/openai/gpt-5.1-codex).

    After digging into the logs and request payload, I confirmed that the root cause is:

    • OpenCode re-sends prior "assistant" messages including the reasoning / reasoning_details metadata

    • When OpenRouter forwards that to OpenAI, the encrypted reasoning blocks (providerMetadata with reasoning.encrypted items like rs_...) no longer match the OpenAI project/key OpenRouter is using

    • OpenAI then rejects the request with:

      The encrypted content for item rs_0aa9cdb85cd23c86016920cad04e4c8196bf0bdb7dbce6a4df could not be verified.
      type: invalid_request_error

    To work around this, I patched my local OpenCode clone to strip reasoning provider metadata only when using the OpenRouter provider.

    Concretely, I added an option to MessageV2.toModelMessage(...):

    export function toModelMessage(
      input: { info: Info; parts: Part[] }[],
      options?: {
        // When true, strips reasoning providerMetadata to avoid OpenAI encrypted content verification errors via OpenRouter
        stripReasoningMetadata?: boolean
      },
    ): ModelMessage[] { ... }

    and when model.npm === "@openrouter/ai-sdk-provider", I call it with stripReasoningMetadata: true.

    Inside toModelMessage, for assistant messages I now do (simplified):

    if (part.type === "text")
      assistantMessage.parts.push({
        type: "text",
        text: part.text,
        providerMetadata: options?.stripReasoningMetadata ? undefined : part.metadata,
      })
    
    if (part.type === "tool") {
      ...
      callProviderMetadata: options?.stripReasoningMetadata ? undefined : part.metadata,
    }
    
    if (part.type === "reasoning") {
      assistantMessage.parts.push({
        type: "reasoning",
        text: part.text,
        // Skip providerMetadata when stripReasoningMetadata is true to avoid
        // OpenAI encrypted content verification errors when using OpenRouter
        providerMetadata: options?.stripReasoningMetadata ? undefined : part.metadata,
      })
    }

    So the encrypted reasoning blocks are no longer forwarded when going through OpenRouter, but everything else (including the reasoning text itself) is preserved. Other providers (direct OpenAI, Anthropic, etc.) keep the original behavior.

    With this patch in place, I can now use openrouter/openai/gpt-5.1-codex in OpenCode without hitting the “Provider returned error / encrypted content could not be verified” issue.

    If it’s helpful, I’m happy to turn this into a PR — or feel free to adapt this approach in whatever way best fits the existing provider abstractions.

  15. rekram1-node commented on Nov 24, 2025

    @rekram1-node
    Contributor

    if you update to latest this should be fixed, may need to clear your cache too, try: opencode models --refresh

  16. jdanbrown commented on Nov 25, 2025

    @jdanbrown
    ContributorAuthor

    👍 Thanks! I got through one non-trivial prompt without issues with openrouter/openai/gpt-5.1-codex. I'll bang on it more tomorrow.

  17. JohnBakhmat commented on Dec 17, 2025

    @JohnBakhmat

    for people in sanctioned regions (Russia, Iran, etc. i don't know them all) try running it through proxy. i thought issue persisted but it was in fact a region restriction

  18. NathanRHD commented on Jan 10, 2026

    @NathanRHD

    I appear to be having the same from my vultr vps but non gpt models from the same openrouter seem to be working?

  19. rekram1-node commented on Jan 16, 2026

    @rekram1-node
    Contributor

    This should be fixed in the next release (1.1.24) by commit: 40836e9

  20. jdanbrown commented on Jan 16, 2026

    @jdanbrown
    ContributorAuthor

    Yep, appears to now be fixed in 1.1.25:

    Image
  21. jdanbrown commented on Jan 16, 2026

    @jdanbrown
    ContributorAuthor

    Did you also fix this other issue in the process? I just confirmed that my repro from the top of it is now working for me in 1.1.25:

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions