DeepSeek 上线 Search 与 Fetch API,每千次成功请求 0.75 美元
DeepSeek search and fetch – $0.75 per 1000 successful requests
DeepSeek 推出 Search API 和 Fetch API,为智能体和 RAG 应用提供实时网页内容:Search 基于 DeepSeek 自研搜索引擎返回结构化结果,Fetch 抓取单个网页并以 Markdown 返回内容。
Search 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 |
完整的请求和响应 schema 请参阅 Search API 参考 和 Fetch API 参考。
认证
在请求头中发送你的 API key 和 JSON 内容类型:
| 请求头 | 必填 | 值 |
|---|---|---|
Authorization | 是 | Bearer <DeepSeek API Key> |
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 requests
response = 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 requests
response = 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 | Yes | 要抓取的页面 URL,长度最多为 8192 个字符,必须是带主机名的 HTTP 或 HTTPS URL,且不得包含用户名或密码。 |
Response
{
"title": "Example article",
"content": "# Example article\n\nArticle content."
}
| Field | Type | Description |
|---|---|---|
title | string | 页面标题,标题不可用时为空。 |
content | string | 抓取到的页面内容,以 Markdown 文本形式返回。 |
抓取受目标站点的可用性和访问策略约束。
Errors
错误遵循 OpenAI 兼容的错误格式。param 字段始终为 null。
{
"error": {
"message": "'count' must be between 1 and 50",
"type": "invalid_request_error",
"param": null,
"code": "invalid_request_error"
}
}
| HTTP Status | Description |
|---|---|
| 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 错误在未修改请求的情况下请勿重试。
Billing
Search 和 Fetch 按成功请求计费,不按 token 或返回结果数量计费:
| API | Unit | Price |
|---|---|---|
| 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 开始。
Rate Limits
对于每个账户,Search 和 Fetch 分别独立限流,访问其中一个不会消耗另一个的配额:
| API | QPS Limit |
|---|---|
| Search | 5 |
| Fetch | 5 |
QPS(每秒请求数)限制按账户级别计算,与使用哪个 API key 无关,并且与模型并发限制相互独立。超过账户级 QPS 限制的请求会收到 HTTP 429。除账户级限制外,Fetch 还受每个域名的 QPS 限制约束,超过该限制的请求同样会收到 HTTP 429。
来源:Hacker News · api-docs.deepseek.com