Grok の Live Search は X の検索APIみたいに使えるのか?
結論: 厳しそう
何の話?
2025年5月20日に Grok (xAI?) API の ChatCompletion エンドポイントに Live Search という機能が追加されました。
これは Grok でのテキスト生成時に自動でウェブ検索を行い、その結果を利用して回答することができるようになります
(いまどき当たり前じゃんと思われそうだけどAPIでそれに対応してるサービスは意外と少ない)
Gemini でいう Grounding、OpenAI でいう Web search Tool ですね
そして Grok は加えて X の検索もできるのが特徴です
昔と違って今の X はポストの取得制限が厳しいので基本大金払わないと X 内部の自由な検索はできないんですよね
Live Search の追加で X 内の検索が(LLM を介してだけど)低コストでできるようになったのでは!?
使う
使い方はリクエストパラメーターちょっと追加するだけです
このパラメーターは xAI 独自のものなので OpenAI SDK とかはたぶん使えないはず
import os
import requests
import json
from pprint import pprint as pp
API_KEY = "***"
url = "https://api.x.ai/v1/chat/completions"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}",
}
payload = {
"messages": [
{
"role": "user",
"content": "@blue_pen5805 が今一番気になっていることを教えてください。",
},
],
"search_parameters": {
"mode": "on",
"max_search_results": 30, # ← 検索結果の件数 / デフォルトは20件で最大30件
"sources": [ # ← 検索対象 / x 以外に web と news と rss が選べる(複数可)
{
"type": "x",
"x_handles": ["blue_pen5805"], # 対象ユーザーID / ← 指定しなかったら全ユーザーが対象になる
},
],
},
"model": "grok-3-fast-latest"
}
response = requests.post(url, headers=headers, json=payload)
pp(response.json())
{'choices': [{'finish_reason': 'stop',
'index': 0,
'message': {'content': '@blue_pen5805(ぶるぺん)が今一番気になっていることについて、Xの最新の投稿を基に推測すると、AI技術や画像生成ツールに関する話題が中心のようです。特に、直近の2025年5月22日の投稿では「Grok '
'API の Live Search '
'機能」を活用した検索方法について試してみた内容を述べており、技術的な実験や新しい機能への関心がうかがえます。また、5月21日の投稿では「Imagen '
'4」を試した感想を述べており、画像生成技術の進化に対する興味も見られます。\n'
'\n'
'ただし、これらの投稿は本人が「今一番気になっていること」を明言しているわけではなく、普段からAIや技術関連の話題を頻繁に扱っていることから推測したものです。明確に「一番気になっている」と特定することは難しいため、最新の技術やツールに対する探求心が強いと考えるのが妥当でしょう。',
'refusal': None,
'role': 'assistant'}}],
'citations': ['https://x.com/blue_pen5805/status/1775427545221284304',
'https://x.com/blue_pen5805/status/1883828880546689323',
'https://x.com/blue_pen5805/status/1776252758431285616',
'https://x.com/blue_pen5805/status/1885682548975825071',
'https://x.com/blue_pen5805/status/1902377377914884246',
'https://x.com/blue_pen5805/status/1902994351887982770',
'https://x.com/blue_pen5805/status/1745509877303402996',
'https://x.com/blue_pen5805/status/1866785716291899728',
'https://x.com/blue_pen5805/status/1906057351410626922',
'https://x.com/blue_pen5805/status/1891444324518547542',
'https://x.com/blue_pen5805/status/1853338749499048273',
'https://x.com/blue_pen5805/status/1746463212374217192',
'https://x.com/blue_pen5805/status/1747573154099462256',
'https://x.com/blue_pen5805/status/1805560494398619851',
'https://x.com/blue_pen5805/status/1609174743135182854',
'https://x.com/blue_pen5805/status/1714686742174007302',
'https://x.com/blue_pen5805/status/1885585525530386476',
'https://x.com/blue_pen5805/status/1802955673044422710',
'https://x.com/blue_pen5805/status/1720765966513222070',
'https://x.com/blue_pen5805/status/1757622466858635419',
'https://x.com/blue_pen5805/status/1607330388661215233',
'https://x.com/blue_pen5805/status/1609225844551192577',
'https://x.com/blue_pen5805/status/1609051853303566337',
'https://x.com/blue_pen5805/status/1924012814454395009',
'https://x.com/blue_pen5805/status/1924463272511820047',
'https://x.com/blue_pen5805/status/1924384669933715908',
'https://x.com/blue_pen5805/status/1923071355752173754',
'https://x.com/blue_pen5805/status/1923297761073488264',
'https://x.com/blue_pen5805/status/1924821027760308308',
'https://x.com/blue_pen5805/status/1925469069203087485'],
'created': 1747928798,
'id': '...',
'model': 'grok-3-fast',
'object': 'chat.completion',
'system_fingerprint': 'fp_3eff0197bc',
'usage': {'completion_tokens': 198,
'completion_tokens_details': {'accepted_prediction_tokens': 0,
'audio_tokens': 0,
'reasoning_tokens': 0,
'rejected_prediction_tokens': 0},
'prompt_tokens': 3806,
'prompt_tokens_details': {'audio_tokens': 0,
'cached_tokens': 0,
'image_tokens': 0,
'text_tokens': 3806},
'total_tokens': 4004}}
こんな感じで search_parameters
を指定するだけで勝手に検索してきます。
citations
に利用された検索結果が列挙されてますね。
上の例では指定してませんが日時での絞り込み検索にも対応しています。
で、何が厳しいのか
素人ながら以下の点が厳しい気がしました
最大で30件しか取れない
X のポストって1件1件がしょぼいので30件程度じゃ足りない!
これが一番ツラいポイント
検索ワードの構築がなんかそんなに頭よくない気がする
恐らく内部で検索クエリを思考してそれをもとに検索していると思いますが、全然関係ないだろみたいな検索結果が citations
に含まれていたりします。
X 内検索ではないですが、Web 検索で「@blue_pen5805 のことを調べて」と自分のプロフィールを調べさせたら何故かアダルト動画サイトが citations
に含まれていました。なんで?
(多分)フラグがついてるポストが検索対象にならない
いわゆるセンシティブなポストが対象になってない気がします
センシティブなAI画像を投稿している人のことを聞いたらまるで健全な人のような説明をされました
別に問題ないか!
(多分)ポストしか検索対象にならないから回答が微妙
ユーザーのプロフィールとかは見てくれないみたいです
また、あくまでそれぞれのポストを単体でしか見てないようなので回答が浅めになりがち
Live Search を使うとコストが増える
現時点(5/23)では無料ですが、2025年6月5日から有料になるとされています。
まだ価格は発表されてないので具体的にはわかりませんが Grok のコスト + Live Search のコストになるのは結構つらいかも?
Grok の価格も全く高いわけではないけど他社が安すぎる(主にgemini)ので相対的に高く見える問題があります
なので
現状だと使えるケースは限られているかなといった印象でした
まだ実装されたばかりなので今後の進化に期待!
おまけ
max_completion_tokens
を 1
にしてリクエストすると...
Live Search を有効にして LLM の出力コスト(completion_tokens
)がほぼ0円なのに citations
はちゃんと返ってくるので最低コストで検索だけ行える!!!
が、入力コスト(prompt_tokens
)に検索結果のトークン数が乗るみたいなのであんまり意味なさそうでした。
{'choices': [{'finish_reason': 'length',
'index': 0,
'message': {'content': '@',
'refusal': None,
'role': 'assistant'}}],
'citations': ['https://x.com/blue_pen5805/status/1747573154099462256',
'https://x.com/blue_pen5805/status/1776252758431285616',
'https://x.com/blue_pen5805/status/1902377377914884246',
'https://x.com/blue_pen5805/status/1609174743135182854',
'https://x.com/blue_pen5805/status/1891444324518547542',
'https://x.com/blue_pen5805/status/1775427545221284304',
'https://x.com/blue_pen5805/status/1853338749499048273',
'https://x.com/blue_pen5805/status/1607330388661215233',
'https://x.com/blue_pen5805/status/1609051853303566337',
'https://x.com/blue_pen5805/status/1885585525530386476',
'https://x.com/blue_pen5805/status/1906057351410626922',
'https://x.com/blue_pen5805/status/1902994351887982770',
'https://x.com/blue_pen5805/status/1802955673044422710',
'https://x.com/blue_pen5805/status/1885682548975825071',
'https://x.com/blue_pen5805/status/1745509877303402996',
'https://x.com/blue_pen5805/status/1883828880546689323',
'https://x.com/blue_pen5805/status/1866785716291899728',
'https://x.com/blue_pen5805/status/1746463212374217192',
'https://x.com/blue_pen5805/status/1757622466858635419',
'https://x.com/blue_pen5805/status/1805560494398619851',
'https://x.com/blue_pen5805/status/1609225844551192577',
'https://x.com/blue_pen5805/status/1714686742174007302',
'https://x.com/blue_pen5805/status/1720765966513222070',
'https://x.com/blue_pen5805/status/1924384669933715908',
'https://x.com/blue_pen5805/status/1924012814454395009',
'https://x.com/blue_pen5805/status/1923297761073488264',
'https://x.com/blue_pen5805/status/1924463272511820047',
'https://x.com/blue_pen5805/status/1925049383906893883',
'https://x.com/blue_pen5805/status/1924821027760308308',
'https://x.com/blue_pen5805/status/1923071355752173754'],
'created': 1747930568,
'id': '...',
'model': 'grok-3-fast',
'object': 'chat.completion',
'system_fingerprint': 'fp_3eff0197bc',
'usage': {'completion_tokens': 1,
'completion_tokens_details': {'accepted_prediction_tokens': 0,
'audio_tokens': 0,
'reasoning_tokens': 0,
'rejected_prediction_tokens': 0},
'prompt_tokens': 3798,
'prompt_tokens_details': {'audio_tokens': 0,
'cached_tokens': 0,
'image_tokens': 0,
'text_tokens': 3798}, # ← 検索しなかったら 18 なので自動で 3780 盛られている
'total_tokens': 3799}}
Web 検索で safe_search を OFF にすると...
成人向けサイトとかもガッツリ検索して回答してくれます。これは他のサービスにはないかも?
なおガッツリすぎて検索できてるのに恥ずかしがって教えてくれないパターンも割とあります
Discussion