DeepSeek 网摘deepseek.wang
EN
📄 查看英文原文

教程 · 2026-04-25 · 机器翻译,仅供参考

如何设置 DeepSeek Chrome 扩展程序 V4(步骤详解)

Tutorials·April 25, 2026·By DS指南编辑
DeepSeek Chrome extension tutorial card showing the five steps to build a side-panel that pipes selected text into V4: define manifest.json with a side_panel UI, store the sk- API key in chrome.storage.local, send the selected text or freeform prompt to the OpenAI-compatible /chat/completions endpoint, route easy work to V4-Flash and harder work to V4-Pro, and stream the response into the panel.

想要在浏览器标签旁边直接获取DeepSeek的答案,而无需复制粘贴到聊天窗口中吗?DeepSeek Chrome扩展程序正是如此——它将选定的文本、页面摘要或自由形式问题传递到DeepSeek API,并直接显示响应。但问题是Chrome Web Store中没有单一的“官方”DeepSeek扩展;您可以选择接受DeepSeek API密钥的社区扩展,或者自己用大约80行代码构建一个最小化的扩展。

本教程将使用2026年4月24日发布的当前DeepSeek V4模型介绍这两种方法。到结束时,您将拥有一个工作侧边栏,该侧边栏在选定的文本上调用`deepseek-v4-flash`(或`deepseek-v4-pro`),并显示成本估算和常见错误。

What you’ll build

Browser with a DeepSeek Chrome extension popup open beside an article, showing summarise and ask actions.

您将在这个教程结束时拥有一个Chrome扩展程序,该扩展程序打开一个侧面板,从网页上获取提示或当前选定的文本,并从DeepSeek API返回响应。该扩展程序将您的API密钥本地存储在 chrome.storage.local,向兼容OpenAI的端点发送请求 POST /chat/completions,并支持成本效益 deepseek-v4-flash 和前沿级别的 deepseek-v4-pro 模型ID。

覆盖两条路径:

  • 路径A — 安装社区扩展 从Chrome Web Store中获取并粘贴您的API密钥。最快,但您信任他人的代码来处理您的密钥。
  • 路径B — 构建您自己的最小化扩展 使用清单V3。大约需要15-20分钟,可完全控制,并可以从本地文件夹中解包加载。

两条路径都针对相同的API接口,因此请求/响应逻辑相同。如果您对API本身是新手,请参阅 DeepSeek API getting started 指南涵盖了身份验证以及将请求连接到浏览器之前的第一步操作。

Prerequisites

  • Google Chrome 120+(或任何支持清单V3的Chromium浏览器——Edge、Brave、Arc)。
  • 一个DeepSeek账户和一个API密钥。如果您没有,请按照 get a DeepSeek API key walkthrough.
  • DeepSeek计费控制台上的资金余额。即使是2美元的充值也足以在V4-Flash上进行数千次测试调用。
  • 仅针对路径B:一个文本编辑器(VS Code即可)以及基本的JavaScript和JSON知识。

为什么选择Chrome扩展而不是网页应用?

DeepSeek网站聊天(chat.deepseek.com)功能齐全,并能跨回合保持对话历史。浏览器扩展在三个特定的工作流程中胜出:

  • 上下文选择。 在任何标签页中突出显示一段文本,并将其发送到DeepSeek,无需切换窗口。
  • 页面感知提示。 使用“总结这篇文章”或“提取关键论点”的指令,页面文本会自动注入。
  • 模型和参数控制。 选择V4-Flash进行常规工作,V4-Pro进行更复杂的推理,根据 temperature 每个任务设置,并切换思考模式——这些功能网页UI无法以相同方式暴露。

代价:API是无状态的。与网页聊天不同,扩展必须在每个请求中重新发送对话历史。欲了解更多差异,请参阅 DeepSeek browser vs app.

路径A:安装社区扩展

Chrome Web Store中有几个第三方扩展程序接受DeepSeek API密钥。搜索“DeepSeek”或“AI侧边栏”,在安装前寻找这些信号:

  1. 开源,您可以通过链接的GitHub仓库阅读。
  2. API密钥本地存储 in chrome.storage.local,永远不会发送到第三方服务器。
  3. 最近更新 (过去90天内)以及非平凡的安装次数。
  4. 清单V3 — 清单V2扩展已被弃用,并将停止工作。

配置扩展

安装后,打开扩展的选项页面,然后:

  1. 从DeepSeek控制台粘贴您的API密钥。
  2. 将基本URL设置为 https://api.deepseek.com (or https://api.deepseek.com/v1 (如果扩展预期为OpenAI路径)。
  3. 将模型设置为 deepseek-v4-flash 以供通用使用。
  4. 如果思维模式被暴露,请在日常提示时关闭它,仅在有更复杂的推理任务时启用它。

如果扩展仍然引用旧版ID,如 deepseek-chat or deepseek-reasoner,它们将继续工作——它们目前路由到 deepseek-v4-flash — but they will be retired on 2026-07-24 at 15:59 UTC。在有机会时切换到V4 ID;迁移只需一行代码。 model= swap and the base_url does not change.

路径B:构建自己的最小化扩展

如果您关心您的API密钥所触及的内容,这是我的推荐路线。以下扩展程序是一个完整的清单V3构建,包含三个文件: manifest.json, sidepanel.html, and sidepanel.js.

第1步:创建项目文件夹

创建一个名为 deepseek-sidepanel 的目录,其中包含以下三个文件。

第2步:编写清单文件

Create manifest.json 如下JSON。其中的 host_permissions 条目允许从扩展内部调用DeepSeek API的fetch请求。

{
  "manifest_version": 3,
  "name": "DeepSeek Side Panel",
  "version": "1.0.0",
  "description": "Send selected text to DeepSeek V4.",
  "permissions": ["sidePanel", "storage", "activeTab", "scripting"],
  "host_permissions": ["https://api.deepseek.com/*"],
  "action": { "default_title": "Open DeepSeek panel" },
  "side_panel": { "default_path": "sidepanel.html" },
  "background": {
    "service_worker": "background.js"
  }
}

第3步:编写侧边栏HTML

Create sidepanel.html这是可见的用户界面:一个密钥字段、一个模型选择器、一个提示框和一个响应区域。

<!doctype html>
<html>
  <body>
    <input id="key" type="password" placeholder="DeepSeek API key" />
    <select id="model">
      <option value="deepseek-v4-flash">V4-Flash (cheap)</option>
      <option value="deepseek-v4-pro">V4-Pro (frontier)</option>
    </select>
    <label><input id="think" type="checkbox" /> Thinking mode</label>
    <textarea id="prompt" rows="6"></textarea>
    <button id="send">Send</button>
    <pre id="out"></pre>
    <script src="sidepanel.js"></script>
  </body>
</html>

第4步:编写侧边栏JavaScript

Create sidepanel.js此文件构建请求体,调用 POST /chat/completions,并渲染响应。OpenAI SDK的模式在这里也是使用普通的 fetch.

const $ = (id) => document.getElementById(id);

chrome.storage.local.get("key", (r) => { if (r.key) $("key").value = r.key; });
$("key").addEventListener("change", (e) =>
  chrome.storage.local.set({ key: e.target.value })
);

$("send").addEventListener("click", async () => {
  const body = {
    model: $("model").value,
    messages: [{ role: "user", content: $("prompt").value }],
    temperature: 1.3,
    max_tokens: 2048,
    stream: false
  };
  if ($("think").checked) {
    body.reasoning_effort = "high";
    body.thinking = { type: "enabled" };
  }
  const res = await fetch("https://api.deepseek.com/chat/completions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "Authorization": "Bearer " + $("key").value
    },
    body: JSON.stringify(body)
  });
  const data = await res.json();
  $("out").textContent = data.choices?.[0]?.message?.content ?? JSON.stringify(data, null, 2);
});

需要一个小型的 background.js 服务工作者来在点击工具栏图标时打开面板:

chrome.action.onClicked.addListener((tab) =>
  chrome.sidePanel.open({ windowId: tab.windowId })
);

第5步:在Chrome中加载扩展

  1. Open chrome://extensions.
  2. Toggle 开发者模式 打开(右上角)。
  3. Click 加载未打包 并选择您的 deepseek-sidepanel 文件夹。
  4. 将扩展程序固定到工具栏。

Verify it worked

点击工具栏图标以打开侧边面板,粘贴您的API密钥,保持模型开启,并输入“用单个单词在响应区域内。回复。”点击 deepseek-v4-flash。您应该在1-2秒内看到 Send在响应区域内。 在响应区域内。 如果启用思考模式,响应对象还包含

If thinking mode is enabled, the response object also contains reasoning_content alongside the final content. 上述最小扩展仅涉及渲染 content; 将其扩展以显示推理跟踪只需五行代码更改。

成本:这实际上运行的是什么?

根据官方DeepSeek定价页面,截至2026年4月的API定价:

Model Input cache hit Input cache miss Output
deepseek-v4-flash $0.0028 / 1M $0.14 / 1M $0.28 / 1M
deepseek-v4-pro $0.0145 / 1M (list; promo $0.003625 through 2026-05-31) $0.435 promo / $1.74 list per 1M $0.87 promo / $3.48 list per 1M

一个现实的Chrome扩展程序工作负载——比如每天200个提示,每个提示包含一个500个token的系统提示(已缓存)、一个300个token的用户消息和一个600个token的回复——在以下情况下花费如下: deepseek-v4-flash:

  • 缓存输入:500 × 200 = 100,000个token × $0.0028/M = $0.0028
  • 非缓存输入:300 × 200 = 60,000个token × $0.14/M = $0.0084
  • 输出:600 × 200 = 120,000个token × $0.28/M = $0.0336
  • 每日总计:约$0.045 — 大约每月$1.35。

The same workload on deepseek-v4-pro 运行大约 每日$0.45或者每月13.50美元——大约是花费的10倍,只有在V4-Flash真正在任务上失败时才有正当理由。对于更丰富的估算器,请参考: DeepSeek pricing calculator 处理混合工作负载。

V3及之前版本下的离峰折扣已于2025-09-05结束,并且尚未在V4中重新引入。不要围绕它们进行预算。

DeepSeek官方的温度指南值得直接编码到您扩展程序的UI预设中:

Task type Temperature Notes
Code generation, math 0.0 确定性;与V4-Pro搭配解决难题
数据分析,数据清洗 1.0 平衡;V4-Flash足够好
通用聊天,翻译 1.3 侧面板上方的默认设置
Creative writing, poetry 1.5 较松的采样

值得在Chrome扩展UI中展示的其他参数: top_p 用于核采样, max_tokens (V4支持最多384,000个输出标记,相对于1,000,000个标记的上下文窗口), stream 用于逐个标记渲染,和 response_format={"type": "json_object"} 对于JSON模式。JSON模式旨在返回有效的JSON——但不保证——因此,在您的提示中始终包含“json”一词,并附带一个小示例模式,并设置 max_tokens high enough that the output cannot be truncated mid-object.

Common errors and fixes

Symptom Likely cause Fix
401 Unauthorized 错误或缺失的API密钥 重新粘贴密钥;检查是否没有前后空格
402 Payment Required 余额为零 在计费控制台中充值
429 Too Many Requests Rate limit hit 添加少量回退;参见 DeepSeek API rate limits 参考
控制台中出现CORS错误 host_permissions 缺失 Confirm https://api.deepseek.com/* in manifest.json
空响应,JSON模式 已记录的边缘情况 重新提示;提出 max_tokens包含 "json" + schema 在提示中
Truncated thinking output max_tokens too low 为 thinking-max 设置 max_tokens ≥ 384,000 容量
模型ID被拒绝 错别字或2026-07-24之后停用的ID Use deepseek-v4-flash or deepseek-v4-pro

安全注意事项

Diagram of a Chrome extension architecture wiring popup, background script and DeepSeek V4 API.

在您信任任何扩展(包括您自己的)与API密钥之前,值得做的三件事:

  • 永远不要在源代码中硬编码密钥。 上面的扩展通过以下方式存储它 chrome.storage.local,它将密钥保存在本地机器上,而不是代码库中。
  • 限制 host_permissions 仅限于DeepSeek域。像 <all_urls> 这样的通配符过于激进,在任何您安装的第三方扩展中都是红旗。
  • 轮换密钥 如果您发布或共享扩展程序文件夹。DeepSeek控制台允许随时撤销和重新发布。

Next steps

上面的侧面板故意保持最小化。按有用性排序的合理升级:

  1. Streaming. 切换 stream: true 并解析服务器发送的事件以实现逐个token的渲染。 DeepSeek API streaming guide covers the SSE format.
  2. 选择文本捕获。 添加一个内容脚本,读取 window.getSelection() 并预先填充提示框。
  3. Conversation history. 在 messages 中维护一个 chrome.storage.local 数组,以便多轮对话能够正常工作——记住API本身是无状态的。
  4. Context caching. 在每个 messages 数组的开头保持系统提示,这样DeepSeek的自动前缀缓存就可以启动,并且你可以支付缓存命中率。参见 DeepSeek context caching 参考.

如果你想要同一模型的不同表面,该 DeepSeek with VS Code 指南将V4连接到编辑器而不是浏览器,以及更广泛的 DeepSeek tutorials 网络中心目录记录了网站上所有的集成。

DeepSeek AI Guide is an independent resource and is not affiliated with DeepSeek or its parent company. Model IDs, pricing and API behaviour change; check the official DeepSeek documentation and pricing page before committing to a production decision.

是否有官方的DeepSeek Chrome扩展?

不。截至2026年4月,DeepSeek在chat.deepseek.com发布网络聊天、移动应用和API,但不提供第一方浏览器扩展。Chrome Web Store托管接受DeepSeek API密钥的社区构建扩展。在粘贴密钥之前,请验证任何扩展是否为开源、最近更新且使用清单V3。有关经过验证的起点,请参阅 verify official DeepSeek app.

运行DeepSeek Chrome扩展的成本是多少?

扩展代码免费;您只需支付DeepSeek API费用。在 deepseek-v4-flash, 200 prompts a day with modest token sizes 运行大约 $1.35 a month. On deepseek-v4-pro,相同的负载接近13.50美元。在DeepSeek计费控制台中充值少量余额,并观察使用情况。 DeepSeek API pricing 页面上列出了当前的每百万令牌费用。

我能否在扩展中使用遗留的deepseek-chat模型ID?

是的,直到2026-07-24 15:59 UTC。在那之前,直到退休日期, deepseek-chat and deepseek-reasoner 的路由保持不变。该 deepseek-v4-flash 分别在非思考模式和思考模式下。之后,使用旧ID的请求将失败。切换操作只需一行代码。 model= swap; the base_url 参考文档涵盖了迁移过程。 DeepSeek OpenAI SDK compatibility 参考 covers the migration.

Chrome扩展会保留我的对话历史吗?

只有当你构建它时。DeepSeek API是无状态的——服务器不会记住之前的回合,因此客户端必须在每个请求中重新发送完整的数组。chat.deepseek.com的网页聊天在服务器端保留历史记录;除非它本地存储消息,否则扩展不会保留。 messages (总大小284B / 活跃参数13B)以低成本处理常规摘要、翻译和聊天。 DeepSeek browser vs app guide explains this difference.

在浏览器扩展中,V4-Flash和V4-Pro有什么区别?

deepseek-v4-flash (1.6T / 活跃49B)是前沿级模型,用于更困难的编码和推理,输出速率大约是12倍。两者都共享一个1,000,000个token的上下文窗口,并支持思考模式。从Flash开始;只有当Flash失败时才升级到Pro。在详细比较它们。 deepseek-v4-pro (1.6T / 活跃49B)是前沿级模型,用于更困难的编码和推理,输出速率大约是12倍。两者都共享一个1,000,000个token的上下文窗口,并支持思考模式。从Flash开始;只有当Flash失败时才升级到Pro。在详细比较它们。 DeepSeek V4 overview.

Sources & Methodology

Last source check: April 30, 2026

Primary sources

  • OfficialDeepSeek API文档端点、请求/响应形状、模型ID最后检查日期:2026年4月30日
  • 价格DeepSeek API定价页面每百万令牌费率,计费单位,缓存命中定价最后检查日期:2026年4月30日
  • 代码仓库DeepSeek-AI 在 GitHub 上开放权重发布详情,训练/推理说明最后检查日期:2026年4月30日

Technical 参考s

Methodology

Information in this article was checked against the official DeepSeek documentation, the article's cited primary sources, and the deepseekai.guide pricing dataset on the date shown above. Where third-party numbers are quoted, the originating source is linked inline so the reader can verify and re-check.

Data confidence

引用带主要来源链接的事实为高;上下文叙述为中等。

Editorial note

人工智能工具发展迅速。如果您发现过时的数字或损坏的链接,页脚中的联系链接是向编辑团队报告的最快方式。