本页内容
搜索 API(Search API)与抓取 API(Fetch API)为智能体和 RAG 应用提供访问实时网页内容的能力:
- Search API:针对查询检索网页,并返回结构化结果。其背后由 DeepSeek 自研的搜索引擎驱动。
- Fetch API:抓取单个网页,并以 Markdown 返回其内容。
两者都是纯 JSON API,使用与 DeepSeek API 相同的 Bearer 认证。
基础 URL 为 https://api.deepseek.com:
| API | 端点 |
|---|---|
| Search | POST https://api.deepseek.com/v1/tools/search |
| Fetch | POST https://api.deepseek.com/v1/tools/fetch |
完整的请求与响应结构,请参阅 Search API 参考 和 Fetch API 参考。
认证
在请求头中发送你的 API key 和 JSON 内容类型:
| 请求头 | 是否必需 | 值 |
|---|---|---|
Authorization |
是 | Bearer |
Content-Type |
是 | application/json |
Search API
请求
curl https://api.deepseek.com/v1/tools/search \ -H "Authorization: Bearer <DeepSeek API Key>" \ -H "Content-Type: application/json" \ -d '{ "query": "DeepSeek V4 release", "count": 5, "need_content": true }'
import requestsresponse = requests.post( "https://api.deepseek.com/v1/tools/search", headers={ "Authorization": "Bearer <DeepSeek API Key>", }, json={ "query": "DeepSeek V4 release", "count": 5, "need_content": True, },)response.raise_for_status()for result in response.json()["results"]: print(result["title"], result["url"]) print(result["summary"])
请求字段:
| 字段 | 类型 | 是否必需 | 默认值 | 说明 |
|---|---|---|---|---|
query |
string | 是 | - | 搜索查询,必须包含 1 到 128 个 Unicode 字符,不能全为空白字符,并支持下文列出的查询运算符。 |
count |
integer | 否 | 10 |
返回结果数量,取值范围 1 到 50。 |
ori_question |
string | 否 | - | 触发本次搜索的用户原始问题,长度 1 到 128 个字符,用于提升查询理解;null 视为未提供。 |
localization |
string | 否 | "" |
可选 IP 地址,用于本地化搜索结果。 |
need_content |
boolean | 否 | false |
是否在 content 中返回页面内容;为 false 时该字段始终为空字符串。 |
请求体中的未知字段会被忽略。
查询运算符
查询会连同其搜索语法原样转发。下面的示例将运算符与搜索词组合使用;你可以在一个查询中组合多个运算符。
| 运算符 | 示例 | 说明 |
|---|---|---|
site: |
DeepSeek site:github.com |
将结果限制在指定站点;要指定多个站点,用空格分隔多个 site: 子句并用 OR 连接,例如 DeepSeek site:github.com OR site:huggingface.co。 |
-site: |
DeepSeek -site:example.com |
排除指定站点;多个站点用空格分隔。 |
- |
DeepSeek -advertisement |
排除包含该词的页面;多个词用空格分隔。 |
-"..." |
DeepSeek -"release notes" |
排除包含该精确短语的页面;短语可包含空格,多个短语用空格分隔。 |
"..." |
DeepSeek "exact phrase" |
匹配精确短语;多个短语用空格分隔。 |
lang: |
DeepSeek lang:zh,en |
将结果限制在指定语言代码;多个代码用逗号分隔,例如 lang:zh,en。 |
after: |
DeepSeek after:2025 或 DeepSeek after:2025-01-01 |
将结果限制为在某个日期之后发布的页面。 |
before: |
DeepSeek before:2026 或 DeepSeek before:2026-06-01 |
将结果限制为在某个日期之前发布的页面。 |
例如:
{ "query": "DeepSeek site:github.com OR site:huggingface.co lang:en after:2025", "count": 10}
响应
请求成功时返回 HTTP 200 和一个 results 数组。没有匹配结果的正常搜索会返回空数组。
{ "results": [ { "rerank_score": 2.4, "title": "DeepSeek V4 model released", "url": "https://example.com/deepseek-v4", "snippet": "DeepSeek V4 is now available, with tool calling and long-context support.", "summary": "DeepSeek has released the V4 model. The release adds improved tool calling and long-context support for agent workflows.", "content": "DeepSeek V4 is now generally available...", "site_name": "Example News", "site_icon": "https://example.com/favicon.ico", "date": "2026-06-01T00:00:00+00:00", "authority": 3 } ]}
results 中的每一项包含:
| 字段 | 类型 | 说明 |
|---|---|---|
rerank_score |
number | 0 到 3 的相关性评分,综合相关性、权威性与时效性等信号;1.5 及以上视为高质量结果。 |
title |
string | 结果标题。 |
url |
string | 结果 URL。 |
snippet |
string | 与查询相关的简短摘要,通常 100 到 200 个字符,适合在 UI 中展示。 |
summary |
string | 与查询相关的长摘要,通常 600 到 800 个字符,供模型阅读。 |
content |
string | 页面内容;当 need_content 为 false 或内容不可用时为空。 |
site_name |
string 或 null | 站点名称;不可用时为 null。 |
site_icon |
string 或 null | 站点图标 URL;不可用时为 null。 |
date |
string 或 null | UTC 发布时间,格式为 RFC 3339;未知时为 null。 |
authority |
integer | 页面权威等级,0 到 4(-1 表示未知);3 及以上表示高度权威的来源。 |
Fetch API
请求
curl https://api.deepseek.com/v1/tools/fetch \ -H "Authorization: Bearer <DeepSeek API Key>" \ -H "Content-Type: application/json" \ -d '{ "url": "https://example.com/article" }'
import requestsresponse = requests.post( "https://api.deepseek.com/v1/tools/fetch", headers={ "Authorization": "Bearer <DeepSeek API Key>", }, json={"url": "https://example.com/article"},)response.raise_for_status()page = response.json()print(page["title"])print(page["content"])
请求字段:
| 字段 | 类型 | 是否必需 | 说明 |
|---|---|---|---|
url |
string | 是 | 要抓取的页面 URL,最多 8192 个字符,必须是带主机名的 HTTP 或 HTTPS URL,且不得包含用户名或密码。 |
响应
{ "title": "Example article", "content": "# Example article\n\nArticle content."}
| 字段 | 类型 | 说明 |
|---|---|---|
title |
string | 页面标题;标题不可用时为空字符串。 |
content |
string | 抓取到的页面内容,以 Markdown 文本返回。 |
抓取受目标站点的可用性与访问策略约束。
错误
错误采用兼容 OpenAI 的格式。param 字段始终为 null。
{ "error": { "message": "'count' must be between 1 and 50", "type": "invalid_request_error", "param": null, "code": "invalid_request_error" }}
| HTTP 状态码 | 说明 |
|---|---|
| 400 | 请求头或请求体无效,包括 JSON 格式错误或字段值无效。 |
| 401 | API key 缺失或无效。 |
| 402 | 账户余额不足。 |
| 403 | Fetch 请求被安全策略拒绝。 |
| 404 | Fetch 无法获取可用的页面内容,例如 URL 不可用、URL 被站点策略屏蔽、目标站点返回错误、内容类型不受支持,或页面没有可提取的 Markdown 内容。 |
| 408 | 读取请求体超时。 |
| 413 | 请求体过大。 |
| 429 | 超出 Search 或 Fetch 的 QPS 限制。 |
| 500 | 发生内部服务器错误。 |
| 504 | 下游请求超时。 |
Search 与 Fetch 均为只读操作。遇到 HTTP 408、429 或 5xx 错误时,请等待后重试。遇到 HTTP 402 错误时,请先充值账户再重试。对于其他 4xx 错误,在未修改请求前不要重试。
计费
Search 与 Fetch 按成功请求计费,而不是按 token 或返回结果数量计费:
| API | 单位 | 价格 |
|---|---|---|
| Search | 每 1,000 次成功请求 | $0.75 |
| Fetch | 每 1,000 次成功请求 | $0.75 |
只有返回 HTTP 200 且产生结果的请求才会计费(Search 必须返回非空的 results 数组,Fetch 必须返回页面内容)。失败的请求、空搜索结果和超时均不计费。count 只控制返回多少条结果,不影响按请求计费的价格。
注意:当你通过 DeepSeek Harness、Claude Code 或 Codex 使用 DeepSeek API 时,服务端工具调用已经会访问 Search 与 Fetch API。这些调用目前免费;按请求计费将于北京时间 2026 年 11 月 1 日 00:00 开始。











