home / skills / openclaw / skills / xai-search

xai-search skill

This skill helps you search X/Twitter and the web in real-time using Grok API, delivering fresh results for dynamic queries.

npx playbooks add skill openclaw/skills --skill xai-search

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
2.9 KB
---
name: xai-search
description: Search X/Twitter and the web in real-time using xAI's Grok API with agentic search tools.
metadata: {"clawdbot":{"emoji":"🔍"}}
---

# 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: `pip install xai-sdk`

## Quick Usage (curl)

### Web Search
```bash
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
```bash
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)
```bash
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:

```bash
# 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 searches
- `grok-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 accounts
- `from_date` / `to_date` — date range (ISO8601 format)
- `enable_image_understanding` — analyze images in posts
- `enable_video_understanding` — analyze videos in posts

## Web Search Filters

- `allowed_domains` / `excluded_domains` — limit to specific sites
- `enable_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

This skill lets you search X/Twitter and the web in real time using xAI's Grok agentic search tools. It combines Grok's web_search and x_search tools so an agent can decide which sources to query and aggregate results for fast, contextual answers. It requires an XAI_API_KEY and the xai-sdk installed.

How this skill works

The skill calls xAI's chat/completions endpoint with tools enabled for web_search and x_search. The Grok agent can perform multiple tool calls, filter results, and synthesize findings into a single response. You can run web-only, X-only, or combined searches, and adjust model choice between fast and reasoning variants.

When to use it

  • Breaking news and live reactions where X provides immediate signals
  • Research or factual queries that need authoritative web sources
  • Sentiment and opinion analysis across public posts
  • Combined context where both news articles and social reaction matter
  • Automated workflows that need agentic multi-step search and synthesis

Best practices

  • Set XAI_API_KEY in your environment and install xai-sdk via pip before running
  • Choose grok-3-fast for quick lookups and grok-4-1-fast for in-depth reasoning
  • Use filters (allowed/excluded domains or handles, date ranges) to reduce noise
  • Enable image/video understanding only when media analysis is required to save API calls
  • Use the helper script for simple CLI usage or integrate the curl patterns into your automation

Example use cases

  • Monitor real-time reactions to a product launch by combining web articles and X posts
  • Compile a factual briefing on a breaking event using web_search plus eyewitness posts from X
  • Track sentiment trends for a hashtag with filters for date and specific handles
  • Automate a daily digest that pulls top news and relevant social commentary
  • Research niche topics by restricting allowed_domains and combining web and X results

FAQ

What credentials are required?

You need an XAI_API_KEY set in your environment and Python with the xai-sdk installed.

Which model should I pick?

Use grok-3-fast for speed and grok-4-1-fast for complex reasoning tasks.

Can I filter results?

Yes. You can filter X searches by handles, date ranges, and media analysis, and web searches by allowed/excluded domains and media options.