OpenCode 接入 DeepSeek V4

想试试 DeepSeek V4,随手扔给 GPT-5.4 让它帮我配 OpenCode。折腾了 20 分钟,踩了两个坑,最终稳了。记录一下。 第一步:选对入口 DeepSeek 现在有两个模型: deepseek-v4-pro — 主力 deepseek-v4-flash — 快速便宜 端点我用的是...
OpenCode 接入 DeepSeek V4
OpenCode 接入 DeepSeek V4

想试试 DeepSeek V4,随手扔给 GPT-5.4 让它帮我配 OpenCode。折腾了 20 分钟,踩了两个坑,最终稳了。记录一下。

第一步:选对入口

DeepSeek 现在有两个模型:

  • deepseek-v4-pro — 主力
  • deepseek-v4-flash — 快速便宜

端点我用的是 https://api.deepseek.com/beta,实测比 /v1 顺,没遇到奇怪的兼容问题。

第二步:配 provider

OpenCode 里不要复用现有的 openai 或 anthropic provider,直接新建一个:

"aic":{
  "npm":"@ai-sdk/openai-compatible",
  "name":"兼容奥",
  "options":{"baseURL":"https://api.deepseek.com/beta","apiKey":"sk-xxx","includeUsage":true},
  "models":{
    "deepseek-v4-pro":{
      "name":"DeepSeek V4 Pro",
      "attachment":true,"reasoning":true,
      "interleaved":{"field":"reasoning_content"},
      "modalities":{"input":["text","image","pdf"],"output":["text"]},
      "limit":{"context":1000000,"output":384000},
      "options":{"extra_body":{"thinking":{"type":"disabled"}}},
      "variants":{
        "high":{"reasoning_effort":"high","extra_body":{"thinking":{"type":"enabled"}}},
        "xhigh":{"reasoning_effort":"max","extra_body":{"thinking":{"type":"enabled"}}}
      },
      "cost":{"input":0.44,"output":0.88,"cache_read":0.0037}
    },
    "deepseek-v4-flash":{
      "name":"DeepSeek V4 Flash",
      "attachment":true,"reasoning":true,
      "interleaved":{"field":"reasoning_content"},
      "modalities":{"input":["text","image","pdf"],"output":["text"]},
      "limit":{"context":1000000,"output":384000},
      "options":{"extra_body":{"thinking":{"type":"disabled"}}},
      "variants":{
        "high":{"reasoning_effort":"high","extra_body":{"thinking":{"type":"enabled"}}}
      },
      "cost":{"input":0.147,"output":0.293,"cache_read":0.0029}
    }
  }
}

踩坑记录

坑一:选错 npm 包

一开始想挂到 aio@ai-sdk/openai)下面。原因是 OpenCode 的 openai provider 走的是 /v1/responses,DeepSeek 只支持 /v1/chat/completions。GPT-5.4 直接告诉我换 @ai-sdk/openai-compatible,立竿见影。

坑二:思考模式下报 400

配好之后一切到 high variant 就报这个:

"The reasoning_content in the thinking mode must be passed back to the API."

DeepSeek 思考模式要求每轮请求必须把上一轮的思维链带回去。OpenCode 默认不干这事。

解法是模型配置里加一行:

"interleaved":{"field":"reasoning_content"}

加了之后多轮对话、工具调用都正常了。这个字段在 OC 文档里没怎么提,是翻 GitHub issue #6040 翻出来的。

一些选择

  • 默认关思考:日常够用,省 token。需要深度推理时切 variant
  • variant 命名high / xhigh,和 OC 其他模型统一
  • flash 不给 xhigh:定位是快速模型,开满思考没意义
  • 成本按美元写:DeepSeek 定价是人民币,按 6.82 换算的,差不多就行

8 个帖子 - 8 位参与者

阅读完整话题

来源: linux.do查看原文