Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(provider): send reasoning_effort to official DeepSeek endpoints (#1849)

wojiecihuo8e8b99ee36bc
diff --git a/docs/adr/model-reasoning-effort-override.md b/docs/adr/model-reasoning-effort-override.md
index 865dfff10..cd8d6581e 100644
--- a/docs/adr/model-reasoning-effort-override.md
+++ b/docs/adr/model-reasoning-effort-override.md
@@ -19,6 +19,14 @@ allows/disallows the parameter. Keep this provenance separate from catalog
compatibility and apply it last, only when building a Chat Completions model.
The setting does not turn reasoning on or override the selected thinking level.
+## Update (2026-10-23)
+
+The automatic default for official `deepseek.com` endpoints changed after this
+ADR landed: those rows now leave `supportsReasoningEffort` to pi-ai detection,
+so the selected level reaches the wire by default (D672, #1821). The explicit
+per-model override described here is unchanged and still takes precedence in
+both directions.
+
Expose Auto / Send / Do not send in the existing per-model settings. Host
normalization, configuration copying and synchronization preserve the value.
Other APIs hide the setting and ignore it during request construction.
diff --git a/docs/spec/03-runtime/11-provider-model-system.md b/docs/spec/03-runtime/11-provider-model-system.md
index 87c439b1c..f9395a425 100644
--- a/docs/spec/03-runtime/11-provider-model-system.md
+++ b/docs/spec/03-runtime/11-provider-model-system.md
@@ -127,9 +127,14 @@ Non-official DeepSeek endpoints also set `requiresNonEmptyReasoningReplay` so
missing reasoning is filled with a documented placeholder instead of `""`
(OpenCode / third-party relays reject empty echoes after compaction; see
ADR 0256 / #296). Official `deepseek.com` rows keep empty-string fill (#223).
-Both official and relay rows set `supportsReasoningEffort: false`; DeepSeek
-does not accept the generic OpenAI `reasoning_effort` request field even when
-thinking is enabled. The overlay does not change `thinkingFormat`.
+Relay rows set `supportsReasoningEffort: false` because DeepSeek-family relays
+were reported rejecting the generic OpenAI `reasoning_effort` field (#1664).
+Official `deepseek.com` rows leave the flag to pi-ai, which sends
+`reasoning_effort` (low / high / max) next to `thinking: {type: "enabled"}` as
+DeepSeek documents, so the selected thinking level reaches the wire (#1821,
+D672). An explicit per-model `supportsReasoningEffort` selection (`send` or
+`omit`) still overrides this automatic rule on either kind of row. The overlay
+does not change `thinkingFormat`.
Anthropic Messages requests set `forceAdaptiveThinking: true` when the
models.dev record publishes a reasoning `effort` option and no
diff --git a/docs/spec/06-delivery/04-e2e-test-plan.md b/docs/spec/06-delivery/04-e2e-test-plan.md
index 24dde95a1..f5dd1e4d5 100644
--- a/docs/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/spec/06-delivery/04-e2e-test-plan.md
@@ -1732,9 +1732,10 @@ identify the platform validation still needed.
turns that had no thinking. Non-official DeepSeek-family relays use real
retained thinking when available, otherwise the documented non-empty
placeholder from ADR 0256 — never a silent empty string after compaction.
- The request omits the generic OpenAI `reasoning_effort` field because
- DeepSeek endpoints do not accept it, while the selected thinking mode still
- follows the endpoint's own wire format.
+ Relay requests omit the generic OpenAI `reasoning_effort` field because
+ relays were reported rejecting it (#1664). Official `api.deepseek.com`
+ requests send `thinking: {type: "enabled"}` together with the selected
+ `reasoning_effort` (#1821).
The request does not switch `thinkingFormat` to `"deepseek"` solely because
the model id contains `"deepseek"`. Official `api.deepseek.com` rows keep
URL-based DeepSeek `thinkingFormat` from pi-ai.
diff --git a/docs/spec/08-meta/decisions-log.md b/docs/spec/08-meta/decisions-log.md
index e3f8ab2c4..a7b84a613 100644
--- a/docs/spec/08-meta/decisions-log.md
+++ b/docs/spec/08-meta/decisions-log.md
@@ -81,7 +81,7 @@ This log freezes previously open questions into concrete decisions.
| D023 | Provider coverage goal | **Universal market coverage** (not a tiny fixed vendor list) | Globalization + real coding workflows |
| D024 | Coverage strategy | **pi-ai native providers + first-class OpenAI-compatible + custom providers** | Maximum reach without rewriting every SDK |
| D308 | Zhipu / Z.AI named endpoint presets | **Amend D024 / ADR 0116: the add-provider Service select offers four OpenAI-compatible Zhipu endpoints — China and international standard API plus GLM Coding Plan — with locked published URLs and models.dev `vendorKey`s (`zhipuai`, `zhipuai-coding-plan`, `zai`, `zai-coding-plan`). No new apiStyle or wire adapter. Completions requests on those URLs use `thinkingFormat: "zai"` and `zaiToolStream: true`. Custom endpoint remains available.** | Users had to know which BigModel / Z.AI URL to paste, and `vendorKey: "custom"` could catalog-match the wrong API vs Coding Plan record. Named presets keep coverage on the existing OpenAI-compatible path. See ADR 0155 and E2E-005D. |
-| D389 | DeepSeek reasoning_content replay on aggregators | **Amend D024: Completions requests for DeepSeek-family models set `requiresReasoningContentOnAssistantMessages: true` and `supportsReasoningEffort: false` when the row `vendorKey`, base URL, model id, or catalog `family` identifies DeepSeek. Do not change `thinkingFormat` for that match. pi-ai still auto-detects official `deepseek.com` URLs.** | DeepSeek thinking mode 400s if any replayed assistant message omits `reasoning_content` or if a relay receives the unsupported generic `reasoning_effort` field. PI-Desktop stores a UUID as `model.provider`, so SiliconFlow, Volcengine, and custom gateways never match pi-ai's `provider === "deepseek"` check. See E2E-005E. |
+| D389 | DeepSeek reasoning_content replay on aggregators | **Amend D024: Completions requests for DeepSeek-family models set `requiresReasoningContentOnAssistantMessages: true` (and, off `deepseek.com`, `supportsReasoningEffort: false`; amended by D672) when the row `vendorKey`, base URL, model id, or catalog `family` identifies DeepSeek. Do not change `thinkingFormat` for that match. pi-ai still auto-detects official `deepseek.com` URLs.** | DeepSeek thinking mode 400s if any replayed assistant message omits `reasoning_content` or if a relay receives the unsupported generic `reasoning_effort` field. PI-Desktop stores a UUID as `model.provider`, so SiliconFlow, Volcengine, and custom gateways never match pi-ai's `provider === "deepseek"` check. See E2E-005E. |
| D424 | DeepSeek reasoning across compaction | **Amend D389 / ADR 0136: restore thinkingSignature on history rebuild; store recent thinking in checkpoint `details.retainedReasoning` and replay after the summary; non-official DeepSeek Completions rows set `requiresNonEmptyReasoningReplay` so the pi-ai patch uses a documented placeholder instead of `""`. Official deepseek.com keeps empty-string fill.** | OpenCode / third-party DeepSeek V4.1 Flash 400s after compaction when empty reasoning is echoed (#296). |
| D309 | Add-provider common path is Service + key | **Amend D308 / ADR 0116 / ADR 0155: a new add-provider dialog starts with only Service. Named endpoints (Zhipu / Z.AI, OpenCode Go) then show Service + API key and a host summary. Custom endpoint then shows Name, Base URL, and API key. Name (named) and API format (custom) stay in Advanced. OpenCode Go is a Service option. No stepper or vendor-card grid.** | Stacking Name, Base URL, and API format next to Service made a known service look like a generic gateway. The common path should be pick a service and paste a key. See ADR 0156 and E2E-005 / E2E-005B / E2E-005D. |
| D310 | Custom API format stays beside the key; Service lists top models.dev vendors | **Amend D309 / ADR 0155 / ADR 0156: Custom endpoint shows Name + Base URL, then API key beside API format on the common path. Named Service options expand to models.dev-backed international and China first-party endpoints (OpenAI, Anthropic, Google, OpenRouter, Groq, xAI, Mistral, Together, Fireworks, OpenCode Go, Z.AI, DeepSeek, Qwen, Moonshot, Zhipu, SiliconFlow, Volcengine, MiniMax Anthropic Messages, MiniMax OpenAI-compatible, Kimi For Coding), each with a published URL and wire style. Named display names stay in Advanced.** | Custom gateways need the format next to the key, while named vendors should cover the usual domestic and international APIs without a closed allowlist. See E2E-005 / E2E-005B / E2E-005D. |
@@ -7947,3 +7947,23 @@ must keep splitting are covered by `markdown-blocks.test.mjs`.
panel.
See ADR `gen-ui-inline-visualization`, `03-runtime/03-tools-and-permissions.md`
§4b.1, `03-runtime/04-data-storage.md`, and E2E-GENUI-inline-visualization-card.
+
+## 2026-10-23 — Official DeepSeek endpoints send reasoning_effort again (D672)
+
+- D672 amends D389: only DeepSeek-family rows whose base URL is not
+ `deepseek.com` set `supportsReasoningEffort: false`. Official rows leave the
+ flag to pi-ai, which sends `reasoning_effort` next to
+ `thinking: {type: "enabled"}`.
+- DeepSeek documents `reasoning_effort` (low / high / max) for Chat
+ Completions. With the flag forced off, official requests carried only the
+ thinking toggle, so low, high, and max produced the same request (#1821).
+ The #1664 report concerned relays, which keep the suppression by default.
+ Verified against `api.deepseek.com`: low, high, and max arrive as sent and
+ the endpoint still returns 200 for `thinking: {type: "enabled"}` alone.
+- The per-model `supportsReasoningEffort` override from D671 / #1846 still wins
+ in both directions, and relays that reject the field keep the suppression.
+- No persisted format or protocol change. Covered by
+ `packages/shared/src/provider-presets.test.ts`, the captured-request test in
+ `packages/agent-runtime/src/provider-binding.test.ts`, and the official-wire
+ cases in `packages/agent-runtime/src/provider-reasoning-effort.test.ts`. See
+ `03-runtime/11-provider-model-system.md` and E2E-005E.
diff --git a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
index 31ea7fd85..852f2163e 100644
--- a/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
+++ b/docs/zh-CN/spec/03-runtime/11-provider-model-system.md
@@ -118,8 +118,11 @@ OpenAI 风格的 Copilot 线路 API 仍将令牌作为请求密钥签名;所
`reasoning_content`。非官方 DeepSeek 端点还会设置 `requiresNonEmptyReasoningReplay`,
用文档化的非空占位符而不是 `""` 填补缺失推理(OpenCode / 第三方中转在压缩后拒绝空回传;
见 ADR 0256 / #296)。官方 `deepseek.com` 行仍使用空串回填(#223)。该覆盖不改
-`thinkingFormat`。官方与中转行都会设置 `supportsReasoningEffort: false`;即使开启思考,
-DeepSeek 也不接受通用 OpenAI 的 `reasoning_effort` 请求字段。
+`thinkingFormat`。中转行设置 `supportsReasoningEffort: false`,因为有 DeepSeek 系中转
+被报告拒绝通用 OpenAI 的 `reasoning_effort` 字段(#1664)。官方 `deepseek.com` 行把该标志
+交给 pi-ai,按 DeepSeek 文档在 `thinking: {type: "enabled"}` 旁发送 `reasoning_effort`
+(low / high / max),使所选思考等级真正下发(#1821,D672)。模型绑定上显式选择的
+`supportsReasoningEffort`(`send` 或 `omit`)在两类行上都仍优先于该自动规则。
当 Pi catalog 记录发布了推理 `effort` 选项且没有 `budget_tokens` 选项时
(例如 Opus 4.7+、Opus 5.x、Fable),Anthropic Messages 请求会设置
diff --git a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
index 45af7f685..0d853866b 100644
--- a/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
+++ b/docs/zh-CN/spec/06-delivery/04-e2e-test-plan.md
@@ -489,7 +489,7 @@ task-candidate E2E 从请求工作树运行,但使用主工作区已经准备
- **前提条件**:已配置一个 Base URL 不含 `deepseek.com` 的 OpenAI 兼容提供商,模型 ID 属于 DeepSeek 系(例如硅基流动 `deepseek-ai/DeepSeek-V3.2`),并开启思考模式。
- **步骤**:1) 在思考模式下开始会话。2) 完成若干回合,其中至少一条助手回复没有思考文本。3) 再发一条提示,使历史被回放到提供商。
-- **预期**:后续 Completions 请求的每条 assistant 消息都带推理字段。官方 `api.deepseek.com` 行对无思考内容的回合仍可使用 `""`。非官方 DeepSeek 系中转在可用时回传保留的真实思考,否则使用 ADR 0256 文档化的非空占位符——压缩后不得静默回填空串。请求不会携带通用 OpenAI 的 `reasoning_effort` 字段,因为 DeepSeek 端点不接受它;已选的思考模式仍按端点自身线路发送。不会仅因模型 ID 含 `"deepseek"` 就把 `thinkingFormat` 改成 `"deepseek"`。官方 `api.deepseek.com` 行仍使用 pi-ai 按 URL 检测的 DeepSeek `thinkingFormat`。
+- **预期**:后续 Completions 请求的每条 assistant 消息都带推理字段。官方 `api.deepseek.com` 行对无思考内容的回合仍可使用 `""`。非官方 DeepSeek 系中转在可用时回传保留的真实思考,否则使用 ADR 0256 文档化的非空占位符——压缩后不得静默回填空串。中转请求不携带通用 OpenAI 的 `reasoning_effort` 字段,因为有中转被报告拒绝它(#1664);官方 `api.deepseek.com` 请求同时发送 `thinking: {type: "enabled"}` 与所选的 `reasoning_effort`(#1821)。不会仅因模型 ID 含 `"deepseek"` 就把 `thinkingFormat` 改成 `"deepseek"`。官方 `api.deepseek.com` 行仍使用 pi-ai 按 URL 检测的 DeepSeek `thinkingFormat`。
- **链接规格**:`03-runtime/11-provider-model-system.md`、
`03-runtime/12-provider-config-schema.md`
- **验收**:B(提供商 Completions 兼容)
diff --git a/docs/zh-CN/spec/08-meta/decisions-log.md b/docs/zh-CN/spec/08-meta/decisions-log.md
index 44ee3d882..03f57b51d 100644
--- a/docs/zh-CN/spec/08-meta/decisions-log.md
+++ b/docs/zh-CN/spec/08-meta/decisions-log.md
@@ -83,7 +83,7 @@
| D023 | 提供商覆盖目标 | **全球市场覆盖**(不是一个很小的固定供应商列表) | 全球化+真实的编码工作流程 |
| D024 | 覆盖策略 | **pi-ai 原生提供商 + 一流的 OpenAI 兼容 + 自定义提供商** | 无需重写每个 SDK 即可实现最大覆盖范围 |
| D308 | 智谱 / Z.AI 命名端点预设 | **修订 D024 / ADR 0116:添加服务的「服务」下拉框提供四套 OpenAI 兼容智谱端点——国内/国际标准 API 以及 GLM Coding Plan——锁定已发布 URL,并写入 models.dev `vendorKey`(`zhipuai`、`zhipuai-coding-plan`、`zai`、`zai-coding-plan`)。不新增 apiStyle 或线路适配器。这些 URL 上的 Completions 请求使用 `thinkingFormat: "zai"` 与 `zaiToolStream: true`。自定义端点仍可用。** | 用户此前必须手填 BigModel / Z.AI 地址,且 `vendorKey: "custom"` 可能把 API 与 Coding Plan 目录配错。命名预设把覆盖范围留在现有 OpenAI 兼容路径上。见 ADR 0155 与 E2E-005D。 |
-| D389 | 聚合端点上回放 DeepSeek 的 reasoning_content | **修订 D024:当行的 `vendorKey`、Base URL、模型 ID 或目录 `family` 能识别为 DeepSeek 时,DeepSeek 系模型的 Completions 请求设置 `requiresReasoningContentOnAssistantMessages: true` 与 `supportsReasoningEffort: false`。该匹配不改 `thinkingFormat`。pi-ai 仍对官方 `deepseek.com` URL 做自动检测。** | DeepSeek 思考模式在任一条回放的 assistant 消息缺少 `reasoning_content`,或中转收到不支持的通用 `reasoning_effort` 字段时会 400。PI-Desktop 把 UUID 存成 `model.provider`,硅基流动、火山方舟和自定义网关永远匹配不上 pi-ai 的 `provider === "deepseek"` 判断。见 E2E-005E。 |
+| D389 | 聚合端点上回放 DeepSeek 的 reasoning_content | **修订 D024:当行的 `vendorKey`、Base URL、模型 ID 或目录 `family` 能识别为 DeepSeek 时,DeepSeek 系模型的 Completions 请求设置 `requiresReasoningContentOnAssistantMessages: true`(非 `deepseek.com` 时另设 `supportsReasoningEffort: false`;由 D672 修订)。该匹配不改 `thinkingFormat`。pi-ai 仍对官方 `deepseek.com` URL 做自动检测。** | DeepSeek 思考模式在任一条回放的 assistant 消息缺少 `reasoning_content`,或中转收到不支持的通用 `reasoning_effort` 字段时会 400。PI-Desktop 把 UUID 存成 `model.provider`,硅基流动、火山方舟和自定义网关永远匹配不上 pi-ai 的 `provider === "deepseek"` 判断。见 E2E-005E。 |
| D424 | 压缩后保留 DeepSeek 推理 | **修订 D389 / ADR 0136:历史重建时恢复 thinkingSignature;把最近思考写入检查点 `details.retainedReasoning` 并在摘要后回放;非官方 DeepSeek Completions 行设置 `requiresNonEmptyReasoningReplay`,使 pi-ai 补丁使用文档化占位符而非 `""`。官方 deepseek.com 仍用空串回填。** | OpenCode / 第三方 DeepSeek V4.1 Flash 在压缩后回传空推理字段会 400(#296)。 |
| D309 | 添加服务的常见路径是服务 + 密钥 | **修订 D308 / ADR 0116 / ADR 0155:新建添加服务对话框先只显示服务。命名端点(智谱 / Z.AI、OpenCode Go)随后显示服务 + API 密钥和主机摘要。自定义端点随后显示名称、Base URL 和 API 密钥。名称(命名行)与接口格式(自定义行)放在高级里。OpenCode Go 是服务选项。没有步进器或厂商卡片网格。** | 把名称、Base URL 和接口格式与服务叠在一起,让已知服务看起来像通用网关。常见路径应是选服务并粘贴密钥。见 ADR 0156 与 E2E-005 / E2E-005B / E2E-005D。 |
| D310 | 自定义接口格式与密钥并排;服务列出 models.dev 主流厂商 | **修订 D309:自定义端点在常见路径上并排显示 API 密钥与接口格式。服务下拉框按国际 / 国内列出 models.dev 的主流厂商端点。命名服务的显示名称仍在高级里。** | 自定义网关需要在密钥旁选择格式;命名厂商应覆盖常用国内外 API。见 E2E-005。 |
@@ -5550,3 +5550,19 @@ Markdown 源码,不是 `text/html` 负载;对禁用行内 HTML 的外部编
- v1 不支持控件状态、后续消息、CDN、图标库和微调面板。
见 ADR `gen-ui-inline-visualization`、`03-runtime/03-tools-and-permissions.md`
§4b.1、`03-runtime/04-data-storage.md` 与 E2E-GENUI-inline-visualization-card。
+
+## 2026-10-23 — 官方 DeepSeek 端点恢复发送 reasoning_effort(D672)
+
+- D672 修订 D389:只有 Base URL 不是 `deepseek.com` 的 DeepSeek 系行设置
+ `supportsReasoningEffort: false`。官方行把该标志交给 pi-ai,由它在
+ `thinking: {type: "enabled"}` 旁发送 `reasoning_effort`。
+- DeepSeek 文档为 Chat Completions 提供 `reasoning_effort`(low / high / max)。强制关闭
+ 后官方请求只剩思考开关,low、high、max 发出的请求完全相同(#1821)。#1664 针对的是
+ 中转,中转默认仍然抑制。已在 `api.deepseek.com` 上验证:low、high、max 原样到达,
+ 只发送 `thinking: {type: "enabled"}` 时仍返回 200。
+- 来自 D671 / #1846 的按模型 `supportsReasoningEffort` 覆盖在双向仍优先,拒绝该字段的
+ 中转保持抑制。
+- 不改变持久化格式或协议。由 `packages/shared/src/provider-presets.test.ts`、
+ `packages/agent-runtime/src/provider-binding.test.ts` 的请求抓取测试,以及
+ `packages/agent-runtime/src/provider-reasoning-effort.test.ts` 的官方线路用例覆盖。见
+ `03-runtime/11-provider-model-system.md` 与 E2E-005E。
diff --git a/packages/agent-runtime/src/provider-binding.test.ts b/packages/agent-runtime/src/provider-binding.test.ts
index d47396951..66504b30c 100644
--- a/packages/agent-runtime/src/provider-binding.test.ts
+++ b/packages/agent-runtime/src/provider-binding.test.ts
@@ -1616,6 +1616,74 @@ describe("DeepSeek-family relay reasoning replay (#296)", () => {
});
});
+describe("DeepSeek Completions reasoning effort on the wire (#1821)", () => {
+ const captureFirstRequest = async (
+ provider: RuntimeProviderConfig,
+ reasoning: "low" | "high" | undefined,
+ ): Promise<Record<string, unknown>> => {
+ const requests: Record<string, unknown>[] = [];
+ const fetch = vi.fn(async (_input: RequestInfo | URL, init?: RequestInit) => {
+ requests.push(JSON.parse(String(init?.body)) as Record<string, unknown>);
+ return new Response(
+ JSON.stringify({ choices: [{ delta: { content: "ok" }, finish_reason: "stop" }] }),
+ { status: 200, headers: { "content-type": "application/json" } },
+ );
+ });
+ const model = buildProviderModel(provider);
+ await createProviderModels(provider, model)
+ .streamSimple(
+ model,
+ {
+ systemPrompt: "system",
+ messages: [{ role: "user", content: "hello", timestamp: 1 }],
+ tools: [],
+ },
+ { reasoning, fetch },
+ )
+ .result();
+ expect(requests).toHaveLength(1);
+ return requests[0];
+ };
+
+ const official: RuntimeProviderConfig = {
+ ...keyedProvider,
+ id: "deepseek-row",
+ vendorKey: "deepseek",
+ baseUrl: "https://api.deepseek.com",
+ modelId: "deepseek-flash",
+ supportsReasoning: true,
+ supportedThinkingLevels: ["off", "low", "high"],
+ };
+
+ it("sends the selected effort next to thinking on the official endpoint", async () => {
+ const high = await captureFirstRequest(official, "high");
+ expect(high.thinking).toEqual({ type: "enabled" });
+ expect(high.reasoning_effort).toBe("high");
+
+ const low = await captureFirstRequest(official, "low");
+ expect(low.reasoning_effort).toBe("low");
+
+ const off = await captureFirstRequest(official, undefined);
+ expect(off.thinking).toEqual({ type: "disabled" });
+ expect(off.reasoning_effort).toBeUndefined();
+ });
+
+ it("still omits reasoning_effort on a DeepSeek relay by default (#1664)", async () => {
+ const relay = await captureFirstRequest(
+ {
+ ...keyedProvider,
+ id: "relay",
+ baseUrl: "https://gw.example.test/v1",
+ modelId: "deepseek-v4.1-flash",
+ supportsReasoning: true,
+ supportedThinkingLevels: ["off", "low", "high"],
+ },
+ "high",
+ );
+ expect(relay.reasoning_effort).toBeUndefined();
+ });
+});
+
describe("session affinity for the adapters' anonymous endpoints (#1634)", () => {
const ownEndpoint = (
overrides: Partial<RuntimeProviderConfig> = {},
diff --git a/packages/agent-runtime/src/provider-reasoning-effort.test.ts b/packages/agent-runtime/src/provider-reasoning-effort.test.ts
index 0a107f667..7adc66aa9 100644
--- a/packages/agent-runtime/src/provider-reasoning-effort.test.ts
+++ b/packages/agent-runtime/src/provider-reasoning-effort.test.ts
@@ -81,9 +81,69 @@ describe("per-model Chat Completions reasoning effort override", () => {
expect(bodies[0]).not.toHaveProperty("reasoning_effort");
});
- it.each([undefined, null, false, true])("keeps official DeepSeek auto protection with override %s", (override) => {
- const provider = { ...providerFor("deepseek-v4.1-flash", override), vendorKey: "deepseek", baseUrl: "https://api.deepseek.com" };
- expect(buildProviderModel(provider).compat).toMatchObject({ supportsReasoningEffort: override === true });
+ function officialProvider(override?: boolean | null): RuntimeProviderConfig {
+ const provider = {
+ ...providerFor("deepseek-v4.1-flash", override),
+ vendorKey: "deepseek",
+ baseUrl: "https://api.deepseek.com",
+ };
+ return {
+ ...provider,
+ supportedThinkingLevels: ["off", "low", "high", "max"],
+ modelConfig: modelConfigWithBinding(genericModelConfig(provider.modelId), {
+ contextWindow: 128_000,
+ maxTokens: 8192,
+ thinkingLevels: ["off", "low", "high", "max"],
+ supportsReasoningEffort: override,
+ }),
+ };
+ }
+
+ async function captureOfficialBody(reasoning?: "low" | "high" | "max"): Promise<Record<string, unknown>> {
+ const provider = officialProvider(undefined);
+ const model = buildProviderModel(provider);
+ const bodies: Record<string, unknown>[] = [];
+ await createProviderModels(provider, model).streamSimple(model, {
+ messages: [{ role: "user", content: "hello", timestamp: 0 }],
+ }, {
+ ...(reasoning ? { reasoning } : {}),
+ fetch: async (input, init) => {
+ bodies.push(await new Request(input, init).json() as Record<string, unknown>);
+ const chunk = {
+ id: "fixture", object: "chat.completion.chunk", created: 0, model: provider.modelId,
+ choices: [{ index: 0, delta: { role: "assistant", content: "OK" }, finish_reason: "stop" }],
+ };
+ return new Response(`data: ${JSON.stringify(chunk)}\n\ndata: [DONE]\n\n`, {
+ headers: { "content-type": "text/event-stream" },
+ });
+ },
+ }).result();
+ expect(bodies).toHaveLength(1);
+ return bodies[0];
+ }
+
+ it.each([undefined, null])("leaves official DeepSeek to pi-ai detection (override %s)", (override) => {
+ const compat = buildProviderModel(officialProvider(override)).compat ?? {};
+ expect(compat).not.toHaveProperty("supportsReasoningEffort");
+ });
+
+ it("keeps an explicit omit on official DeepSeek rows", () => {
+ expect(buildProviderModel(officialProvider(false)).compat).toMatchObject({ supportsReasoningEffort: false });
+ });
+
+ it("sends an explicit allow on official DeepSeek rows", () => {
+ expect(buildProviderModel(officialProvider(true)).compat).toMatchObject({ supportsReasoningEffort: true });
+ });
+
+ it.each(["low", "high", "max"] as const)("carries the %s level to the official DeepSeek wire", async (level) => {
+ const body = await captureOfficialBody(level);
+ expect(body.thinking).toEqual({ type: "enabled" });
+ expect(body.reasoning_effort).toBe(level);
+ });
+
+ it("sends only the thinking toggle for an official DeepSeek row at off", async () => {
+ const body = await captureOfficialBody();
+ expect(body).not.toHaveProperty("reasoning_effort");
});
it("does not mistake catalog compatibility for an explicit saved override", () => {
diff --git a/packages/shared/src/provider-presets.test.ts b/packages/shared/src/provider-presets.test.ts
index 083dae6d9..a90638d05 100644
--- a/packages/shared/src/provider-presets.test.ts
+++ b/packages/shared/src/provider-presets.test.ts
@@ -93,10 +93,35 @@ describe("DeepSeek reasoning replay", () => {
deepseekRequestCompat({ baseUrl: "https://api.deepseek.com" }),
).toEqual({
requiresReasoningContentOnAssistantMessages: true,
- supportsReasoningEffort: false,
});
});
+ it("keeps reasoning_effort on official endpoints and suppresses it on relays (#1821)", () => {
+ // Official DeepSeek Completions documents `reasoning_effort` (low/high/max)
+ // next to `thinking`; only relays were reported to reject it (#1664).
+ expect(
+ deepseekRequestCompat({ baseUrl: "https://api.deepseek.com/v1", modelId: "deepseek-flash" })
+ ?.supportsReasoningEffort,
+ ).toBeUndefined();
+ expect(
+ deepseekRequestCompat({ baseUrl: "https://gw.example.test/v1", modelId: "deepseek-v4.1-flash" })
+ ?.supportsReasoningEffort,
+ ).toBe(false);
+ });
+
+ it("does not treat a relay URL containing deepseek.com as an official host", () => {
+ for (const baseUrl of [
+ "https://api.deepseek.com.evil.test/v1",
+ "https://relay.example.test/v1/deepseek.com",
+ ]) {
+ expect(isOfficialDeepSeekEndpoint({ baseUrl })).toBe(false);
+ expect(deepseekRequestCompat({ baseUrl, modelId: "deepseek-v4.1-flash" })).toMatchObject({
+ supportsReasoningEffort: false,
+ requiresNonEmptyReasoningReplay: true,
+ });
+ }
+ });
+
it("matches aggregator and custom DeepSeek-family models without a deepseek.com URL", () => {
expect(
deepseekRequestCompat({
diff --git a/packages/shared/src/provider-presets.ts b/packages/shared/src/provider-presets.ts
index f38e73d78..7c80cd234 100644
--- a/packages/shared/src/provider-presets.ts
+++ b/packages/shared/src/provider-presets.ts
@@ -508,7 +508,14 @@ export function isDeepSeekReasoningReplay(input: {
/** Official DeepSeek Completions hosts that still accept empty-string replay. */
export function isOfficialDeepSeekEndpoint(input: { baseUrl?: string }): boolean {
- return (input.baseUrl ?? "").toLowerCase().includes("deepseek.com");
+ const baseUrl = input.baseUrl?.trim();
+ if (!baseUrl) return false;
+ try {
+ const hostname = new URL(baseUrl).hostname.toLowerCase();
+ return hostname === "deepseek.com" || hostname.endsWith(".deepseek.com");
+ } catch {
+ return false;
+ }
}
/**
@@ -522,8 +529,12 @@ export const DEEPSEEK_REASONING_REPLAY_PLACEHOLDER =
export type DeepSeekRequestCompat = {
requiresReasoningContentOnAssistantMessages: true;
- /** DeepSeek endpoints reject the OpenAI-style `reasoning_effort` field. */
- supportsReasoningEffort: false;
+ /**
+ * Relays reported rejecting the OpenAI-style `reasoning_effort` field
+ * (#1664), so it is suppressed off `deepseek.com`. Official endpoints
+ * document it next to `thinking` and keep pi-ai's detection (#1821).
+ */
+ supportsReasoningEffort?: false;
/** When set, missing reasoning is filled with {@link DEEPSEEK_REASONING_REPLAY_PLACEHOLDER}. */
requiresNonEmptyReasoningReplay?: true;
};
@@ -537,10 +548,7 @@ export function deepseekRequestCompat(input: {
}): DeepSeekRequestCompat | undefined {
if (!isDeepSeekReasoningReplay(input)) return undefined;
if (isOfficialDeepSeekEndpoint(input)) {
- return {
- requiresReasoningContentOnAssistantMessages: true,
- supportsReasoningEffort: false,
- };
+ return { requiresReasoningContentOnAssistantMessages: true };
}
return {
requiresReasoningContentOnAssistantMessages: true,