Skip to main content
Lesson 5 of 14 · Real-Time Web & X Search

Enable X Search for Twitter Research

Lesson 5 of 14 Updated July 30, 2026 Beginner
On this page
  1. Access X’s Real-Time Feed from Your API
  2. Enable X Search
  3. The Four Capabilities of X Search
  4. Usage with Different SDKs
  5. Combine web_search and x_search
  6. Hands-On Practice
  7. Key Takeaways

Access X’s Real-Time Feed from Your API

X (formerly Twitter) remains the go-to platform for real-time information: company announcements, reactions to news, emerging trends, and public debates. Grok API’s x_search tool lets you query this feed directly from your applications, without needing a separate X API subscription or managing additional subscriptions.

X Search with Grok

Where the legacy Chat Completions endpoint offered a sources: ["x"] parameter in search_parameters, the Responses API provides a dedicated tool with much finer filtering capabilities.

10
filterable handles
4
search types
$5
per 1,000 calls
Video
exclusive analysis

Enabling it follows the same principle as web_search. You add the x_search tool to the tools array:

response = client.responses.create(
    model="grok-4.5",
    input="What are people saying about the AI Act on X today?",
    tools=[{"type": "x_search"}]
)

print(response.output_text)

The model automatically decides when to query X based on the nature of your prompt. Questions about current events, public opinion, or trends will naturally trigger search.

The x_search tool goes beyond simple keyword search. It offers four query modes:

  • Keyword search: find posts containing specific terms
  • Semantic search: find posts related to a concept, even without exact words
  • User search: identify relevant accounts on a topic
  • Thread retrieval: reconstruct complete discussion threads

The model automatically chooses the most appropriate mode based on your request. You don’t need to specify which mode to use explicitly.

Usage with Different SDKs

xAI SDK (Python)

from xai_sdk.tools import x_search

response = client.chat.create(
    model="grok-4.5",
    tools=[x_search()]
)

OpenAI SDK Compatible

response = client.responses.create(
    model="grok-4.5",
    input="Tech trends on X this week",
    tools=[{"type": "x_search"}]
)

Vercel AI SDK (JavaScript)

import { xai } from '@ai-sdk/xai';

const response = await generateText({
  model: xai.responses('grok-4.5'),
  prompt: 'Tech trends on X this week',
  tools: [xai.tools.xSearch()]
});

You can enable both tools simultaneously to get a complete view of a topic. The model will choose the most relevant tool, or use both if necessary:

response = client.responses.create(
    model="grok-4.5",
    input="Complete analysis of the latest Apple keynote",
    tools=[
        {"type": "web_search"},
        {"type": "x_search"}
    ]
)

In this case, the model might search for press articles via web_search and real-time reactions via x_search, then synthesize both perspectives in its response.

Hands-On Practice

Create a script that uses x_search to monitor discussions around a professional topic that interests you. Test with current event queries and observe how the model synthesizes opinions and facts from X.

Key Takeaways

  • The x_search tool activates with {"type": "x_search"} in the tools array
  • It supports four search types: keywords, semantic, users, and threads
  • Cost is identical to web_search: $5 per 1,000 calls
  • Both tools can be enabled simultaneously for complete coverage
  • Video understanding is an x_search exclusive (absent from web_search)