answers
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseAnswers — AI Grounding
基于AI的事实性回答(Answers)
Requires API Key: Get one at https://api.search.brave.comPlan: Included in the Answers plan. See https://api-dashboard.search.brave.com/app/subscriptions/subscribe
需要API密钥:请前往https://api.search.brave.com获取适用套餐:包含在Answers套餐中。详情请见https://api-dashboard.search.brave.com/app/subscriptions/subscribe
When to Use
适用场景
| Use Case | Skill | Why |
|---|---|---|
| Quick factual answer (raw context) | | Single search, returns raw context for YOUR LLM |
| Fast AI answer with citations | | streaming, citations |
| Thorough multi-search deep research | | Iterative deep research, synthesized cited answer |
This endpoint () supports two modes:
/res/v1/chat/completions- Single-search (default): Fast AI-grounded answer from a single search. Supports .
enable_citations - Research (): Multi-iteration deep research with progress events and synthesized cited answer.
enable_research=true
| 使用场景 | 技能/接口 | 原因 |
|---|---|---|
| 快速获取事实性回答(原始上下文) | | 单次搜索,为你的LLM返回原始上下文 |
| 快速获取带引用的AI回答 | | 支持流式响应、附带引用 |
| 全面的多轮深度研究 | | 迭代式深度研究,生成带引用的综合回答 |
本接口 () 支持两种模式:
/res/v1/chat/completions- 单搜索(默认):基于单次搜索快速生成AI事实性回答,支持参数。
enable_citations - 研究模式(设置):多轮迭代深度研究,包含进度事件,生成带引用的综合回答。
enable_research=true
Quick Start (cURL)
快速开始(cURL示例)
Blocking (Single-Search)
阻塞式响应(单搜索模式)
bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
"model": "brave",
"stream": false
}'bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
"model": "brave",
"stream": false
}'Streaming with Citations (Single-Search)
带引用的流式响应(单搜索模式)
bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "What are recent breakthroughs in fusion energy?"}],
"model": "brave",
"stream": true,
"enable_citations": true
}'bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "What are recent breakthroughs in fusion energy?"}],
"model": "brave",
"stream": true,
"enable_citations": true
}'Research Mode
研究模式
bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "Compare quantum computing approaches"}],
"model": "brave",
"stream": true,
"enable_research": true,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}'bash
curl -X POST "https://api.search.brave.com/res/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-d '{
"messages": [{"role": "user", "content": "Compare quantum computing approaches"}],
"model": "brave",
"stream": true,
"enable_research": true,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}'Endpoint
接口信息
http
POST https://api.search.brave.com/res/v1/chat/completionsAuthentication: header (or )
X-Subscription-Token: <API_KEY>Authorization: Bearer <API_KEY>SDK Compatible: Works with OpenAI SDK via
base_url="https://api.search.brave.com/res/v1"http
POST https://api.search.brave.com/res/v1/chat/completions认证方式:通过请求头(或)进行认证
X-Subscription-Token: <API_KEY>Authorization: Bearer <API_KEY>SDK兼容性:可通过设置适配OpenAI SDK
base_url="https://api.search.brave.com/res/v1"Two Modes
两种模式对比
| Feature | Single-Search (default) | Research ( |
|---|---|---|
| Speed | Fast | Slow |
| Searches | 1 | Multiple (iterative) |
| Streaming | Optional ( | Required ( |
| Citations | | Built-in (in |
| Progress events | No | Yes ( |
| Blocking response | Yes ( | No |
| 特性 | 单搜索(默认) | 研究模式( |
|---|---|---|
| 响应速度 | 快 | 慢 |
| 搜索次数 | 1次 | 多次(迭代式) |
| 流式响应 | 可选( | 必填( |
| 引用来源 | 需设置 | 内置(包含在 |
| 进度事件 | 无 | 有( |
| 阻塞式响应 | 支持( | 不支持 |
Parameters
参数说明
Standard Parameters
标准参数
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| array | Yes | - | Single user message (exactly 1 message) |
| string | Yes | - | Use |
| bool | No | true | Enable SSE streaming |
| string | No | "US" | Search country (2-letter country code or |
| string | No | "en" | Response language |
| string | No | "moderate" | Search safety level ( |
| int | No | null | Upper bound on completion tokens |
| bool | No | false | Include inline citation tags (single-search streaming only) |
| object | No | null | OpenAI-compatible; |
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| 数组 | 是 | - | 仅支持单条用户消息(数组中必须恰好包含1条消息) |
| 字符串 | 是 | - | 需设置为 |
| 布尔值 | 否 | true | 启用SSE流式响应 |
| 字符串 | 否 | "US" | 搜索地区(两位国家代码或 |
| 字符串 | 否 | "en" | 响应语言 |
| 字符串 | 否 | "moderate" | 搜索安全级别( |
| 整数 | 否 | null | 生成内容的最大token数上限 |
| 布尔值 | 否 | false | 启用内联引用标签(仅单搜索模式的流式响应支持) |
| 对象 | 否 | null | 兼容OpenAI的参数; |
Research Parameters
研究模式专属参数
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| bool | No | | Enable research mode |
| bool | No | | Enable extended thinking |
| int | No | | Max tokens per query (1024-16384) |
| int | No | | Max total search queries (1-50) |
| int | No | | Max research iterations (1-5) |
| int | No | | Time budget in seconds (1-300) |
| int | No | | Results per search query (1-60) |
| 参数名 | 类型 | 是否必填 | 默认值 | 描述 |
|---|---|---|---|---|
| 布尔值 | 否 | | 启用研究模式 |
| 布尔值 | 否 | | 启用扩展思考逻辑 |
| 整数 | 否 | | 每个搜索查询的最大token数(范围1024-16384) |
| 整数 | 否 | | 最大总搜索查询次数(范围1-50) |
| 整数 | 否 | | 最大研究迭代次数(范围1-5) |
| 整数 | 否 | | 时间预算(秒,范围1-300) |
| 整数 | 否 | | 每次搜索查询返回的结果数(范围1-60) |
Constraints (IMPORTANT)
约束条件(重要)
| Constraint | Error |
|---|---|
| "Blocking response doesn't support 'enable_research' option" |
| "Research mode doesn't support 'enable_citations' option" |
| "Blocking response doesn't support 'enable_citations' option" |
| 约束条件 | 错误提示 |
|---|---|
| "Blocking response doesn't support 'enable_research' option" |
| "Research mode doesn't support 'enable_citations' option" |
| "Blocking response doesn't support 'enable_citations' option" |
OpenAI SDK Usage
OpenAI SDK 使用示例
Blocking (Single-Search)
阻塞式响应(单搜索模式)
python
from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
response = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
stream=False,
)
print(response.choices[0].message.content)python
from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
response = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "How does the James Webb Space Telescope work?"}],
stream=False,
)
print(response.choices[0].message.content)Streaming with Citations (Single-Search)
带引用的流式响应(单搜索模式)
python
from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "What are the current trends in renewable energy?"}],
stream=True,
extra_body={"enable_citations": True}
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")python
from openai import OpenAI
client = OpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "What are the current trends in renewable energy?"}],
stream=True,
extra_body={"enable_citations": True}
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Research Mode
研究模式
python
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = await client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "Compare quantum computing approaches"}],
stream=True,
extra_body={
"enable_research": True,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)python
from openai import AsyncOpenAI
client = AsyncOpenAI(
base_url="https://api.search.brave.com/res/v1",
api_key="your-brave-api-key",
)
stream = await client.chat.completions.create(
model="brave",
messages=[{"role": "user", "content": "Compare quantum computing approaches"}],
stream=True,
extra_body={
"enable_research": True,
"research_maximum_number_of_iterations": 3,
"research_maximum_number_of_seconds": 120
}
)
async for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)Response Format
响应格式
Blocking Response (stream=false
, single-search only)
stream=false阻塞式响应(stream=false
,仅单搜索模式支持)
stream=falseStandard OpenAI-compatible JSON:
json
{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "The James Webb Space Telescope works by..."}, "index": 0, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 10, "completion_tokens": 50, "total_tokens": 60}
}兼容OpenAI标准格式的JSON:
json
{
"id": "chatcmpl-...",
"object": "chat.completion",
"choices": [{"message": {"role": "assistant", "content": "The James Webb Space Telescope works by..."}, "index": 0, "finish_reason": "stop"}],
"usage": {"prompt_tokens": 10, "completion_tokens": 50, "total_tokens": 60}
}Streaming Response
流式响应
SSE response with OpenAI-compatible chunks:
text
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Based on"},"index":0}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":" recent research"},"index":0}]}
data: [DONE]采用SSE格式,返回兼容OpenAI的响应块:
text
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":"Based on"},"index":0}]}
data: {"id":"chatcmpl-...","object":"chat.completion.chunk","choices":[{"delta":{"content":" recent research"},"index":0}]}
data: [DONE]Streaming Tags by Mode
不同模式下的流式标签
Single-Search (with enable_citations=true
)
enable_citations=true单搜索模式(启用enable_citations=true
)
enable_citations=true| Tag | Purpose |
|---|---|
| Inline citation references |
| JSON cost/billing data |
| 标签 | 用途 |
|---|---|
| 内联引用标记 |
| JSON格式的成本/计费数据 |
Research Mode
研究模式
| Tag | Purpose | Keep? |
|---|---|---|
| Generated search queries | Debug |
| URL counts (verbose) | Debug |
| URL selection reasoning | Debug |
| Stats: time, iterations, queries, URLs analyzed, tokens | Monitor |
| Knowledge gaps identified | Yes |
| Final synthesized answer (only the final answer is emitted; intermediate drafts are dropped) | Yes |
| JSON cost/billing data (included at end of streaming response) | Yes |
| 标签 | 用途 | 是否需要保留 |
|---|---|---|
| 生成的搜索查询语句 | 调试用 |
| 待分析的URL数量(详细日志) | 调试用 |
| URL选择的推理过程 | 调试用 |
| 统计信息:耗时、迭代次数、查询次数、已分析URL数、token数 | 监控用 |
| 识别出的知识盲区 | 需要 |
| 最终综合回答(仅输出最终结果;中间草稿会被丢弃) | 需要 |
| JSON格式的成本/计费数据(在流式响应末尾返回) | 需要 |
Usage Tag Format
Usage标签格式
The tag contains JSON-stringified cost and token data:
<usage>text
<usage>{"X-Request-Requests":1,"X-Request-Queries":8,"X-Request-Tokens-In":15000,"X-Request-Tokens-Out":2000,"X-Request-Requests-Cost":0.005,"X-Request-Queries-Cost":0.032,"X-Request-Tokens-In-Cost":0.075,"X-Request-Tokens-Out-Cost":0.01,"X-Request-Total-Cost":0.122}</usage><usage>text
<usage>{"X-Request-Requests":1,"X-Request-Queries":8,"X-Request-Tokens-In":15000,"X-Request-Tokens-Out":2000,"X-Request-Requests-Cost":0.005,"X-Request-Queries-Cost":0.032,"X-Request-Tokens-In-Cost":0.075,"X-Request-Tokens-Out-Cost":0.01,"X-Request-Total-Cost":0.122}</usage>Use Cases
典型应用场景
- Chat interface integration: Drop-in OpenAI SDK replacement with web-grounded answers. Set .
base_url="https://api.search.brave.com/res/v1" - Deep research / comprehensive topic research: Use research mode () for complex questions needing multi-source synthesis (e.g., "Compare approaches to nuclear fusion").
enable_research=true - OpenAI SDK drop-in: Same SDK, same streaming format — just change and
base_url. Works with both sync and async clients.api_key - Cited answers: Enable in single-search mode for inline citation tags, or use research mode which automatically includes citations in its answer.
enable_citations=true
- 聊天界面集成:直接替换OpenAI SDK,生成基于网络事实的回答。只需设置即可。
base_url="https://api.search.brave.com/res/v1" - 深度研究/主题调研:针对需要多源信息综合的复杂问题(如“对比核聚变的不同实现方案”),启用研究模式()。
enable_research=true - OpenAI SDK无缝适配:使用相同的SDK与流式格式,仅需修改和
base_url。支持同步与异步客户端。api_key - 带引用的回答:在单搜索模式下启用获取内联引用标记,或使用研究模式(自动在回答中包含引用来源)。
enable_citations=true
Notes
注意事项
- Timeout: Set client timeout to at least 30s for single-search, 300s (5 min) for research
- Single message: The array must contain exactly 1 user message
messages - Cost monitoring: Parse the tag from streaming responses to track costs
<usage>
- 超时设置:单搜索模式建议将客户端超时设置为至少30秒,研究模式建议设置为300秒(5分钟)
- 单条消息限制:数组必须恰好包含1条用户消息
messages - 成本监控:通过解析流式响应中的标签跟踪使用成本
<usage>