xAI Search
@aydencook03
npx machina-cli add skill @aydencook03/xai-search --openclawxAI 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_KEYenvironment variable- Python 3 + xai-sdk:
pip install xai-sdk
Quick Usage (curl)
Web Search
curl -s https://api.x.ai/v1/chat/completions \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-3-fast",
"messages": [{"role": "user", "content": "YOUR QUERY HERE"}],
"tools": [{"type": "function", "function": {"name": "web_search"}}]
}' | jq -r '.choices[0].message.content'
X/Twitter Search
curl -s https://api.x.ai/v1/chat/completions \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-3-fast",
"messages": [{"role": "user", "content": "YOUR QUERY HERE"}],
"tools": [{"type": "function", "function": {"name": "x_search"}}]
}' | jq -r '.choices[0].message.content'
Combined (Web + X)
curl -s https://api.x.ai/v1/chat/completions \
-H "Authorization: Bearer $XAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-3-fast",
"messages": [{"role": "user", "content": "YOUR QUERY HERE"}],
"tools": [
{"type": "function", "function": {"name": "web_search"}},
{"type": "function", "function": {"name": "x_search"}}
]
}' | jq -r '.choices[0].message.content'
Helper Script
For convenience, use the xai-search.py script in the scripts/ folder:
# Web search (adjust path to your skill location)
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py web "latest news about AI"
# X/Twitter search
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py x "what are people saying about Clawdbot"
# Both
python ~/.clawdbot/skills/xai-search/scripts/xai-search.py both "current events today"
Models
grok-3-fast— fast, good for quick searchesgrok-4-1-fast— reasoning model, better for complex queries
X Search Filters
You can filter X searches by:
allowed_x_handles/excluded_x_handles— limit to specific accountsfrom_date/to_date— date range (ISO8601 format)enable_image_understanding— analyze images in postsenable_video_understanding— analyze videos in posts
Web Search Filters
allowed_domains/excluded_domains— limit to specific sitesenable_image_understanding— 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)
Overview
xAI Search lets you query X/Twitter and the web in real time via Grok API. It leverages agentic tools (web_search and x_search) with fast or reasoning models (grok-3-fast and grok-4-1-fast) to pull fresh results. This enables real-time monitoring, competitive intel, and research that spans social and web sources.
How This Skill Works
Send a natural language query to the Grok API. Choose tools: web_search, x_search, or both, to fetch web pages and X/Twitter data. Apply filters for domains, handles, dates, and media understanding; the model may issue multiple search calls to gather diverse results.
When to Use It
- Real-time breaking news and trends
- Brand or competitor monitoring across X/Twitter and the web
- Sentiment analysis from social chatter plus corroborating sources
- Fact-checking or research requiring multiple sources and dates
- Product launch tracking or issue monitoring with domain/date filters
Quick Start
- Step 1: Export XAI_API_KEY and install the SDK (e.g., pip install xai-sdk)
- Step 2: Run a query with web_search, x_search, or both (via API or xai-search.py)
- Step 3: Apply filters (domains, handles, dates) and review the combined results
Best Practices
- Start with broad queries and iteratively narrow using filters (domains, handles, dates)
- Use both web_search and x_search for balanced coverage
- Prefer grok-3-fast for quick answers; switch to grok-4-1-fast for complex queries
- Validate results by cross-referencing sources and dates across tools
- Leverage the xai-search.py helper for common tasks and automation
Example Use Cases
- Monitor a breaking AI policy story by pulling recent posts from X and related articles from top domains
- Track customer sentiment about a new product launch across X/Twitter and the web
- Research a topic with multi-domain results including news, blogs, and official docs
- Verify a claim by cross-checking dates and sources from multiple outlets
- Track ongoing events with date filters and image/video understanding when available