Skip to content

Invalid argument for parameter maxOutputTokens: maxOutputTokens must be >= 1 #21522

Closed

Description

@Hoshino-Yumetsuki

Description

The expected behavior is that the request should succeed even without the limit parameter:

"limit": {
"context": 200000,
"output": 32000
}

This functionality worked correctly in all versions prior to 1.4.0.

Plugins

oh-my-opencode

OpenCode version

1.4.0

Steps to reproduce

No response

Screenshot and/or share link

Image

Operating System

Windows 11

Terminal

Windows Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 8, 2026
  2. github-actions commented on Apr 8, 2026

    @github-actions
    Contributor

    This issue doesn't fully meet our contributing guidelines.

    What needs to be fixed:

    • The Description field contains only - and has no actual content explaining the bug or what behavior is observed
    • Steps to reproduce is empty (_No response_) — please describe what you were doing when the error occurred (e.g., which model/provider you are using, what action triggered it)

    Please edit this issue to address the above within 2 hours, or it will be automatically closed.


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

    If you believe this was flagged incorrectly, please let a maintainer know.

  3. added
    needs:complianceThis means the issue will auto-close after 2 hours.
    and removed
    needs:complianceThis means the issue will auto-close after 2 hours.
    on Apr 8, 2026
  4. github-actions commented on Apr 8, 2026

    @github-actions
    Contributor

    Thanks for updating the issue! It now has the information needed to investigate. We appreciate the screenshot and the context about this being a regression in 1.4.0.

  5. darsh12 commented on Apr 8, 2026

    @darsh12

    Just a DP. After I removed oh-my-opencode, opencode started working

  6. Hoshino-Yumetsuki commented on Apr 8, 2026

    @Hoshino-Yumetsuki
    Author

    Just a DP. After I removed oh-my-opencode, opencode started working

    thank for your suggestion, i will open a issue in omo`s repository

  7. Jedeiah commented on Apr 9, 2026

    @Jedeiah

    Just a DP. After I removed oh-my-opencode, opencode started working只是个 DP。在我移除了“哦,我的 opencode”后,opencode 开始正常工作了

    thank for your suggestion, i will open a issue in omo`s repository谢谢你的建议,我会在 OMO 的仓库里开一个问题

    哥,找到问题了吗? 我今天也遇到了,同时在code-yeongyu/oh-my-openagent 仓库里没看到你提的issue。

  8. Hoshino-Yumetsuki commented on Apr 9, 2026

    @Hoshino-Yumetsuki
    Author

    Just a DP. After I removed oh-my-opencode, opencode started working只是个 DP。在我移除了“哦,我的 opencode”后,opencode 开始正常工作了

    thank for your suggestion, i will open a issue in omo`s repository谢谢你的建议,我会在 OMO 的仓库里开一个问题

    哥,找到问题了吗? 我今天也遇到了,同时在code-yeongyu/oh-my-openagent 仓库里没看到你提的issue。

    我是更新就行了,我已经把issue关了

  9. Yiaichen commented on Apr 10, 2026

    @Yiaichen

    Just a DP. After I removed oh-my-opencode, opencode started working只是个 DP。在我移除了“哦,我的 opencode”后,opencode 开始正常工作了

    thank for your suggestion, i will open a issue in omo`s repository谢谢你的建议,我会在 OMO 的仓库里开一个问题

    哥,找到问题了吗? 我今天也遇到了,同时在code-yeongyu/oh-my-openagent 仓库里没看到你提的issue。

    我是更新就行了,我已经把issue关了

    我更新到最新版本一样有这个问题

    Image
  10. Jedeiah commented on Apr 11, 2026

    @Jedeiah

    @Yiaichen 回复你的评论:

    根本原因是 oh-my-openagent 读取到某些模型的能力缓存 limit.output = 0,
    没有做防御性校验,直接把 0 透传成 maxOutputTokens=0 发给 OpenCode,
    OpenCode 1.4.0+ 要求 maxOutputTokens >= 1 所以报错。


    以下是合理的临时方案(可丢给Ai让它去解决):

    方案 A(限自定义模型,且要覆盖所有 agent 用到的模型才有效):

    如果你用的是自定义 provider 里声明的模型,可以在 opencode.json 的对应模型
    条目下加 limit.output,让 oh-my-openagent 读到正确值而不是缓存里的 0:

    {
      "provider": {
        "your-provider": {
          "models": {
            "your-model-id": {
              "limit": {
                "output": 4096,
                "context": 128000
              }
            }
          }
        }
      }
    }

    注意:oh-my-openagent 会启动多个 agent,每个 agent 用不同模型。
    必须给所有涉及的模型都加上 limit.output,漏一个就还会触发。
    对 opencode 内置识别的标准模型(如 anthropic/claude-sonnet)无效。


    方案 B(治本,推荐):

    直接给 oh-my-openagent 的 dist/index.js 打补丁,
    在写入和透传 maxOutputTokens 的三个关键路径上过滤掉 <= 0 的值。

    文件路径(以 macOS 为例,Windows 路径类似):
    ~/.cache/opencode/packages/oh-my-openagent@latest/node_modules/oh-my-openagent/dist/index.js

    改动 1 - applySessionPromptParams 写入时(搜 model.maxTokens !== undefined):

    改前:
    ...model.maxTokens !== undefined ? { maxOutputTokens: model.maxTokens } : {}

    改后:
    ...typeof model.maxTokens === "number" && model.maxTokens > 0 ? { maxOutputTokens: model.maxTokens } : {}

    改动 2 - 读取会话参数发请求时(搜 storedPromptParams.maxOutputTokens !== undefined):

    改前:

    if (storedPromptParams.maxOutputTokens !== undefined) {
      output.maxOutputTokens = storedPromptParams.maxOutputTokens;
    }

    改后:

    if (typeof storedPromptParams.maxOutputTokens === "number" && storedPromptParams.maxOutputTokens > 0) {
      output.maxOutputTokens = storedPromptParams.maxOutputTokens;
    }

    改动 3 - compatibility 结果写回时(搜 compatibility.maxTokens !== undefined):

    改前:

    if (compatibility.maxTokens !== undefined) {
      output.maxOutputTokens = compatibility.maxTokens;
    } else {
      delete output.maxOutputTokens;
    }

    改后:

    if (typeof compatibility.maxTokens === "number" && compatibility.maxTokens > 0) {
      output.maxOutputTokens = compatibility.maxTokens;
    } else {
      delete output.maxOutputTokens;
    }

    改完后删除模型能力缓存再重启:
    rm ~/.cache/oh-my-opencode/model-capabilities.json # macOS/Linux
    Windows: 删除 %USERPROFILE%\.cache\oh-my-opencode\model-capabilities.json

    ⚠️ 注意:插件更新后补丁可能会被覆盖,需要重新打一遍。

  11. takam-alex-christian commented on Apr 22, 2026

    @takam-alex-christian

    This issues was caused by the oh-my-opencode plugin. Adding the following to each model in ~!/.config/opencode.jsonc resolved the issue for me.

    "limit": { "output": 4096, "context": 128000 }

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 workingcoreAnything pertaining to core functionality of the application (opencode server stuff)windows

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions