xai-x-search について
xAIのGrok連携を使ってXをリアルタイム検索するスキルです。話題、アカウント、市場動向を追う分析担当者向けで、投稿やセンチメントの要約にも対応します。
主な機能
- 01話題や株式銘柄の投稿を検索
- 02指定アカウントの最新投稿を監視
- 03Xのトレンドを取得
- 04アカウントや日付で絞り込み
- 05画像や動画を分析
活用シーン
- 01金融ニュースや決算への反応を追跡
- 02銘柄ごとのセンチメントを比較
- 03指定アカウントの最新動向を監視
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ adaptationio/ skrillz --skill xai-x-searchインストール後、Claude Code で/xai-x-searchを入力して読み込まれたか確認します。
詳細
xAI X(Twitter)検索
Grok の X ネイティブ統合を利用したリアルタイムの Twitter/X 検索です。これは xAI に固有の機能です。
クイックスタート
import os
from openai import OpenAI
client = OpenAI(
api_key=os.getenv("XAI_API_KEY"),
base_url="https://api.x.ai/v1"
)
# Simple X search
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": "Search X for what people are saying about Tesla stock today"
}]
)
print(response.choices[0].message.content)
検索機能
1. トピック検索
def search_x_topic(topic: str) -> str:
"""Search X for posts about a topic."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": f"Search X for recent posts about {topic}. Summarize the main discussions and sentiment."
}]
)
return response.choices[0].message.content
2. ティッカー/株式検索
def search_stock_mentions(ticker: str) -> str:
"""Search X for stock ticker mentions."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": f"""Search X for mentions of ${ticker} stock.
Find:
- Recent discussions
- Sentiment (bullish/bearish)
- Key influencer opinions
- Breaking news mentions
Return structured analysis."""
}]
)
return response.choices[0].message.content
3. アカウントのモニタリング
def monitor_account(handle: str) -> str:
"""Get recent posts from a specific X account."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": f"Search X for the most recent posts from @{handle}. Summarize their latest activity."
}]
)
return response.choices[0].message.content
4. トレンドトピック
def get_trending() -> str:
"""Get current trending topics on X."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": "What are the current trending topics on X? List the top 10 with brief descriptions."
}]
)
return response.choices[0].message.content
Agent Tools API(上級者向け)
より細かく制御するには、Agent Tools API を使用します。
# Using Responses API with x_search tool
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": "Search X for posts about Bitcoin from the last 24 hours"
}],
tools=[{
"type": "x_search",
"x_search": {
"enabled": True,
"date_range": {
"start": "2025-12-04",
"end": "2025-12-05"
}
}
}]
)
ハンドルで絞り込む
# Search only specific accounts
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": "What are these financial analysts saying about the market?"
}],
tools=[{
"type": "x_search",
"x_search": {
"enabled": True,
"allowed_x_handles": [
"jimcramer",
"elonmusk",
"chaikinadx",
"unusual_whales"
]
}
}]
)
よくあるユースケース
金融ニュースのモニタリング
def monitor_financial_news() -> dict:
"""Monitor financial news on X."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": """Search X for breaking financial news in the last hour.
Focus on:
- Market-moving news
- Earnings announcements
- Fed/economic news
- Major analyst calls
Return as JSON:
{
"breaking_news": [...],
"market_sentiment": "bullish/bearish/neutral",
"key_events": [...]
}"""
}]
)
return response.choices[0].message.content
決算発表への反応の追跡
def track_earnings_reaction(ticker: str) -> str:
"""Track X reaction to earnings announcement."""
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": f"""Search X for reaction to ${ticker} earnings.
Analyze:
- Overall sentiment
- Key concerns raised
- Positive highlights mentioned
- Notable influencer reactions
- Volume of discussion"""
}]
)
return response.choices[0].message.content
競合分析
def compare_sentiment(tickers: list) -> str:
"""Compare X sentiment across multiple stocks."""
ticker_str = ", ".join([f"${t}" for t in tickers])
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{
"role": "user",
"content": f"""Compare X sentiment for: {ticker_str}
For each, provide:
- Current sentiment score (-1 to +1)
- Key themes being discussed
- Notable mentions
Return as structured comparison."""
}]
)
return response.choices[0].message.content
検索パラメーター
| パラメーター | 説明 | 最大値 |
|---|---|---|
allowed_x_handles | これらのアカウントのみを検索します | 10 |
excluded_x_handles | これらのアカウントを除外します | 10 |
date_range.start | 開始日(ISO8601) | - |
date_range.end | 終了日(ISO8601) | - |
include_media | 画像/動画を分析します | - |
レート制限と料金
| 指標 | 値 |
|---|---|
| 検索あたりの料金 | $0.005(1,000 件あたり $5) |
| ハンドルフィルターの最大数 | 10 |
| 日付範囲 | 任意 |
ベストプラクティス
1. 具体的に指定する
# Bad - too vague
"Search X for stocks"
# Good - specific query
"Search X for posts about $AAPL stock price movement today from verified financial accounts"
2. 構造化された出力をリクエストする
# Request JSON for easier parsing
content = """Search X for $NVDA sentiment. Return JSON:
{
"sentiment": "bullish/bearish/neutral",
"score": -1 to 1,
"key_posts": [...],
"influencer_opinions": [...]
}"""
3. ハンドルフィルターを使って精度を高める
# Filter to trusted sources
financial_handles = [
"DeItaone", # Breaking news
"unusual_whales", # Options flow
"Fxhedgers", # Market news
"zaborsky" # Analysis
]
4. 他のデータと組み合わせる
# Combine X sentiment with price data
x_sentiment = search_stock_mentions("AAPL")
price_data = finnhub_client.get_quote("AAPL")
# Analyze together
制限事項
- 皮肉の検出 - 皮肉を含む投稿を誤って解釈する場合があります
- ボットのコンテンツ - ボットの投稿を常に除外できるとは限りません
- 過去データの範囲 - 最近のデータに最適です
- レート制限 - 検索 1,000 件あたり $5
エラー処理
def safe_x_search(query: str) -> dict:
"""X search with error handling."""
try:
response = client.chat.completions.create(
model="grok-4-1-fast",
messages=[{"role": "user", "content": query}],
timeout=30
)
return {
"success": True,
"data": response.choices[0].message.content
}
except Exception as e:
return {
"success": False,
"error": str(e)
}
関連スキル
xai-sentiment- センチメント分析xai-stock-sentiment- 株式に特化したセンチメント分析xai-agent-tools- 高度なツールの使用
参考資料
コメント
Markdown 対応