简介
Grok Live Search 是 xAI API 内置的服务端工具,把 Grok 响应 grounding 在新鲜 web、X(Twitter)、news 结果上 —— 不用搭外部 retrieval 流水线。设 mode=on/auto、选源类型,Grok 自己 search + read + cite。返回内联引用和 num_sources_used 字段。适合新闻问答、金融/体育/选举应用、任何答案必须反映当下现实的场景。兼容任何 OpenAI 兼容客户端(Python / JS / curl)打 api.x.ai。装机时间 2 分钟。
Curl 例子
curl https://api.x.ai/v1/chat/completions \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-3",
"messages": [{"role":"user","content":"本周 AI 融资 Top 3:金额 + 领投方"}],
"search_parameters": {
"mode": "on",
"sources": [{"type":"web"},{"type":"news"},{"type":"x"}],
"max_search_results": 10,
"from_date": "2026-05-01",
"to_date": "2026-05-08"
}
}'Python 带日期范围 + X 账号筛选
resp = client.chat.completions.create(
model="grok-3",
messages=[{"role": "user", "content": "@sama 在 X 上怎么聊 OpenAI 最新发布?"}],
extra_body={
"search_parameters": {
"mode": "on",
"sources": [
{"type": "x", "x_handles": ["sama"]},
],
"from_date": "2026-05-05",
"max_search_results": 5,
}
},
)源类型
| 类型 | 筛选 | 检索什么 |
|---|---|---|
web |
无 | 公网搜索索引 |
news |
无 | 新闻文章语料 |
x |
x_handles[] |
X(Twitter)posts |
rss |
links[] |
指定的 RSS feed |
模式
off—— 纯模型知识截止(默认)auto—— Grok 自己决定要不要 searchon—— 总是 search(新闻 / 金融 / 体育 / 选举类问题用)
响应字段
resp.choices[0].message.content # grounding 后答案
resp.choices[0].message.citations # {url, title, source_type} 列表
resp.usage.num_sources_used # 实际几个结果参与了答案FAQ
Q: Live Search 成本?
A: 在 token 成本之上按搜索次数计费 —— 通常每次调用几美分,看 max_search_results。具体费率看 console.x.ai。比自己跑 search + scraper + chunker 便宜。
Q: 替代 Tavily / Exa / Perplexity API 吗? A: Grok 用户基本是 —— 一次调用 search + grounding,零件更少。Tavily/Exa 模型无关,多模型栈还有用。Perplexity API 直接对打:Grok 长上下文赢,Perplexity 学术引用深度赢。
Q: 怎么缓存结果省钱? A: 把 (query, source_filter, date_range) 三元组 hash 当 cache key,按新鲜度需求设 TTL(金融 5 分钟、一般新闻 1 小时)存响应。xAI 服务端不缓存。