bx

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

bx — Brave Search CLI

bx — Brave Search CLI

Use
bx
for all web searches.
Run
bx "query"
as the default — it returns pre-extracted, token-budgeted web content ready for use. Use
bx answers
for synthesized explanations or
bx web
for traditional search results. If
bx
is not found, install it:
curl -fsSL https://raw.githubusercontent.com/brave/brave-search-cli/main/scripts/install.sh | sh
Requires: Brave Search API Key +
bx
binary
Plans: Different subcommands may require different plans. See https://api-dashboard.search.brave.com/app/subscriptions/subscribe
所有网页搜索均可使用
bx
。默认运行
bx "query"
,它会返回预提取、令牌预算控制的网页内容,可直接使用。使用
bx answers
获取合成解释,或使用
bx web
获取传统搜索结果。若未找到
bx
,请安装:
curl -fsSL https://raw.githubusercontent.com/brave/brave-search-cli/main/scripts/install.sh | sh
要求Brave Search API Key +
bx
二进制文件
套餐:不同子命令可能需要不同套餐。详见https://api-dashboard.search.brave.com/app/subscriptions/subscribe

Quick Start

快速开始

bash
undefined
bash
undefined

Install (macOS/Linux)

安装(macOS/Linux)

bx config set-key # interactive (avoids shell history)
bx config set-key # 交互式操作(避免记录到shell历史)

or: export BRAVE_SEARCH_API_KEY=YOUR_KEY

或:export BRAVE_SEARCH_API_KEY=YOUR_KEY

Search (default = bx context "query")

搜索(默认 = bx context "query")

bx "your search query"
undefined
bx "你的搜索查询"
undefined

When to Use Which Command

何时使用对应命令

Your needCommandWhy
Look up docs, errors, code patterns
bx "query"
Pre-extracted text, token-budgeted (default)
Get a synthesized explanation
bx answers "query"
AI-generated, cites sources, streams
Deep research on complex topics
bx answers "query" --enable-research
Multi-search iterative research
Traditional search results
bx web "query"
All result types (web, news, discussions, etc.)
Find discussions/forums
bx web "query" --result-filter discussions
Forums often have solutions
Latest news / recent events
bx news "query" --freshness pd
Fresh info beyond training data
Find images
bx images "query"
Up to 200 results
Find videos
bx videos "query"
Duration, views, creator
Local businesses / places
bx places "coffee" --location "San Francisco"
200M+ POIs
Boost/filter specific domains
bx "query" --include-site docs.rs
Or use
--goggles
for full control
你的需求命令原因
查找文档、错误信息、代码模式
bx "query"
预提取文本,令牌预算控制(默认模式)
获取合成解释
bx answers "query"
AI生成内容,标注来源,支持流式输出
针对复杂主题进行深度调研
bx answers "query" --enable-research
多轮迭代搜索调研
传统搜索结果
bx web "query"
包含所有结果类型(网页、新闻、讨论等)
查找讨论/论坛内容
bx web "query" --result-filter discussions
论坛通常包含解决方案
最新新闻/近期事件
bx news "query" --freshness pd
获取超出训练数据范围的实时信息
查找图片
bx images "query"
最多返回200条结果
查找视频
bx videos "query"
包含时长、浏览量、创作者信息
本地商家/地点
bx places "coffee" --location "San Francisco"
覆盖2亿+兴趣点(POI)
提升/过滤特定域名结果
bx "query" --include-site docs.rs
或使用
--goggles
实现完全控制

Commands

命令列表

CommandDescriptionOutput path
context
Default. RAG/LLM grounding — pre-extracted web content
.grounding.generic[]
->
{url, title, snippets[]}
answers
AI answers — OpenAI-compatible, streaming by default
.choices[0].delta.content
(stream)
web
Web search — all result types
.web.results[]
,
.news.results[]
, etc.
news
News articles with freshness filters
.results[]
->
{title, url, age}
images
Image search (up to 200 results)
.results[]
->
{title, url, thumbnail.src}
videos
Video search with duration/views
.results[]
->
{title, url, video.duration}
places
Local place/POI search (200M+ POIs)
.results[]
->
{title, postal_address}
suggest
Autocomplete/query suggestions
.results[]
->
{query}
spellcheck
Spell-check a query
.results[0].query
config
Manage API key and settings
set-key
,
show-key
,
path
,
show
命令描述输出路径
context
默认命令。RAG/LLM基础锚定——预提取网页内容
.grounding.generic[]
->
{url, title, snippets[]}
answers
AI回答——兼容OpenAI,默认流式输出
.choices[0].delta.content
(流式输出)
web
网页搜索——包含所有结果类型
.web.results[]
,
.news.results[]
news
带新鲜度过滤的新闻文章
.results[]
->
{title, url, age}
images
图片搜索(最多200条结果)
.results[]
->
{title, url, thumbnail.src}
videos
带时长/浏览量的视频搜索
.results[]
->
{title, url, video.duration}
places
本地地点/兴趣点搜索(2亿+兴趣点)
.results[]
->
{title, postal_address}
suggest
自动补全/查询建议
.results[]
->
{query}
spellcheck
查询语句拼写检查
.results[0].query
config
管理API密钥和设置
set-key
,
show-key
,
path
,
show

Response Shapes

响应格式

bx "query"
(context — default, recommended)
json
{
  "grounding": {
    "generic": [
      { "url": "...", "title": "...", "snippets": ["extracted content...", "..."] }
    ]
  },
  "sources": {
    "https://example.com": { "title": "...", "hostname": "...", "age": ["...", "2025-01-15", "392 days ago"] }
  }
}
bx answers "query" --no-stream
(single JSON response)
json
{"choices": [{"message": {"content": "Full answer text..."}}]}
bx answers "query"
(streaming — default, one JSON chunk per line)
json
{"choices": [{"delta": {"content": "chunk"}}]}
bx web "query"
(full search results)
json
{
  "web": { "results": [{"title": "...", "url": "...", "description": "..."}] },
  "news": { "results": [...] },
  "videos": { "results": [...] },
  "discussions": { "results": [...] }
}
bx "query"
(context——默认推荐模式)
json
{
  "grounding": {
    "generic": [
      { "url": "...", "title": "...", "snippets": ["extracted content...", "..."] }
    ]
  },
  "sources": {
    "https://example.com": { "title": "...", "hostname": "...", "age": ["...", "2025-01-15", "392 days ago"] }
  }
}
bx answers "query" --no-stream
(单一JSON响应)
json
{"choices": [{"message": {"content": "Full answer text..."}}]}
bx answers "query"
(流式输出——默认,每行一个JSON块)
json
{"choices": [{"delta": {"content": "chunk"}}]}
bx web "query"
(完整搜索结果)
json
{
  "web": { "results": [{"title": "...", "url": "...", "description": "..."}] },
  "news": { "results": [...] },
  "videos": { "results": [...] },
  "discussions": { "results": [...] }
}

Token Budget Control

令牌预算控制

Control output size for context (the default command):
FlagShort aliasDefaultDescription
--maximum-number-of-tokens
--max-tokens
8192Approximate total tokens (1024-32768)
--maximum-number-of-tokens-per-url
--max-tokens-per-url
4096Max tokens per URL (512-8192)
--maximum-number-of-urls
--max-urls
20Max URLs in response (1-50)
--maximum-number-of-snippets
--max-snippets
50Max snippets across all URLs
--maximum-number-of-snippets-per-url
--max-snippets-per-url
Max snippets per URL
--context-threshold-mode
--threshold
balancedRelevance:
strict
,
balanced
,
lenient
bash
bx "topic" --max-tokens 4096 --max-tokens-per-url 1024 --max-urls 5 --threshold strict
控制context(默认命令)的输出大小:
标志短别名默认值描述
--maximum-number-of-tokens
--max-tokens
8192总令牌数近似值(范围1024-32768)
--maximum-number-of-tokens-per-url
--max-tokens-per-url
4096单URL最大令牌数(范围512-8192)
--maximum-number-of-urls
--max-urls
20响应中包含的最大URL数量(范围1-50)
--maximum-number-of-snippets
--max-snippets
50所有URL的最大片段数量
--maximum-number-of-snippets-per-url
--max-snippets-per-url
单URL最大片段数量
--context-threshold-mode
--threshold
balanced相关性模式:
strict
(严格)、
balanced
(平衡)、
lenient
(宽松)
bash
bx "topic" --max-tokens 4096 --max-tokens-per-url 1024 --max-urls 5 --threshold strict

Goggles — Custom Ranking

Goggles — 自定义排序

Goggles let you control which sources appear in results. Boost official docs, suppress SEO spam, or build focused search scopes. No other search tool offers this. Supported on
context
,
web
, and
news
.
Goggles允许你控制结果中显示的来源。可提升官方文档权重、抑制SEO垃圾内容,或构建聚焦的搜索范围。没有其他搜索工具提供此功能。支持
context
web
news
命令。

Domain Shortcuts

域名快捷方式

bash
undefined
bash
undefined

Allowlist — only results from these domains

白名单——仅返回这些域名的结果

bx "rust axum" --include-site docs.rs --include-site github.com
bx "rust axum" --include-site docs.rs --include-site github.com

Blocklist — exclude specific domains

黑名单——排除特定域名

bx "python tutorial" --exclude-site example.com

`--include-site`, `--exclude-site`, and `--goggles` are mutually exclusive.
bx "python tutorial" --exclude-site example.com

`--include-site`、`--exclude-site`和`--goggles`互斥。

Inline Rules

内联规则

bash
undefined
bash
undefined

Boost official docs, demote blog posts

提升官方文档权重,降低博客文章权重

bx "axum middleware tower"
--goggles '$boost=5,site=docs.rs $boost=3,site=github.com /docs/$boost=5 /blog/$downrank=3' --max-tokens 4096
bx "axum middleware tower"
--goggles '$boost=5,site=docs.rs $boost=3,site=github.com /docs/$boost=5 /blog/$downrank=3' --max-tokens 4096

Allowlist mode — only include matched sites

白名单模式——仅包含匹配的站点

bx "Python asyncio patterns"
--goggles '$discard $boost,site=docs.python.org $boost,site=peps.python.org'
undefined
bx "Python asyncio patterns"
--goggles '$discard $boost,site=docs.python.org $boost,site=peps.python.org'
undefined

DSL Quick Reference

DSL速查

RuleEffectExample
$boost=N,site=DOMAIN
Promote domain (N=1-10)
$boost=3,site=docs.rs
$downrank=N,site=DOMAIN
Demote domain (N=1-10)
$downrank=5,site=example.com
$discard,site=DOMAIN
Remove domain entirely
$discard,site=example.com
/path/$boost=N
Boost matching URL paths
/docs/$boost=5
Generic
$discard
Allowlist mode — discard unmatched
$discard
(as first rule)
Separate rules with newlines. Full DSL: goggles-quickstart.
规则效果示例
$boost=N,site=DOMAIN
提升域名权重(N=1-10)
$boost=3,site=docs.rs
$downrank=N,site=DOMAIN
降低域名权重(N=1-10)
$downrank=5,site=example.com
$discard,site=DOMAIN
完全移除该域名结果
$discard,site=example.com
/path/$boost=N
提升匹配URL路径的权重
/docs/$boost=5
通用
$discard
白名单模式——丢弃未匹配结果
$discard
(作为第一条规则)
规则之间用换行分隔。完整DSL文档:goggles-quickstart

Piping Rules via Stdin

通过标准输入传递规则

bash
echo '$boost=5,site=docs.rs
$boost=5,site=crates.io
$boost=3,site=github.com' | bx "axum middleware" --goggles @- --max-tokens 4096
Use
@/path/to/file
to reuse a goggle across queries.
bash
echo '$boost=5,site=docs.rs
$boost=5,site=crates.io
$boost=3,site=github.com' | bx "axum middleware" --goggles @- --max-tokens 4096
使用
@/path/to/file
可在多个查询中复用同一Goggle规则。

Agent Workflow Examples

Agent工作流示例

Debugging an error:
bash
bx "Python TypeError cannot unpack non-iterable NoneType" --max-tokens 4096
Corrective RAG loop:
bash
undefined
调试错误:
bash
bx "Python TypeError cannot unpack non-iterable NoneType" --max-tokens 4096
修正型RAG循环:
bash
undefined

1. Broad search

1. 宽泛搜索

bx "axum middleware authentication" --max-tokens 4096
bx "axum middleware authentication" --max-tokens 4096

2. Too general? Narrow with strict threshold

2. 结果太泛?用严格阈值缩小范围

bx "axum middleware tower layer authentication example" --threshold strict --max-tokens 4096
bx "axum middleware tower layer authentication example" --threshold strict --max-tokens 4096

3. Still need synthesis? Ask for an answer

3. 仍需要合成内容?请求AI回答

bx answers "how to implement JWT auth middleware in axum" --enable-research

**Checking for breaking changes before upgrading:**
```bash
bx "Next.js 15 breaking changes migration guide" --max-tokens 8192
bx news "Next.js 15 release" --freshness pm
Non-streaming answers for programmatic use:
bash
bx answers "compare SQLx and Diesel for Rust" --no-stream
Answers via stdin (OpenAI-compatible JSON body):
bash
echo '{"messages":[{"role":"user","content":"what are the OWASP top 10 vulnerabilities for web APIs"}]}' | bx answers -
bx answers "how to implement JWT auth middleware in axum" --enable-research

**升级前检查破坏性变更:**
```bash
bx "Next.js 15 breaking changes migration guide" --max-tokens 8192
bx news "Next.js 15 release" --freshness pm
用于程序化调用的非流式回答:
bash
bx answers "compare SQLx and Diesel for Rust" --no-stream
通过标准输入传递请求(兼容OpenAI的JSON格式):
bash
echo '{"messages":[{"role":"user","content":"what are the OWASP top 10 vulnerabilities for web APIs"}]}' | bx answers -

Exit Codes

退出码

CodeMeaningAgent action
0SuccessProcess results
1Client error (bad request)Fix query/parameters
2Usage error (bad flags)Fix CLI arguments
3Auth/permission error (401/403)Check API key:
bx config show-key
4Rate limited (429)Retry after delay
5Server/network errorRetry with backoff
代码含义Agent操作建议
0成功处理结果
1客户端错误(请求无效)修正查询/参数
2使用错误(标志无效)修正CLI参数
3认证/权限错误(401/403)检查API密钥:
bx config show-key
4速率限制(429)延迟后重试
5服务器/网络错误退避重试

Use Cases

使用场景

  • AI agents / coding assistants: One-call web search with token-budgeted, RAG-ready content — replaces search + scrape + extract
  • Fact-checking: Verify claims against current web content with
    bx "query" --threshold strict
  • Documentation lookup: Search official docs with
    --include-site
    or Goggles domain boosting
  • Research: Deep multi-source research with
    bx answers "topic" --enable-research
  • Debugging: Search for error messages and stack traces directly
  • News monitoring: Track topics with
    bx news "query" --freshness pd
  • Local search: Find businesses and places with
    bx places "query" --location "city"
  • AI Agent/编码助手:一键式网页搜索,提供令牌预算控制、适用于RAG的内容——替代搜索+抓取+提取流程
  • 事实核查:使用
    bx "query" --threshold strict
    根据当前网页内容验证声明
  • 文档检索:使用
    --include-site
    或Goggles域名提升功能搜索官方文档
  • 调研:使用
    bx answers "topic" --enable-research
    进行多来源深度调研
  • 调试:直接搜索错误信息和堆栈跟踪
  • 新闻监控:使用
    bx news "query" --freshness pd
    跟踪话题
  • 本地搜索:使用
    bx places "query" --location "city"
    查找商家和地点

Notes

注意事项

  • All output is JSON to stdout; errors go to stderr
  • Global flags:
    --api-key KEY
    ,
    --timeout SECS
    (default 30),
    --extra KEY=VALUE
    (repeatable, adds arbitrary API parameters)
  • Location awareness:
    context
    and
    web
    support
    --lat
    ,
    --long
    ,
    --city
    ,
    --state
    ,
    --state-name
    ,
    --loc-country
    ,
    --postal-code
    ,
    --timezone
  • Research mode:
    bx answers --enable-research
    can take up to 5 minutes; set client timeout accordingly
  • Help:
    bx --help
    for all commands;
    bx <command> --help
    for per-command flags
  • 所有输出均为JSON格式,输出至标准输出;错误信息输出至标准错误
  • 全局标志
    --api-key KEY
    --timeout SECS
    (默认30秒)、
    --extra KEY=VALUE
    (可重复使用,添加任意API参数)
  • 位置感知
    context
    web
    命令支持
    --lat
    --long
    --city
    --state
    --state-name
    --loc-country
    --postal-code
    --timezone
    参数
  • 调研模式
    bx answers --enable-research
    可能需要长达5分钟;请相应设置客户端超时时间
  • 帮助
    bx --help
    查看所有命令;
    bx <command> --help
    查看命令专属标志