xAI Search (Grok API)
Use xAI's agentic search to query X/Twitter and the web in real-time. This leverages Grok's web_search and x_search tools.
Docs: https://docs.x.ai/docs/
Requirements
- -
XAI_API_KEY environment variable - Python 3 + xai-sdk: INLINECODE3
Quick Usage (curl)
Web Search
CODEBLOCK0
X/Twitter Search
CODEBLOCK1
Combined (Web + X)
CODEBLOCK2
Helper Script
For convenience, use the xai-search.py script in the scripts/ folder:
CODEBLOCK3
Models
- -
grok-3-fast — fast, good for quick searches - INLINECODE7 — reasoning model, better for complex queries
X Search Filters
You can filter X searches by:
- -
allowed_x_handles / excluded_x_handles — limit to specific accounts - INLINECODE10 /
to_date — date range (ISO8601 format) - INLINECODE12 — analyze images in posts
- INLINECODE13 — analyze videos in posts
Web Search Filters
- -
allowed_domains / excluded_domains — limit to specific sites - INLINECODE16 — analyze images on pages
Tips
- - For breaking news: use X search
- For factual/research queries: use web search or both
- For sentiment/opinions: use X search
- The model will make multiple search calls if needed (agentic)
xAI搜索 (Grok API)
使用xAI的智能搜索功能实时查询X/Twitter和网络。该功能利用Grok的websearch和xsearch工具。
文档: https://docs.x.ai/docs/
环境要求
- - XAIAPIKEY 环境变量
- Python 3 + xai-sdk:pip install xai-sdk
快速使用 (curl)
网络搜索
bash
curl -s https://api.x.ai/v1/chat/completions \
-H Authorization: Bearer $XAI
APIKEY \
-H Content-Type: application/json \
-d {
model: grok-3-fast,
messages: [{role: user, content: 在此输入您的查询}],
tools: [{type: function, function: {name: web_search}}]
} | jq -r .choices[0].message.content
X/Twitter搜索
bash
curl -s https://api.x.ai/v1/chat/completions \
-H Authorization: Bearer $XAI
APIKEY \
-H Content-Type: application/json \
-d {
model: grok-3-fast,
messages: [{role: user, content: 在此输入您的查询}],
tools: [{type: function, function: {name: x_search}}]
} | jq -r .choices[0].message.content
组合搜索(网络 + X)
bash
curl -s https://api.x.ai/v1/chat/completions \
-H Authorization: Bearer $XAI
APIKEY \
-H Content-Type: application/json \
-d {
model: grok-3-fast,
messages: [{role: user, content: 在此输入您的查询}],
tools: [
{type: function, function: {name: web_search}},
{type: function, function: {name: x_search}}
]
} | jq -r .choices[0].message.content
辅助脚本
为方便使用,可使用scripts/文件夹中的xai-search.py脚本:
bash
网络搜索(根据技能位置调整路径)
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py web 关于AI的最新新闻
X/Twitter搜索
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py x 大家对Clawdbot的看法
两者都搜索
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py both 今日时事
模型
- - grok-3-fast — 快速,适合快速搜索
- grok-4-1-fast — 推理模型,适合复杂查询
X搜索过滤器
您可以通过以下方式过滤X搜索:
- - allowedxhandles / excludedxhandles — 限定特定账号
- fromdate / todate — 日期范围(ISO8601格式)
- enableimageunderstanding — 分析帖子中的图片
- enablevideounderstanding — 分析帖子中的视频
网络搜索过滤器
- - alloweddomains / excludeddomains — 限定特定网站
- enableimageunderstanding — 分析页面中的图片
使用技巧
- - 突发新闻:使用X搜索
- 事实/研究查询:使用网络搜索或两者结合
- 情感/观点:使用X搜索
- 模型会根据需要多次调用搜索(智能模式)