llm-context by brave/brave-search-skills
npx skills add https://github.com/brave/brave-search-skills --skill llm-context需要 API 密钥 : 请访问 https://api.search.brave.com 获取
套餐 : 包含在 搜索 套餐中。请参阅 https://api-dashboard.search.brave.com/app/subscriptions/subscribe
Brave LLM 上下文 API 提供预先提取、按相关性排序的网页内容,旨在将 LLM 响应基于实时搜索结果。与传统返回链接和摘要的网页搜索 API 不同,LLM 上下文提取实际的页面内容——文本片段、表格、代码块和结构化数据——以便您的 LLM 或 AI 智能体可以直接对其进行推理。
| 功能 | LLM 上下文 (本服务) | AI 基础 (answers) |
|---|---|---|
| 输出 | 供您的 LLM 使用的原始提取内容 | 带有引用的端到端 AI 答案 |
| 接口 | REST API (GET/POST) | OpenAI 兼容的 /chat/completions |
| 搜索 |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| 每个请求单次搜索 |
| 多轮搜索 (迭代研究) |
| 速度 | 快 (<1秒) | 较慢 |
| 套餐 | 搜索 | 答案 |
| 端点 | /res/v1/llm/context | /res/v1/chat/completions |
| 最适合 | AI 智能体、RAG 管道、工具调用 | 聊天界面、研究模式 |
GET https://api.search.brave.com/res/v1/llm/context
POST https://api.search.brave.com/res/v1/llm/context
身份验证 : X-Subscription-Token: <API_KEY> 请求头
可选请求头 :
Accept-Encoding: gzip — 启用 gzip 压缩curl -s "https://api.search.brave.com/res/v1/llm/context?q=tallest+mountains+in+the+world" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
curl -s --compressed -X POST "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "Accept-Encoding: gzip" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"q": "tallest mountains in the world"}'
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-G \
--data-urlencode "q=rust programming" \
--data-urlencode 'goggles=$discard
$site=docs.rs
$site=rust-lang.org'
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|---|---|---|---|---|
q | string | 是 | - | 搜索查询 (1-400 字符,最多 50 个单词) |
country | string | 否 | US | 搜索国家 (2 字母国家代码或 ALL) |
search_lang | string | 否 | en | 语言偏好 (2+ 字符语言代码) |
count | int | 否 | 20 | 要考虑的最大搜索结果数 (1-50) |
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|---|---|---|---|---|
maximum_number_of_urls | int | 否 | 20 | 响应中的最大 URL 数 (1-50) |
maximum_number_of_tokens | int | 否 | 8192 | 上下文中的近似最大令牌数 (1024-32768) |
maximum_number_of_snippets | int | 否 | 50 | 所有 URL 中的最大片段数 (1-100) |
maximum_number_of_tokens_per_url | int | 否 | 4096 | 每个独立 URL 的最大令牌数 (512-8192) |
maximum_number_of_snippets_per_url | int | 否 | 50 | 每个独立 URL 的最大片段数 (1-100) |
| 参数 | 类型 | 必需 | 默认值 | 描述 |
|---|---|---|---|---|
context_threshold_mode | string | 否 | balanced | 包含内容的相关性阈值 (strict/balanced/lenient) |
enable_local | bool | 否 | null | 本地召回控制 (true/false/null,见下文) |
goggles | string/list | 否 | null | 用于自定义重新排序的 Goggle URL 或内联定义 |
| 任务类型 | count | max_tokens | 示例 |
|---|---|---|---|
| 简单事实查询 | 5 | 2048 | "Python 是哪一年创建的?" |
| 标准查询 | 20 | 8192 | "React hooks 的最佳实践" |
| 复杂研究 | 50 | 16384 | "比较用于生产的 AI 框架" |
更大的上下文窗口提供更多信息,但会增加延迟和成本 (您的推理成本)。从默认值开始并进行调整。
| 模式 | 行为 |
|---|---|
strict | 更高阈值 — 结果更少但更相关 |
balanced | 默认 — 覆盖范围和相关性之间的良好平衡 |
lenient | 更低阈值 — 结果更多,可能包含相关性较低的内容 |
enable_local 参数控制位置感知召回:
| 值 | 行为 |
|---|---|
null (未设置) | 自动检测 — 当提供任何位置请求头时启用本地召回 |
true | 强制本地 — 即使没有位置请求头也始终使用本地召回 |
false | 强制标准 — 即使有位置请求头也始终使用标准网页排名 |
对于大多数用例,省略 enable_local 并让 API 根据位置请求头自动检测。
| 请求头 | 类型 | 描述 |
|---|---|---|
X-Loc-Lat | float | 纬度 (-90.0 至 90.0) |
X-Loc-Long | float | 经度 (-180.0 至 180.0) |
X-Loc-City | string | 城市名称 |
X-Loc-State | string | 州/地区代码 (ISO 3166-2) |
X-Loc-State-Name | string | 州/地区名称 |
X-Loc-Country | string | 2 字母国家代码 |
X-Loc-Postal-Code | string | 邮政编码 |
优先级 :
X-Loc-Lat+X-Loc-Long优先。当提供坐标时,基于文本的请求头 (City, State, Country, Postal-Code) 不会用于位置解析。仅当您没有坐标时才提供基于文本的请求头。
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "X-Loc-Lat: 37.7749" \
-H "X-Loc-Long: -122.4194" \
-G \
--data-urlencode "q=best coffee shops near me"
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "X-Loc-City: San Francisco" \
-H "X-Loc-State: CA" \
-H "X-Loc-Country: US" \
-G \
--data-urlencode "q=best coffee shops near me"
Goggles 让您可以控制哪些来源为您的 LLM 提供基础——这对 RAG 质量至关重要。
| 用例 | Goggle 规则 |
|---|---|
| 仅官方文档 | $discard\n$site=docs.python.org |
| 排除用户内容 | $discard,site=reddit.com\n$discard,site=stackoverflow.com |
| 学术来源 | $discard\n$site=arxiv.org\n$site=.edu |
| 无付费墙 | $discard,site=medium.com |
| 方法 | 示例 |
| --- | --- |
| 托管 | --data-urlencode "goggles=https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/1k_short.goggle" |
| 内联 | --data-urlencode 'goggles=$discard\n$site=example.com' |
托管的 goggles 必须托管在 GitHub/GitLab 上,包含
! name:、! description:、! author:请求头,并在 https://search.brave.com/goggles/create 注册。内联规则无需注册。
语法 : $boost=N / $downrank=N (1–10), $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.com
{
"grounding": {
"generic": [
{
"url": "https://example.com/page",
"title": "Page Title",
"snippets": [
"Relevant text chunk extracted from the page...",
"Another relevant passage from the same page..."
]
}
],
"map": []
},
"sources": {
"https://example.com/page": {
"title": "Page Title",
"hostname": "example.com",
"age": ["Wednesday, January 15, 2025", "2025-01-15", "392 days ago"]
}
}
}
enable_local){
"grounding": {
"generic": [...],
"poi": {
"name": "Business Name",
"url": "https://business.com",
"title": "Title of business.com website",
"snippets": ["Business details and information..."]
},
"map": [
{
"name": "Place Name",
"url": "https://place.com",
"title": "Title of place.com website",
"snippets": ["Place information and details..."]
}
]
},
"sources": {
"https://business.com": {
"title": "Business Name",
"hostname": "business.com",
"age": null
}
}
}
| 字段 | 类型 | 描述 |
|---|---|---|
grounding | object | 按类型存放所有基础内容的容器 |
grounding.generic | array | 包含提取内容的 URL 对象数组 (主要基础数据) |
grounding.generic[].url | string | 来源 URL |
grounding.generic[].title | string | 页面标题 |
grounding.generic[].snippets | array | 提取的与查询相关的智能片段 |
grounding.poi | object/null | 兴趣点数据 (仅限本地召回) |
grounding.poi.name | string/null | 兴趣点名称 |
grounding.poi.url | string/null | POI 来源 URL |
grounding.poi.title | string/null | POI 页面标题 |
grounding.poi.snippets | array/null | POI 文本片段 |
grounding.map | array | 地图/地点结果 (仅限本地召回) |
grounding.map[].name | string/null | 地点名称 |
grounding.map[].url | string/null | 地点来源 URL |
grounding.map[].title | string/null | 地点页面标题 |
grounding.map[].snippets | array/null | 地点文本片段 |
sources | object | 所有引用 URL 的元数据,以 URL 为键 |
sources[url].title | string | 页面标题 |
sources[url].hostname | string | 来源主机名 |
sources[url].age | array/null | 页面修改日期 (当可用时) |
注意 : 片段可能包含纯文本或 JSON 序列化的结构化数据 (表格、模式、代码块)。LLMs 能很好地处理这种混合格式。
maximum_number_of_tokens=8192, count=20)。对于简单查询可减少,对于复杂研究可增加。context_threshold_mode=strict。count 和 maximum_number_of_tokens。对于本地查询,请提供位置请求头。每周安装量
95
代码仓库
GitHub 星标数
81
首次出现
2026年2月13日
安全审计
安装于
codex89
gemini-cli88
github-copilot88
kimi-cli87
opencode87
amp86
Requires API Key : Get one at https://api.search.brave.com
Plan : Included in the Search plan. See https://api-dashboard.search.brave.com/app/subscriptions/subscribe
Brave LLM Context API delivers pre-extracted, relevance-ranked web content optimized for grounding LLM responses in real-time search results. Unlike traditional web search APIs that return links and snippets, LLM Context extracts the actual page content—text chunks, tables, code blocks, and structured data—so your LLM or AI agent can reason over it directly.
| Feature | LLM Context (this) | AI Grounding (answers) |
|---|---|---|
| Output | Raw extracted content for YOUR LLM | End-to-end AI answers with citations |
| Interface | REST API (GET/POST) | OpenAI-compatible /chat/completions |
| Searches | Single search per request | Multi-search (iterative research) |
| Speed | Fast (<1s) | Slower |
| Plan | Search | Answers |
| Endpoint | /res/v1/llm/context | /res/v1/chat/completions |
| Best for | AI agents, RAG pipelines, tool calls | Chat interfaces, research mode |
GET https://api.search.brave.com/res/v1/llm/context
POST https://api.search.brave.com/res/v1/llm/context
Authentication : X-Subscription-Token: <API_KEY> header
Optional Headers :
Accept-Encoding: gzip — Enable gzip compressioncurl -s "https://api.search.brave.com/res/v1/llm/context?q=tallest+mountains+in+the+world" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}"
curl -s --compressed -X POST "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "Accept-Encoding: gzip" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"q": "tallest mountains in the world"}'
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-G \
--data-urlencode "q=rust programming" \
--data-urlencode 'goggles=$discard
$site=docs.rs
$site=rust-lang.org'
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
q | string | Yes | - | Search query (1-400 chars, max 50 words) |
country | string | No | US | Search country (2-letter country code or ALL) |
search_lang | string | No |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
maximum_number_of_urls | int | No | 20 | Max URLs in response (1-50) |
maximum_number_of_tokens | int | No | 8192 | Approximate max tokens in context (1024-32768) |
maximum_number_of_snippets | int |
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
context_threshold_mode | string | No | balanced | Relevance threshold for including content (strict/balanced/lenient) |
enable_local | bool | No | null |
| Task Type | count | max_tokens | Example |
|---|---|---|---|
| Simple factual | 5 | 2048 | "What year was Python created?" |
| Standard queries | 20 | 8192 | "Best practices for React hooks" |
| Complex research | 50 | 16384 | "Compare AI frameworks for production" |
Larger context windows provide more information but increase latency and cost (of your inference). Start with defaults and adjust.
| Mode | Behavior |
|---|---|
strict | Higher threshold — fewer but more relevant results |
balanced | Default — good balance between coverage and relevance |
lenient | Lower threshold — more results, may include less relevant content |
The enable_local parameter controls location-aware recall:
| Value | Behavior |
|---|---|
null (not set) | Auto-detect — local recall enabled when any location header is provided |
true | Force local — always use local recall, even without location headers |
false | Force standard — always use standard web ranking, even with location headers |
For most use cases, omit enable_local and let the API auto-detect from location headers.
| Header | Type | Description |
|---|---|---|
X-Loc-Lat | float | Latitude (-90.0 to 90.0) |
X-Loc-Long | float | Longitude (-180.0 to 180.0) |
X-Loc-City | string | City name |
X-Loc-State | string | State/region code (ISO 3166-2) |
X-Loc-State-Name | string | State/region name |
Priority :
X-Loc-Lat+X-Loc-Longtake precedence. When provided, 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.
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "X-Loc-Lat: 37.7749" \
-H "X-Loc-Long: -122.4194" \
-G \
--data-urlencode "q=best coffee shops near me"
curl -s "https://api.search.brave.com/res/v1/llm/context" \
-H "Accept: application/json" \
-H "X-Subscription-Token: ${BRAVE_SEARCH_API_KEY}" \
-H "X-Loc-City: San Francisco" \
-H "X-Loc-State: CA" \
-H "X-Loc-Country: US" \
-G \
--data-urlencode "q=best coffee shops near me"
Goggles let you control which sources ground your LLM — essential for RAG quality.
| Use Case | Goggle Rules |
|---|---|
| Official docs only | $discard\n$site=docs.python.org |
| Exclude user content | $discard,site=reddit.com\n$discard,site=stackoverflow.com |
| Academic sources | $discard\n$site=arxiv.org\n$site=.edu |
| No paywalls | $discard,site=medium.com |
| Method | Example |
| --- | --- |
| Hosted | --data-urlencode "goggles=https://raw.githubusercontent.com/brave/goggles-quickstart/main/goggles/1k_short.goggle" |
Hosted goggles must be on GitHub/GitLab, include
! name:,! description:,! author:headers, and be registered at https://search.brave.com/goggles/create. Inline rules need no registration.
Syntax : $boost=N / $downrank=N (1–10), $discard, $site=example.com. Combine with commas: $site=example.com,boost=3. Separate rules with \n (%0A).
Allow list : $discard\n$site=docs.python.org\n$site=developer.mozilla.org — Block list : $discard,site=pinterest.com\n$discard,site=quora.com
Resources : Discover · Syntax · Quickstart
{
"grounding": {
"generic": [
{
"url": "https://example.com/page",
"title": "Page Title",
"snippets": [
"Relevant text chunk extracted from the page...",
"Another relevant passage from the same page..."
]
}
],
"map": []
},
"sources": {
"https://example.com/page": {
"title": "Page Title",
"hostname": "example.com",
"age": ["Wednesday, January 15, 2025", "2025-01-15", "392 days ago"]
}
}
}
enable_local){
"grounding": {
"generic": [...],
"poi": {
"name": "Business Name",
"url": "https://business.com",
"title": "Title of business.com website",
"snippets": ["Business details and information..."]
},
"map": [
{
"name": "Place Name",
"url": "https://place.com",
"title": "Title of place.com website",
"snippets": ["Place information and details..."]
}
]
},
"sources": {
"https://business.com": {
"title": "Business Name",
"hostname": "business.com",
"age": null
}
}
}
| Field | Type | Description |
|---|---|---|
grounding | object | Container for all grounding content by type |
grounding.generic | array | Array of URL objects with extracted content (main grounding data) |
grounding.generic[].url | string | Source URL |
grounding.generic[].title | string | Page title |
grounding.generic[].snippets |
Note : Snippets may contain plain text OR JSON-serialized structured data (tables, schemas, code blocks). LLMs handle this mixed format well.
maximum_number_of_tokens=8192, count=20). Reduce for simple lookups, increase for complex research.context_threshold_mode=strict when precision > recall.count and maximum_number_of_tokens that meet your needs. For local queries, provide location headers.Weekly Installs
95
Repository
GitHub Stars
81
First Seen
Feb 13, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
codex89
gemini-cli88
github-copilot88
kimi-cli87
opencode87
amp86
超能力技能使用指南:AI助手技能调用优先级与工作流程详解
49,600 周安装
en |
| Language preference (2+ char language code) |
count | int | No | 20 | Max search results to consider (1-50) |
| No |
50 |
| Max snippets across all URLs (1-100) |
maximum_number_of_tokens_per_url | int | No | 4096 | Max tokens per individual URL (512-8192) |
maximum_number_of_snippets_per_url | int | No | 50 | Max snippets per individual URL (1-100) |
Local recall control (true/false/null, see below) |
goggles | string/list | No | null | Goggle URL or inline definition for custom re-ranking |
X-Loc-Country | string | 2-letter country code |
X-Loc-Postal-Code | string | Postal code |
| Inline | --data-urlencode 'goggles=$discard\n$site=example.com' |
| array |
| Extracted smart chunks relevant to the query |
grounding.poi | object/null | Point of interest data (only with local recall) |
grounding.poi.name | string/null | Point of interest name |
grounding.poi.url | string/null | POI source URL |
grounding.poi.title | string/null | POI page title |
grounding.poi.snippets | array/null | POI text snippets |
grounding.map | array | Map/place results (only with local recall) |
grounding.map[].name | string/null | Place name |
grounding.map[].url | string/null | Place source URL |
grounding.map[].title | string/null | Place page title |
grounding.map[].snippets | array/null | Place text snippets |
sources | object | Metadata for all referenced URLs, keyed by URL |
sources[url].title | string | Page title |
sources[url].hostname | string | Source hostname |
sources[url].age | array/null | Page modification dates (when available) |