Skills2026年5月8日·1 分钟阅读

Grok Live Search Tool — Real-Time Web Grounding via API

Grok Live Search grounds output in fresh web/X/news inside one API call. Whitelist sources, set max results, get inline citations.

Agent 就绪

这个资产可以被 Agent 直接读取和安装

TokRepo 同时提供通用 CLI 命令、安装契约、metadata JSON、按适配器生成的安装计划和原始内容链接,方便 Agent 判断适配度、风险和下一步动作。

Stage only · 17/100Stage only
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Stage only
信任
信任等级:New
入口
Asset
通用 CLI 安装命令
npx tokrepo install 7f7bff2c-8bfd-490d-8802-5b2f14f49ac2

简介

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 自己决定要不要 search
  • on —— 总是 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 服务端不缓存。


🙏

来源与感谢

Built by xAI. Live Search docs at docs.x.ai/docs/guides/live-search.

Public SDK: xai-org

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产