xAI Skill
Search X (Twitter), search the web, chat with Grok models (including vision), and analyze X content patterns using xAI's API.
Features
- - X Search: Search posts, threads, and accounts with date/handle filters
- Web Search: Search the web via Grok's web_search tool
- Chat: Text and vision (image analysis) with Grok models
- Analysis: Voice patterns, trend research, post safety checks
- Models: List available xAI models
Setup
API Key
Get your xAI API key from console.x.ai.
CODEBLOCK0
The scripts check these locations in order:
- 1.
XAI_API_KEY env var - INLINECODE1 → INLINECODE2
- INLINECODE3 → INLINECODE4
- INLINECODE5 →
skills.entries["grok-search"].apiKey (fallback)
Default Model (Optional)
Override the default model (grok-4-1-fast):
CODEBLOCK1
Model priority:
- 1. Command-line
--model flag (highest priority) - INLINECODE9 env var
- INLINECODE10 → INLINECODE11
- INLINECODE12 → INLINECODE13
- Default: INLINECODE14
Search
X Search
Search X posts and threads with optional filters.
Basic search:
CODEBLOCK2
With date filter:
CODEBLOCK3
Filter by handles:
CODEBLOCK4
Output formats:
CODEBLOCK5
JSON output schema:
CODEBLOCK6
Web Search
Search the web via Grok.
CODEBLOCK7
JSON output schema:
CODEBLOCK8
Search Options
| Flag | Description | Example |
|---|
| INLINECODE15 | Search X/Twitter | Required for X search |
| INLINECODE16 |
Search the web | Required for web search |
|
--days N | Last N days (X only) |
--days 7 |
|
--from YYYY-MM-DD | Start date (X only) |
--from 2026-01-01 |
|
--to YYYY-MM-DD | End date (X only) |
--to 2026-01-31 |
|
--handles a,b | Only these accounts (X only) |
--handles @user1,@user2 |
|
--exclude a,b | Exclude accounts (X only) |
--exclude @spam |
|
--max N | Max results |
--max 20 |
|
--model ID | Override model |
--model grok-3 |
|
--json | JSON output (default) | - |
|
--links-only | Just URLs | - |
|
--text | Human-readable | - |
|
--raw | Include debug output | - |
See references/search-patterns.md for advanced query patterns and optimization tips.
Chat
Text Chat
Ask Grok anything.
CODEBLOCK9
With model override:
CODEBLOCK10
JSON output:
CODEBLOCK11
JSON schema:
CODEBLOCK12
Vision Chat
Analyze images with Grok.
CODEBLOCK13
Multiple images:
CODEBLOCK14
Supported formats: JPG, PNG, WebP, GIF
Chat Options
| Flag | Description | Example |
|---|
| INLINECODE35 | Model to use | INLINECODE36 |
| INLINECODE37 |
Attach image (can repeat) |
--image ./pic.jpg |
|
--json | JSON output | - |
|
--raw | Include debug output | - |
See references/models.md for model comparison and capabilities.
Analysis
Analyze X content for voice patterns, trends, and post quality.
Voice Analysis
Analyze an account's voice and writing patterns.
CODEBLOCK15
Custom date range:
CODEBLOCK16
JSON output schema:
CODEBLOCK17
Trend Research
Research trends and discussions about a topic.
CODEBLOCK18
JSON output schema:
CODEBLOCK19
Post Safety Check
Check a draft post or existing post for AI signals and platform flag patterns.
Check draft text:
CODEBLOCK20
Check existing post:
CODEBLOCK21
JSON output schema:
CODEBLOCK22
Scoring:
- - AI Detection: 0-10 (10 = definitely AI)
- Platform Flag Risk: 0-10 (10 = high spam risk)
- Quality: 0-10 (10 = excellent)
Analysis Options
| Flag | Description | Example |
|---|
| INLINECODE41 | Date range for analysis | INLINECODE42 |
| INLINECODE43 |
Analyze existing post |
--url https://x.com/... |
|
--model ID | Override model |
--model grok-3 |
|
--json | JSON output | - |
|
--raw | Include debug output | - |
See references/analysis-prompts.md for detailed prompt structures and scoring criteria.
Models
List available xAI models.
CODEBLOCK23
Output:
CODEBLOCK24
JSON output:
CODEBLOCK25
Quick model comparison:
| Model | Speed | Quality | Vision | Best For |
|---|
| grok-4-1-fast | Fast | Good | No | Default (search, chat, analysis) |
| grok-4-fast |
Fast | Good | No | Alternative fast model |
| grok-3 | Slower | Best | No | Complex reasoning, detailed analysis |
| grok-2-vision-1212 | Medium | Good | Yes | Image analysis |
See references/models.md for detailed model capabilities and use cases.
Advanced Usage
Citation Deduplication
For X searches, the tool automatically deduplicates tweet URLs, preferring canonical /@handle/status/id over /i/status/id format.
Custom Model Selection
Override the default model for any operation:
CODEBLOCK26
Debugging
Add --raw to any command to see the full API response:
CODEBLOCK27
Reference Documentation
Examples
Research a topic
CODEBLOCK28
Analyze voice before drafting
CODEBLOCK29
Multi-modal research
CODEBLOCK30
Error Handling
Common errors and solutions:
Missing API key:
Missing XAI_API_KEY
→ Set
XAI_API_KEY environment variable or add to INLINECODE53
Invalid mode:
Must specify --web or --x
→ Add
--web or
--x flag to search command
Image format error:
Unsupported image type
→ Use JPG, PNG, WebP, or GIF format
API error:
xAI API error: 401 Unauthorized
→ Check API key is valid and active
Tips
- - Default model (
grok-4-1-fast) is fast and good for most tasks - Use
grok-3 for complex analysis or when quality matters more than speed - X searches are limited by recency (xAI x_search tool constraints)
- Web searches work best with specific, current queries
- Voice analysis needs sufficient post history (30+ posts recommended)
- Post safety checks are advisory; use judgment for final decisions
- JSON output is best for agent/script consumption
- Text output is better for terminal/human reading
Troubleshooting
No results from X search:
- - Try broader query or longer date range
- Check if handles exist and are public
- Remove overly restrictive filters
Voice analysis incomplete:
- - Increase
--days to get more post history - Check if account is public and active
- Verify handle is correct (with or without @)
API rate limits:
- - xAI enforces rate limits per API key
- Spread requests over time if hitting limits
- Consider upgrading xAI plan for higher limits
Content Writing Workflow
Use the analysis tools to improve your X content:
CODEBLOCK35
Use the JSON output to:
- - Research current discussions and posting angles
- Learn from successful voices in your niche
- Catch AI signals and platform flags before publishing
xAI 技能
使用 xAI 的 API 搜索 X(Twitter)、搜索网页、与 Grok 模型(包括视觉模型)聊天,以及分析 X 内容模式。
功能特性
- - X 搜索:使用日期/账号过滤器搜索帖子、话题和账户
- 网页搜索:通过 Grok 的 web_search 工具搜索网页
- 聊天:与 Grok 模型进行文本和视觉(图像分析)对话
- 分析:语音模式、趋势研究、帖子安全检查
- 模型:列出可用的 xAI 模型
设置
API 密钥
从 console.x.ai 获取你的 xAI API 密钥。
bash
通过 clawdbot 配置(推荐)
clawdbot config set skills.entries.xai-plus.apiKey xai-YOUR-KEY
或环境变量
export XAI
APIKEY=xai-YOUR-KEY
脚本按以下顺序检查这些位置:
- 1. XAIAPIKEY 环境变量
- ~/.clawdbot/clawdbot.json → env.XAIAPIKEY
- ~/.clawdbot/clawdbot.json → skills.entries.xai-plus.apiKey
- ~/.clawdbot/clawdbot.json → skills.entries[grok-search].apiKey(回退)
默认模型(可选)
覆盖默认模型(grok-4-1-fast):
bash
通过配置
clawdbot config set skills.entries.xai-plus.model grok-3
或环境变量
export XAI_MODEL=grok-3
模型优先级:
- 1. 命令行 --model 标志(最高优先级)
- XAIMODEL 环境变量
- ~/.clawdbot/clawdbot.json → env.XAIMODEL
- ~/.clawdbot/clawdbot.json → skills.entries.xai-plus.model
- 默认值:grok-4-1-fast
搜索
X 搜索
使用可选过滤器搜索 X 帖子和话题。
基本搜索:
bash
node {baseDir}/scripts/grok_search.mjs 查询内容 --x
带日期过滤器:
bash
最近 7 天
node {baseDir}/scripts/grok_search.mjs Claude AI --x --days 7
指定日期范围
node {baseDir}/scripts/grok_search.mjs AI agents --x --from 2026-01-01 --to 2026-01-31
按账号过滤:
bash
仅来自特定账号
node {baseDir}/scripts/grok_search.mjs AI news --x --handles @AnthropicAI,@OpenAI
排除账号
node {baseDir}/scripts/grok_search.mjs GPT --x --exclude @spam1,@spam2
输出格式:
bash
JSON(默认,适合代理使用)
node {baseDir}/scripts/grok_search.mjs 查询内容 --x
仅链接
node {baseDir}/scripts/grok_search.mjs 查询内容 --x --links-only
人类可读文本
node {baseDir}/scripts/grok_search.mjs 查询内容 --x --text
JSON 输出模式:
json
{
query: 搜索查询,
mode: x,
results: [
{
title: @handle,
url: https://x.com/handle/status/123,
snippet: 帖子内容...,
author: @handle,
posted_at: 2026-01-15T10:30:00Z
}
],
citations: [https://x.com/...]
}
网页搜索
通过 Grok 搜索网页。
bash
node {baseDir}/scripts/grok_search.mjs TypeScript best practices 2026 --web
JSON 输出模式:
json
{
query: 搜索查询,
mode: web,
results: [
{
title: 页面标题,
url: https://example.com/page,
snippet: 描述...,
author: null,
posted_at: null
}
],
citations: [https://example.com/...]
}
搜索选项
| 标志 | 描述 | 示例 |
|---|
| --x | 搜索 X/Twitter | X 搜索必需 |
| --web |
搜索网页 | 网页搜索必需 |
| --days N | 最近 N 天(仅 X) | --days 7 |
| --from YYYY-MM-DD | 开始日期(仅 X) | --from 2026-01-01 |
| --to YYYY-MM-DD | 结束日期(仅 X) | --to 2026-01-31 |
| --handles a,b | 仅这些账号(仅 X) | --handles @user1,@user2 |
| --exclude a,b | 排除账号(仅 X) | --exclude @spam |
| --max N | 最大结果数 | --max 20 |
| --model ID | 覆盖模型 | --model grok-3 |
| --json | JSON 输出(默认) | - |
| --links-only | 仅 URL | - |
| --text | 人类可读 | - |
| --raw | 包含调试输出 | - |
高级查询模式和优化技巧请参见 references/search-patterns.md。
聊天
文本聊天
向 Grok 提问任何问题。
bash
node {baseDir}/scripts/chat.mjs 什么是量子计算?
带模型覆盖:
bash
node {baseDir}/scripts/chat.mjs --model grok-3 解释机器学习中的 Transformer
JSON 输出:
bash
node {baseDir}/scripts/chat.mjs --json 什么是 TypeScript?
JSON 模式:
json
{
model: grok-4-1-fast,
prompt: 什么是 TypeScript?,
text: TypeScript 是...,
citations: [https://...]
}
视觉聊天
使用 Grok 分析图像。
bash
node {baseDir}/scripts/chat.mjs --image ./screenshot.png 这张图片里有什么?
多张图片:
bash
node {baseDir}/scripts/chat.mjs --image ./pic1.jpg --image ./pic2.jpg 比较这些
支持的格式: JPG、PNG、WebP、GIF
聊天选项
| 标志 | 描述 | 示例 |
|---|
| --model ID | 使用的模型 | --model grok-2-vision-1212 |
| --image PATH |
附加图片(可重复) | --image ./pic.jpg |
| --json | JSON 输出 | - |
| --raw | 包含调试输出 | - |
模型比较和能力请参见 references/models.md。
分析
分析 X 内容的语音模式、趋势和帖子质量。
语音分析
分析账号的语音和写作模式。
bash
node {baseDir}/scripts/analyze.mjs voice @username
自定义日期范围:
bash
最近 60 天
node {baseDir}/scripts/analyze.mjs voice @username --days 60
JSON 输出模式:
json
{
handle: @username,
analyzed_posts: 150,
voice: {
tone: 随意、技术性,
personality: [好奇, 直接, 乐于助人],
perspective: 分享经验的实践者,
energy_level: 中等
},
patterns: {
sentence_structure: [简短陈述句, 偶尔片段句],
vocabulary: [技术性, 易懂],
formatting_quirks: [换行强调, 最少标点],
recurring_phrases: [关键是, 事实证明]
},
topics: [AI, 软件工程, 创业],
best_posts: [
{
url: https://x.com/username/status/123,
text: 帖子内容...,
why: 真实语音,具体示例
}
],
anti_patterns: [从不使用长破折号, 避免编号列表]