2026-11-19-DSH接入腾讯混元TokenHub-hy4-flash.md

DSH 接入腾讯混元 4 Flash(TokenHub 混元模型服务)— 2026-11-19

结果

DSH 模型选择器里多了一个 provider:腾讯混元 (TokenHub),下面挂着两个模型:

热加载生效,没重启 DSH。

(上下文与输出上限取自网关 /models 的 context_length / max_output_tokens,均已实测验证视觉能力)

改了哪两个文件

文件改动
~/.dsh/.credentials.yamlrefs 增加 HUNYUAN_TOKENHUB_API_KEY
~/.dsh/profiles/web/cordis.patch.ymlllm-pi-ai.config.providers 增加 hunyuan 块

备份:cordis.patch.yml.bak-before-hunyuan-20261119-163420、.credentials.yaml.bak-before-hunyuan-20261119-163420。

配置要点(和讯飞那套同构,thinkingFormat: deepseek):

      hunyuan:
        displayName: 腾讯混元 (TokenHub)
        api: openai-completions
        baseURL: https://tokenhub.tencentmaas.com/v1
        apiKeyEnv: HUNYUAN_TOKENHUB_API_KEY
        streamIdleTimeoutMs: 600000
        reasoning: high
        models:
          - id: hy4-flash
            name: Hunyuan-4 Flash (1M)
            contextWindow: 1024000
            maxTokens: 64000
            input: [text, image]
            reasoningEfforts: {off: none, low: low, high: high, max: max}
          - id: deepseek/deepseek-flash
            name: DeepSeek-V4.1-Flash-1017 (TokenHub)
            contextWindow: 1024000
            maxTokens: 384000
            input: [text, image]
            reasoningEfforts: {off: none, low: low, high: high, max: max}
        compat:
          thinkingFormat: deepseek
          maxTokensField: max_tokens      # ← 关键:deepseek/deepseek-flash 不认 max_completion_tokens
          supportsReasoningEffort: true
          supportsDeveloperRole: false
          requiresReasoningContentOnAssistantMessages: true

实测记录(2026-11-19)

基础能力

项目结果
/v1/models200,返回 160+ 个模型(这是聚合网关,不只混元)
普通对话返回 content + reasoning_content(默认就思考)
thinking:{type:"disabled"}生效,reasoning_content 为 null
reasoning_effortnone / low / medium / high / max 五档全接受(各档 reasoning_tokens 有差异)
enable_thinking:false无效(被忽略,照样思考)→ 关思考只能靠 thinking.type
max_completion_tokens真生效:给 5 就 finish_reason=length、usage.completion_tokens=5
max_tokens也接受(200000 不报错),但按官方口径用 max_completion_tokens
tool_calls(流式)正常,首 chunk 带 name+id,finish_reason=tool_calls
视觉可用。64×64 纯色块测试图(左半红、右半蓝)答「红色 蓝色」
developer role接受(内部当 system 处理),配置里仍按 false 走 system 最稳
assistant 历史回传 reasoning_content接受,不报错

走 DSH 自己的适配层(pi-ai openai-completions)验证

实际发出的请求体:

坑:pi-ai 的 ImageContent 是 {type:"image", data, mimeType},写成 {type:"image", image:...} 会构造出空 image_url,网关回 400 invalid_request_error。

⚠️ 两个模型的 token 上限字段不一样(本轮最重要的坑)

模型max_tokensmax_completion_tokens
hy4-flash✅ 生效(给 5 → finish=length、usage=5)✅ 生效
deepseek/deepseek-flash✅ 生效❌ 被完全忽略(给 5 照样输出 303 字、usage=210)

所以 provider 级 maxTokensField 从 max_completion_tokens 改成了 max_tokens —— hy4-flash 两个字段都认,改成 max_tokens 之后两个模型都正确。若不改,deepseek/deepseek-flash 在 DSH 里设的输出上限会完全失效。

上限实测:max_tokens=384000 可过,500000 报 400001 被内部 MaaS 组件拒绝。

DeepSeek-V4.1-Flash-1017(deepseek/deepseek-flash)实测

项目结果
基础对话✅ 带 reasoning_content(默认思考)
thinking:{type:"disabled"}✅ 生效,reasoning_content 为 null
reasoning_effortnone/low/medium/high/max/xhigh/minimal 全接受
视觉✅ 左红右蓝图答「红色,蓝色」
tool_calls(流式)✅ 首 chunk 带 name+id,finish_reason=tool_calls
走 pi-ai 适配层✅ 请求体为 max_tokens + thinking:{type},关思考/高思考/带图三种都验过

deepseek/deepseek-flash 已改成「官方 DeepSeek 档」(2026-11-19)

按 pi-ai 内置 provider data 里 官方 deepseek.json(api.deepseek.com 的 deepseek-flash 条目) 对齐:

        modelOverrides:
          deepseek/deepseek-flash:
            compat:
              supportsStore: false
              supportsDeveloperRole: false
              supportsReasoningEffort: true
              maxTokensField: max_tokens
              requiresReasoningContentOnAssistantMessages: true
              thinkingFormat: deepseek
              supportsStrictMode: true

逐项说明:

官方档项本网关实测说明
thinkingFormat: deepseek✅thinking:{type} 开关有效
maxTokensField: max_tokens✅ 且必须它不认 max_completion_tokens(给 5 照样出 303 字)
supportsStore: false✅实测请求体里确实不再带 store 字段(hy4-flash 仍带 store:false,两种都正常)
supportsDeveloperRole: false✅走 system
requiresReasoningContentOnAssistantMessages: true✅回传 reasoning_content 被接受
supportsStrictMode: true✅curl 直发 strict:true 的 function schema,正常返回 tool_calls
supportsReasoningEffort: true(官方靠 URL auto-detect,这里必须显式)✅不用 api.deepseek.com 域名就检测不到,不显式打开就不会发 reasoning_effort

只覆盖这一个模型(用 modelOverrides),hy4-flash 仍走 provider 级 compat —— 它不需要 strict,也不必被 store 语义影响。 另有一个刻意保留的差异:contextWindow 用网关声明的 1 024 000(官方 api.deepseek.com 是 1 000 000),maxTokens 两边都是 384 000。

这个 key 还能用哪些模型

网关是腾讯的聚合平台,/models 列了 160+ 个(文本、视觉、图像生成、视频生成、3D、TTS、ASR、embedding 都有)。实测:

模型结果
hy4-flash(本次登记)✅
hy4(同系列非 flash)✅
deepseek-v4.1-flash✅
kimi-k3.1-pro✅
glm-5.3-flash❌ 400001 被内部 MaaS 组件拒绝(需单独开通)
minimax-m3.1-flash❌ 同上

要加别的模型,只需在 hunyuan 的 models: 下补一条(contextWindow / maxTokens 抄 /models 的 context_length / max_output_tokens)。

使用

GUI 刷新(Ctrl+F5)→ 模型选择器出现「腾讯混元 (TokenHub) / Hunyuan-4 Flash (1M)」。 思考档:off 不思考(快),high 思考,max 最高。

回滚

cp -a ~/.dsh/profiles/web/cordis.patch.yml.bak-before-hunyuan-20261119-163420 \
      ~/.dsh/profiles/web/cordis.patch.yml
# 再从 ~/.dsh/.credentials.yaml 删掉 HUNYUAN_TOKENHUB_API_KEY 一行
下载此文件