web-search
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseWeb Search
网页搜索
Requires API Key: Get one at https://api.search.brave.comPlan: Included in the Search plan. See https://api-dashboard.search.brave.com/app/subscriptions/subscribe
需要API Key:可在https://api.search.brave.com获取套餐:包含在Search套餐中。详情见https://api-dashboard.search.brave.com/app/subscriptions/subscribe
Quick Start (cURL)
快速开始(cURL)
Basic Search
基础搜索
bash
curl -s "https://api.search.brave.com/res/v1/web/search?q=python+web+frameworks" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"bash
curl -s "https://api.search.brave.com/res/v1/web/search?q=python+web+frameworks" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"With Parameters
带参数搜索
bash
curl -s "https://api.search.brave.com/res/v1/web/search" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-G \
--data-urlencode "q=rust programming tutorials" \
--data-urlencode "country=US" \
--data-urlencode "search_lang=en" \
--data-urlencode "count=10" \
--data-urlencode "safesearch=moderate" \
--data-urlencode "freshness=pm"bash
curl -s "https://api.search.brave.com/res/v1/web/search" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-G \
--data-urlencode "q=rust programming tutorials" \
--data-urlencode "country=US" \
--data-urlencode "search_lang=en" \
--data-urlencode "count=10" \
--data-urlencode "safesearch=moderate" \
--data-urlencode "freshness=pm"Endpoint
端点
http
GET https://api.search.brave.com/res/v1/web/search
POST https://api.search.brave.com/res/v1/web/searchNote: Both GET and POST methods are supported. POST is useful for long queries or complex Goggles.
Authentication: header
X-Subscription-Token: <API_KEY>Optional Headers:
- — Enable gzip compression
Accept-Encoding: gzip
http
GET https://api.search.brave.com/res/v1/web/search
POST https://api.search.brave.com/res/v1/web/search注意:同时支持GET和POST方法。POST适用于长查询或复杂的Goggles配置。
身份验证: 请求头
X-Subscription-Token: <API_KEY>可选请求头:
- — 启用gzip压缩
Accept-Encoding: gzip
When to Use Web Search
何时使用网页搜索
| Feature | Web Search (this) | LLM Context ( | Answers ( |
|---|---|---|---|
| Output | Structured results (links, snippets, metadata) | Pre-extracted page content for LLMs | End-to-end AI answers with citations |
| Result types | Web, news, videos, discussions, FAQ, infobox, locations, rich | Extracted text chunks, tables, code | Synthesized answer + source list |
| Unique features | Goggles, structured data ( | Token budget control, threshold modes | Multi-iteration search, streaming, OpenAI SDK compatible |
| Speed | Fast (~0.5-1s) | Fast (<1s) | Slower (~30-180s) |
| Best for | Search UIs, data extraction, custom ranking | RAG pipelines, AI agents, grounding | Chat interfaces, thorough research |
| 特性 | 网页搜索(本端点) | LLM上下文( | 问答( |
|---|---|---|---|
| 输出 | 结构化结果(链接、摘要、元数据) | 为LLM预提取的页面内容 | 带引用的端到端AI问答结果 |
| 结果类型 | 网页、新闻、视频、讨论、FAQ、信息框、地点、富媒体 | 提取的文本片段、表格、代码 | 合成答案+来源列表 |
| 独有特性 | Goggles、结构化数据( | Token预算控制、阈值模式 | 多轮搜索、流式传输、兼容OpenAI SDK |
| 速度 | 快(约0.5-1秒) | 快(<1秒) | 较慢(约30-180秒) |
| 最佳适用场景 | 搜索UI、数据提取、自定义排序 | RAG流水线、AI Agent、事实校验 | 聊天界面、深度研究 |
Parameters
参数
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| string | Yes | - | Search query (1-400 chars, max 50 words) |
| string | No | | Search country (2-letter country code or |
| string | No | | Language preference (2+ char language code) |
| string | No | | UI language (e.g., "en-US") |
| int | No | | Max results per page (1-20) |
| int | No | | Page offset for pagination (0-9) |
| string | No | | Adult content filter ( |
| string | No | - | Time filter ( |
| bool | No | | Include highlight markers |
| bool | No | | Auto-correct query |
| string | No | - | Filter result types (comma-separated) |
| string | No | - | Custom ranking filter (URL or inline) |
| bool | No | - | Get up to 5 extra snippets per result |
| bool | No | | Apply search operators |
| string | No | - | Measurement units ( |
| bool | No | | Enable rich 3rd party data callback |
| bool | No | | Include |
| 参数 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| 字符串 | 是 | - | 搜索查询(1-400字符,最多50个单词) |
| 字符串 | 否 | | 搜索国家(两位国家代码或 |
| 字符串 | 否 | | 语言偏好(2+字符语言代码) |
| 字符串 | 否 | | UI语言(例如"en-US") |
| 整数 | 否 | | 每页最大结果数(1-20) |
| 整数 | 否 | | 分页偏移量(0-9) |
| 字符串 | 否 | | 成人内容过滤( |
| 字符串 | 否 | - | 时效性筛选( |
| 布尔值 | 否 | | 包含高亮标记 |
| 布尔值 | 否 | | 自动纠正查询 |
| 字符串 | 否 | - | 结果类型筛选(逗号分隔) |
| 字符串 | 否 | - | 自定义排序筛选器(URL或内联规则) |
| 布尔值 | 否 | - | 每个结果最多获取5个额外摘要 |
| 布尔值 | 否 | | 应用搜索运算符 |
| 字符串 | 否 | - | 测量单位( |
| 布尔值 | - | | 启用第三方富媒体数据回调 |
| 布尔值 | 否 | | 在结果中包含 |
Freshness Values
时效性筛选值
| Value | Description |
|---|---|
| Past day (24 hours) |
| Past week (7 days) |
| Past month (31 days) |
| Past year (365 days) |
| Custom date range |
| 值 | 描述 |
|---|---|
| 过去一天(24小时) |
| 过去一周(7天) |
| 过去一个月(31天) |
| 过去一年(365天) |
| 自定义日期范围 |
Result Filter Values
结果筛选值
Filter types: , , , , , , ,
discussionsfaqinfoboxnewsqueryvideosweblocationsbash
undefined可筛选类型:(讨论)、(常见问题)、(信息框)、(新闻)、(查询)、(视频)、(网页)、(地点)
discussionsfaqinfoboxnewsqueryvideosweblocationsbash
undefinedOnly web and video results
仅返回网页和视频结果
curl "...&result_filter=web,videos"
undefinedcurl "...&result_filter=web,videos"
undefinedLocation Headers (Optional)
位置请求头(可选)
For location-aware results, add these headers. Lat/Long is sufficient when coordinates are known — the other headers are only needed as a fallback when coordinates are unavailable.
| Header | Type | Description |
|---|---|---|
| float | User latitude (-90.0 to 90.0) |
| float | User longitude (-180.0 to 180.0) |
| string | IANA timezone (e.g., "America/San_Francisco") |
| string | City name |
| string | State/region code (ISO 3166-2) |
| string | State/region full name (e.g., "California") |
| string | 2-letter country code |
| string | Postal code (e.g., "94105") |
Priority:+X-Loc-Lattake precedence. When provided, downstream services resolve the location directly from coordinates and the text-based headers (City, State, Country, Postal-Code) are not used for location resolution. Provide text-based headers only when you don't have coordinates. Sending both won't break anything — lat/long simply wins.X-Loc-Long
如需基于位置的结果,可添加以下请求头。当已知坐标时,仅需提供Lat/Long即可——其他请求头仅在无法获取坐标时作为备选。
| 请求头 | 类型 | 描述 |
|---|---|---|
| 浮点数 | 用户纬度(-90.0至90.0) |
| 浮点数 | 用户经度(-180.0至180.0) |
| 字符串 | IANA时区(例如"America/San_Francisco") |
| 字符串 | 城市名称 |
| 字符串 | 州/地区代码(ISO 3166-2) |
| 字符串 | 州/地区全名(例如"California") |
| 字符串 | 两位国家代码 |
| 字符串 | 邮政编码(例如"94105") |
优先级:+X-Loc-Lat优先级最高。当提供这两个参数时,下游服务会直接通过坐标解析位置,而文本类请求头(城市、州、国家、邮政编码)不会被用于位置解析。仅在没有坐标时才提供文本类请求头。同时提供两者不会导致错误——坐标会优先生效。X-Loc-Long
Response Format
响应格式
Response Fields
响应字段
| Field | Type | Description |
|---|---|---|
| string | Always |
| string | The original search query |
| string? | Spellcheck-corrected query (if changed) |
| string? | Cleaned/normalized query |
| bool? | Whether spellcheck was disabled |
| bool | Whether more pages exist |
| bool? | True if strict safesearch blocked adult results |
| object? | Applied search operators ( |
| string | Always |
| string | Page title |
| string | Page URL |
| string? | Snippet/description text |
| string? | Human-readable age (e.g., "2 days ago") |
| string? | Content language code |
| object | URL components ( |
| object? | Thumbnail ( |
| string? | Original full-size image URL |
| bool? | Whether the thumbnail is a logo |
| object? | Publisher identity ( |
| string? | ISO datetime of publication (e.g., |
| list[str]? | Up to 5 additional excerpts |
| object? | Additional links ( |
| list? | Raw schema.org structured data |
| object? | Product info and reviews |
| object? | Recipe details (ingredients, time, ratings) |
| object? | Article metadata (author, publisher, date) |
| object? | Book info (author, ISBN, rating) |
| object? | Software product info |
| object? | Aggregate ratings |
| object? | FAQ found on the page |
| object? | Movie info (directors, actors, genre) |
| object? | Video metadata (duration, views, creator) |
| object? | Location/restaurant details |
| object? | Question/answer info |
| object? | Creative work data |
| object? | Music/song data |
| object? | Organization info |
| object? | Review data |
| string? | Content type classification |
| int? | Fetch timestamp (with |
| bool | Whether results were re-ranked by Goggles |
| bool | Whether results are family-friendly |
| object? | Preferred display order (see Mixed Response below) |
| array? | Forum discussion clusters |
| string? | Forum/community name |
| int? | Number of answers/replies |
| string? | Discussion question |
| string? | Top-voted comment excerpt |
| array? | FAQ entries |
| array? | News articles |
| array? | Video results |
| array? | Knowledge graph entries |
| array? | Local POI results |
| string? | Rich result type |
| string? | Callback key for rich data |
| 字段 | 类型 | 描述 |
|---|---|---|
| 字符串 | 始终为 |
| 字符串 | 原始搜索查询 |
| 字符串(可选) | 拼写纠正后的查询(如果有修改) |
| 字符串(可选) | 清理/标准化后的查询 |
| - | 是否禁用了拼写检查 |
| 布尔值 | 是否存在更多分页结果 |
| 布尔值(可选) | 当严格模式SafeSearch拦截了成人内容时为true |
| 对象(可选) | 已应用的搜索运算符( |
| 字符串 | 始终为 |
| 字符串 | 页面标题 |
| 字符串 | 页面URL |
| 字符串(可选) | 摘要/描述文本 |
| 字符串(可选) | 易读的时间标识(例如"2天前") |
| 字符串(可选) | 内容语言代码 |
| 对象 | URL组件( |
| 对象(可选) | 缩略图( |
| 字符串(可选) | 原始全尺寸图片URL |
| 布尔值(可选) | 缩略图是否为Logo |
| 对象(可选) | 发布者身份( |
| 字符串(可选) | 发布时间的ISO格式(例如 |
| 字符串列表(可选) | 最多5个额外摘要片段 |
| 对象(可选) | 页面中的额外链接( |
| 列表(可选) | 原始schema.org结构化数据 |
| 对象(可选) | 产品信息和评论 |
| 对象(可选) | 食谱详情(食材、时间、评分) |
| 对象(可选) | 文章元数据(作者、发布者、日期) |
| 对象(可选) | 书籍信息(作者、ISBN、评分) |
| 对象(可选) | 软件产品信息 |
| 对象(可选) | 综合评分 |
| 对象(可选) | 页面中的FAQ内容 |
| 对象(可选) | 电影信息(导演、演员、类型) |
| 对象(可选) | 视频元数据(时长、播放量、创作者) |
| 对象(可选) | 地点/餐厅详情 |
| 对象(可选) | 问答信息 |
| 对象(可选) | 创意作品数据 |
| 对象(可选) | 音乐/歌曲数据 |
| 对象(可选) | 组织信息 |
| 对象(可选) | 评论数据 |
| 字符串(可选) | 内容类型分类 |
| 整数(可选) | 抓取时间戳(当 |
| 布尔值 | 结果是否被Goggles重新排序 |
| 布尔值 | 结果是否适合家庭观看 |
| 对象(可选) | 推荐的展示顺序(见下方混合响应说明) |
| 数组(可选) | 论坛讨论集群 |
| 字符串(可选) | 论坛/社区名称 |
| 整数(可选) | 回答/回复数量 |
| 字符串(可选) | 讨论问题 |
| 字符串(可选) | 获赞最高的评论摘要 |
| 数组(可选) | FAQ条目 |
| 数组(可选) | 新闻文章 |
| 数组(可选) | 视频结果 |
| 数组(可选) | 知识图谱条目 |
| 数组(可选) | 本地POI结果 |
| 字符串(可选) | 富媒体结果类型 |
| 字符串(可选) | 富媒体数据的回调密钥 |
JSON Example
JSON示例
json
{
"type": "search",
"query": {
"original": "python frameworks",
"altered": "python web frameworks",
"spellcheck_off": false,
"more_results_available": true
},
"web": {
"type": "search",
"results": [
{
"title": "Top Python Web Frameworks",
"url": "https://example.com/python-frameworks",
"description": "A comprehensive guide to Python web frameworks...",
"age": "2 days ago",
"language": "en",
"meta_url": {
"scheme": "https",
"netloc": "example.com",
"hostname": "example.com",
"path": "/python-frameworks"
},
"thumbnail": {
"src": "https://...",
"original": "https://original-image-url.com/img.jpg"
},
"extra_snippets": ["Additional excerpt 1...", "Additional excerpt 2..."]
}
],
"family_friendly": true
},
"mixed": {
"type": "mixed",
"main": [
{"type": "web", "index": 0, "all": false},
{"type": "web", "index": 1, "all": false},
{"type": "videos", "all": true}
],
"top": [],
"side": []
},
"videos": { "...": "..." },
"news": { "...": "..." },
"rich": {
"type": "rich",
"hint": {
"vertical": "weather",
"callback_key": "<callback_key_hex>"
}
}
}json
{
"type": "search",
"query": {
"original": "python frameworks",
"altered": "python web frameworks",
"spellcheck_off": false,
"more_results_available": true
},
"web": {
"type": "search",
"results": [
{
"title": "Top Python Web Frameworks",
"url": "https://example.com/python-frameworks",
"description": "A comprehensive guide to Python web frameworks...",
"age": "2 days ago",
"language": "en",
"meta_url": {
"scheme": "https",
"netloc": "example.com",
"hostname": "example.com",
"path": "/python-frameworks"
},
"thumbnail": {
"src": "https://...",
"original": "https://original-image-url.com/img.jpg"
},
"extra_snippets": ["Additional excerpt 1...", "Additional excerpt 2..."]
}
],
"family_friendly": true
},
"mixed": {
"type": "mixed",
"main": [
{"type": "web", "index": 0, "all": false},
{"type": "web", "index": 1, "all": false},
{"type": "videos", "all": true}
],
"top": [],
"side": []
},
"videos": { "...": "..." },
"news": { "...": "..." },
"rich": {
"type": "rich",
"hint": {
"vertical": "weather",
"callback_key": "<callback_key_hex>"
}
}
}Mixed Response
混合响应
The object defines the preferred display order of results across types. It contains three arrays:
mixed| Array | Purpose |
|---|---|
| Primary result list (ordered sequence of results to display) |
| Results to display above main results |
| Results to display alongside main results (e.g., infobox) |
Each entry is a with (e.g., , ), (into the corresponding result array), and ( to include all results of that type at this position).
ResultReferencetype"web""videos"indexalltruemixed| 数组 | 用途 |
|---|---|
| 主要结果列表(按顺序展示的结果序列) |
| 展示在主要结果上方的结果 |
| 展示在主要结果旁边的结果(例如信息框) |
每个条目是一个对象,包含(例如、)、(对应结果数组的索引)和(表示在此位置包含该类型的所有结果)。
ResultReferencetype"web""videos"indexalltrueSearch Operators
搜索运算符
| Operator | Syntax | Description |
|---|---|---|
| Site | | Limit results to a specific domain |
| File extension | | Results with a specific file extension |
| File type | | Results created in a specific file type |
| In title | | Pages with term in the title |
| In body | | Pages with term in the body |
| In page | | Pages with term in title or body |
| Language | | Pages in a specific language (ISO 639-1) |
| Location | | Pages from a specific country (ISO 3166-1 alpha-2) |
| Include | | Force inclusion of a term |
| Exclude | | Exclude pages containing the term |
| Exact match | | Match the exact phrase in order |
| AND | | Both terms required (uppercase) |
| OR / NOT | | Logical operators (uppercase) |
Set to disable operator parsing.
operators=false| 运算符 | 语法 | 描述 |
|---|---|---|
| 站点限定 | | 将结果限制在特定域名 |
| 文件扩展名 | | 包含特定文件扩展名的结果 |
| 文件类型 | | 特定文件类型创建的结果 |
| 标题包含 | | 标题中包含指定术语的页面 |
| 正文包含 | | 正文中包含指定术语的页面 |
| 页面包含 | | 标题或正文中包含指定术语的页面 |
| 语言限定 | | 特定语言的页面(ISO 639-1代码) |
| 位置限定 | | 特定国家的页面(ISO 3166-1 alpha-2代码) |
| 强制包含 | | 强制包含某个术语 |
| 排除 | | 排除包含某个术语的页面 |
| 精确匹配 | | 精确匹配短语顺序 |
| 逻辑与 | | 必须同时包含两个术语(大写AND) |
| 逻辑或/非 | | 逻辑运算符(大写) |
设置可禁用运算符解析。
operators=falseGoggles (Custom Ranking) — Unique to Brave
Goggles(自定义排序)——Brave独有
Goggles let you re-rank search results — boost trusted sources, suppress SEO spam, or build focused search scopes.
| Method | Example |
|---|---|
| Hosted | |
| Inline | |
Hosted goggles must be on GitHub/GitLab, include,! name:,! description:headers, and be registered at https://search.brave.com/goggles/create. Inline rules need no registration.! author:
Syntax: / (1–10), , . Combine with commas: . Separate rules with ().
$boost=N$downrank=N$discard$site=example.com$site=example.com,boost=3\n%0AAllow list: — Block list:
$discard\n$site=docs.python.org\n$site=developer.mozilla.org$discard,site=pinterest.com\n$discard,site=quora.comGoggles允许你重新排序搜索结果——提升可信来源权重、抑制SEO垃圾信息,或构建聚焦的搜索范围。
| 方式 | 示例 |
|---|---|
| 托管式 | |
| 内联式 | |
托管式Goggles必须托管在GitHub/GitLab,包含、! name:、! description:头信息,并在https://search.brave.com/goggles/create注册。**内联式**规则无需注册。! author:
语法: / (1–10)、、。可通过逗号组合:。规则之间用()分隔。
$boost=N$downrank=N$discard$site=example.com$site=example.com,boost=3\n%0A允许列表: — 阻止列表:
$discard\n$site=docs.python.org\n$site=developer.mozilla.org$discard,site=pinterest.com\n$discard,site=quora.comRich Data Enrichments
富媒体数据增强
For queries about weather, stocks, sports, currency, etc., use the rich callback workflow:
bash
undefined对于天气、股票、体育、货币等查询,可使用富媒体回调流程:
bash
undefined1. Search with rich callback enabled
1. 启用富媒体回调进行搜索
curl -s "https://api.search.brave.com/res/v1/web/search?q=weather+san+francisco&enable_rich_callback=true"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
curl -s "https://api.search.brave.com/res/v1/web/search?q=weather+san+francisco&enable_rich_callback=true"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
Response includes: "rich": {"hint": {"callback_key": "abc123...", "vertical": "weather"}}
响应将包含:"rich": {"hint": {"callback_key": "abc123...", "vertical": "weather"}}
2. Get rich data with the callback key
2. 使用回调密钥获取富媒体数据
curl -s "https://api.search.brave.com/res/v1/web/rich?callback_key=abc123..."
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
**Supported Rich Types**: Calculator, Definitions, Unit Conversion, Unix Timestamp, Package Tracker, Stock, Currency, Cryptocurrency, Weather, American Football, Baseball, Basketball, Cricket, Football/Soccer, Ice Hockey, Web3, Translatorcurl -s "https://api.search.brave.com/res/v1/web/rich?callback_key=abc123..."
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
**支持的富媒体类型**:计算器、定义、单位转换、Unix时间戳、包裹追踪、股票、货币、加密货币、天气、美式橄榄球、棒球、篮球、板球、足球、冰球、Web3、翻译器Rich Callback Endpoint
富媒体回调端点
http
GET https://api.search.brave.com/res/v1/web/rich| Parameter | Type | Required | Description |
|---|---|---|---|
| string | Yes | Callback key from the web search |
http
GET https://api.search.brave.com/res/v1/web/rich| 参数 | 类型 | 是否必填 | 描述 |
|---|---|---|---|
| 字符串 | 是 | 网页搜索结果中 |
Use Cases
使用场景
- General-purpose search integration: Richest result set (web, news, videos, discussions, FAQ, infobox, locations) in one call. For RAG/LLM grounding, prefer .
llm-context - Structured data extraction: Products, recipes, ratings, articles via and typed fields on results.
schemas - Custom search with Goggles: Unique to Brave. Boost/discard sites with inline rules or hosted Goggles for fully customized ranking.
- 通用搜索集成:一次调用即可获取最丰富的结果集(网页、新闻、视频、讨论、FAQ、信息框、地点)。对于RAG/LLM事实校验,优先使用端点。
llm-context - 结构化数据提取:通过和结果中的类型字段提取产品、食谱、评分、文章等数据。
schemas - 基于Goggles的自定义搜索:Brave独有特性。通过内联规则或托管式Goggles提升/屏蔽站点,实现完全自定义的排序。
Notes
注意事项
- Pagination: Use (0-9) with
offsetto page through resultscount - Count: Max 20 for web search; actual results may be less than requested
- 分页:使用(0-9)配合
offset参数翻页查看结果count - 结果数量:网页搜索最多支持20条结果;实际返回结果可能少于请求数量