brave-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBrave Search API
Brave Search API
Overview
概述
Search the web, images, and news using Brave's privacy-focused Search API. Also supports AI Grounding for cited answers via OpenAI SDK compatibility.
借助Brave注重隐私的Search API搜索网页、图片和新闻。还支持通过OpenAI SDK兼容性实现带引用答案的AI Grounding功能。
Prerequisites
前提条件
API Key required. Get one at https://api-dashboard.search.brave.com
bash
export BRAVE_API_KEY="your-api-key"Free tier: 2,000 queries/month. Pro plans unlock Local POI search and AI Grounding.
需要API密钥。请前往https://api-dashboard.search.brave.com获取。
bash
export BRAVE_API_KEY="your-api-key"免费层级:每月2000次查询。专业版计划解锁本地POI搜索和AI Grounding功能。
When to Use
使用场景
- Searching the web for current information
- Finding images on a topic
- Getting recent news articles
- AI-grounded answers with citations
- Autocomplete suggestions
- Location/POI searches (Pro plan)
- 搜索网页获取当前信息
- 查找特定主题的图片
- 获取近期新闻文章
- 带引用的AI锚定答案
- 自动补全建议
- 地点/POI搜索(专业版计划)
High-Throughput Usage
高吞吐量使用方式
Go wide, go fast. This API supports high concurrency—up to 50 requests/second. Don't hold back:
- Fire searches in parallel. Need to research 10 different topics? Launch 10 searches simultaneously. Use multiple Bash tool calls in a single message.
- Use subagents for heavy results. When expecting lots of context (many results, extra snippets, research mode), dispatch a subagent to run the search and synthesize findings. This preserves your main context window.
- Batch related queries. Searching for competitors, alternatives, or multiple aspects of a topic? Run them all at once.
dot
digraph parallel_search {
rankdir=LR;
node [shape=box];
task [label="Research task"];
q1 [label="Query 1"];
q2 [label="Query 2"];
q3 [label="Query 3"];
subagent [label="Subagent\n(preserves context)"];
synthesize [label="Synthesized\nfindings"];
task -> q1;
task -> q2;
task -> q3;
q1 -> subagent [style=dashed];
q2 -> subagent [style=dashed];
q3 -> subagent [style=dashed];
subagent -> synthesize;
}When to use subagents:
- Searching for many sources on a topic (launch search subagent, return summary)
- Deep research with AI Grounding (high token usage, let subagent handle)
- Comparing multiple options (run parallel searches, subagent synthesizes)
When to search directly:
- Quick single queries where you need the raw URLs/snippets
- Low result counts where context isn't a concern
广泛、快速调用。该API支持高并发——最高每秒50次请求。无需受限:
- 并行发起搜索。需要研究10个不同主题?同时发起10次搜索。在单条消息中使用多个Bash工具调用。
- 使用子Agent处理大量结果。当预期会有大量上下文(多结果、额外片段、研究模式)时,分派一个子Agent来运行搜索并整合结果。这样可以保留主上下文窗口。
- 批量处理相关查询。搜索竞品、替代方案或某个主题的多个方面?一次性全部运行。
dot
digraph parallel_search {
rankdir=LR;
node [shape=box];
task [label="Research task"];
q1 [label="Query 1"];
q2 [label="Query 2"];
q3 [label="Query 3"];
subagent [label="Subagent\n(preserves context)"];
synthesize [label="Synthesized\nfindings"];
task -> q1;
task -> q2;
task -> q3;
q1 -> subagent [style=dashed];
q2 -> subagent [style=dashed];
q3 -> subagent [style=dashed];
subagent -> synthesize;
}何时使用子Agent:
- 搜索某个主题的多个来源(启动搜索子Agent,返回摘要)
- 结合AI Grounding的深度研究(高token消耗,交由子Agent处理)
- 比较多个选项(运行并行搜索,子Agent整合结果)
何时直接搜索:
- 需要原始URL/片段的快速单次查询
- 结果数量少,无需担心上下文的场景
Quick Reference
快速参考
| Task | Command |
|---|---|
| Web search | |
| Image search | |
| News search | |
| AI answer | |
| Suggestions | |
| Check key | |
| 任务 | 命令 |
|---|---|
| 网页搜索 | |
| 图片搜索 | |
| 新闻搜索 | |
| AI答案 | |
| 建议 | |
| 检查密钥 | |
API Endpoints
API端点
| API | Endpoint | Plan |
|---|---|---|
| Web Search | | Free |
| Image Search | | Free |
| News Search | | Free |
| Suggest | | Free |
| AI Grounding | | AI Grounding |
| Local POI | | Pro |
| Summarizer | | Pro |
| API | 端点 | 计划 |
|---|---|---|
| 网页搜索 | | 免费 |
| 图片搜索 | | 免费 |
| 新闻搜索 | | 免费 |
| 建议 | | 免费 |
| AI Grounding | | AI Grounding |
| 本地POI | | 专业版 |
| 摘要工具 | | 专业版 |
Common Parameters
通用参数
Web Search
网页搜索
bash
undefinedbash
undefinedBasic search
基础搜索
brave-search web "python async tutorial" --count 10
brave-search web "python async tutorial" --count 10
Filter by freshness (pd=24h, pw=7d, pm=31d, py=365d)
按时效性过滤(pd=24小时,pw=7天,pm=31天,py=365天)
brave-search web "latest news" --freshness pd
brave-search web "latest news" --freshness pd
Filter by country and language
按国家和语言过滤
brave-search web "local restaurants" --country US --lang en
brave-search web "local restaurants" --country US --lang en
Safe search (off, moderate, strict)
安全搜索(关闭、中等、严格)
brave-search web "query" --safesearch strict
brave-search web "query" --safesearch strict
Get extra snippets
获取额外片段
brave-search web "query" --extra-snippets
brave-search web "query" --extra-snippets
Filter result types (web, news, videos, images, discussions)
过滤结果类型(网页、新闻、视频、图片、讨论)
brave-search web "query" --filter web,news
undefinedbrave-search web "query" --filter web,news
undefinedImage Search
图片搜索
bash
undefinedbash
undefinedBasic image search
基础图片搜索
brave-search images "mountain sunset"
brave-search images "mountain sunset"
With safe search
开启安全搜索
brave-search images "landscape" --safesearch strict --count 20
undefinedbrave-search images "landscape" --safesearch strict --count 20
undefinedNews Search
新闻搜索
bash
undefinedbash
undefinedRecent news
近期新闻
brave-search news "AI developments" --count 10
brave-search news "AI developments" --count 10
News with freshness filter
带时效性过滤的新闻
brave-search news "election results" --freshness pd
undefinedbrave-search news "election results" --freshness pd
undefinedAI Grounding (Cited Answers)
AI Grounding(带引用的答案)
bash
undefinedbash
undefinedGet an AI answer with citations
获取带引用的AI答案
brave-search ai "What is the tallest building in the world?"
brave-search ai "What is the tallest building in the world?"
Enable deep research (multiple searches, slower)
开启深度研究(多次搜索,速度较慢)
brave-search ai "Compare React and Vue in 2024" --research
undefinedbrave-search ai "Compare React and Vue in 2024" --research
undefinedWorkflow
工作流
dot
digraph brave_search {
rankdir=TB;
node [shape=box];
need [label="What do you need?" shape=diamond];
web [label="Web Search\nbrave.py web"];
images [label="Image Search\nbrave.py images"];
news [label="News Search\nbrave.py news"];
ai [label="AI Answer\nbrave.py ai"];
results [label="Parse JSON results"];
cite [label="Include citations\nfor AI answers"];
need -> web [label="web pages"];
need -> images [label="images"];
need -> news [label="recent news"];
need -> ai [label="cited answer"];
web -> results;
images -> results;
news -> results;
ai -> cite;
}dot
digraph brave_search {
rankdir=TB;
node [shape=box];
need [label="What do you need?" shape=diamond];
web [label="Web Search\nbrave.py web"];
images [label="Image Search\nbrave.py images"];
news [label="News Search\nbrave.py news"];
ai [label="AI Answer\nbrave.py ai"];
results [label="Parse JSON results"];
cite [label="Include citations\nfor AI answers"];
need -> web [label="web pages"];
need -> images [label="images"];
need -> news [label="recent news"];
need -> ai [label="cited answer"];
web -> results;
images -> results;
news -> results;
ai -> cite;
}Response Structure
响应结构
Web Search Results
网页搜索结果
json
{
"web": {
"results": [
{
"title": "Page Title",
"url": "https://example.com",
"description": "Snippet from the page...",
"extra_snippets": ["Additional context..."]
}
]
},
"query": {
"original": "search query",
"altered": "modified query if spellchecked"
}
}json
{
"web": {
"results": [
{
"title": "Page Title",
"url": "https://example.com",
"description": "Snippet from the page...",
"extra_snippets": ["Additional context..."]
}
]
},
"query": {
"original": "search query",
"altered": "modified query if spellchecked"
}
}AI Grounding Response
AI Grounding响应
Returns OpenAI-compatible format with inline citations:
The tallest building is the Burj Khalifa[1] at 828 meters...
[1] https://source-url.com返回兼容OpenAI的格式,包含内联引用:
The tallest building is the Burj Khalifa[1] at 828 meters...
[1] https://source-url.comCommon Options
通用选项
| Option | Values | Description |
|---|---|---|
| 1-20 (web), 1-200 (images) | Number of results |
| US, GB, DE, FR, etc. | Search region |
| en, de, fr, es, etc. | Search language |
| off, moderate, strict | Adult content filter |
| pd, pw, pm, py | Time filter |
| flag | Output raw JSON |
| 选项 | 取值 | 描述 |
|---|---|---|
| 1-20(网页),1-200(图片) | 结果数量 |
| US, GB, DE, FR等 | 搜索区域 |
| en, de, fr, es等 | 搜索语言 |
| off, moderate, strict | 成人内容过滤 |
| pd, pw, pm, py | 时间过滤 |
| 标志位 | 输出原始JSON |
Error Handling
错误处理
| Error | Cause | Fix |
|---|---|---|
| 401 Unauthorized | Invalid/missing API key | Check |
| 429 Rate Limited | Too many requests | Wait or upgrade plan |
| 422 Validation | Invalid parameters | Check parameter values |
| 错误 | 原因 | 修复方案 |
|---|---|---|
| 401 Unauthorized | API密钥无效/缺失 | 检查 |
| 429 Rate Limited | 请求过多 | 等待或升级计划 |
| 422 Validation | 参数无效 | 检查参数取值 |
Rate Limits
速率限制
- Free: 1 req/sec, 2,000/month
- Pro: Higher limits, check dashboard
- Response headers show remaining quota:
X-RateLimit-Remaining
- 免费版:每秒1次请求,每月2000次
- 专业版:更高限制,请查看控制台
- 响应头显示剩余配额:
X-RateLimit-Remaining
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| API key not set | |
| Wrong endpoint for plan | Check subscription at dashboard |
| Too many results | Web max is 20, use offset for pagination |
| No AI grounding | Requires AI Grounding subscription |
| 错误 | 修复方案 |
|---|---|
| 未设置API密钥 | |
| 计划不支持的端点 | 在控制台检查订阅情况 |
| 结果数量过多 | 网页搜索最多20条,使用offset进行分页 |
| 无AI Grounding功能 | 需要订阅AI Grounding服务 |