Skip to main content
Lesson 8 of 16 · Integrated Tools: Web, X, Code

Enable X Search in the API

Lesson 8 of 16 Updated July 30, 2026 Developer
On this page
  1. Access X data in real time
  2. X Search capabilities
  3. Basic activation
  4. SDK activation
  5. Combine X Search and Web Search
  6. Key differences from Web Search
  7. Key takeaways

Access X data in real time

X Search is a unique built-in tool specific to the Grok API. It lets the model search for posts, profiles, and threads on X (formerly Twitter) in real time. This gives Grok a significant competitive edge over other language model APIs, which typically lack direct access to social networks.

𝕏
Native search
10
Filterable handles
🎥
Video supported
$5
/ 1,000 calls

X Search capabilities

X Search offers four search modes:

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

The model automatically chooses the mode best suited to the user’s request.

Basic activation

Activation works the same way as Web Search. You add {"type": "x_search"} to the tools array:

{
  "model": "grok-4.20-0309-reasoning",
  "input": "What are developers saying about the latest React update?",
  "tools": [
    {"type": "x_search"}
  ]
}

The model automatically searches X for relevant posts and integrates them into its response, with corresponding citations.

SDK activation

xAI SDK (Python)

response = client.responses.create(
    model="grok-4.20-0309-reasoning",
    input="What are the reactions on X about Grok 4?",
    tools=[client.tools.x_search()]
)

OpenAI SDK (Python)

response = client.responses.create(
    model="grok-4.20-0309-reasoning",
    input="What are the reactions on X about Grok 4?",
    tools=[{"type": "x_search"}]
)

Vercel AI SDK (JavaScript)

tools: [xai.tools.xSearch()]

You can enable both tools simultaneously so the model cross-references information from the web and social networks:

{
  "tools": [
    {"type": "web_search"},
    {"type": "x_search"}
  ]
}

The model decides which one to use—or both—based on the question asked. A question about public opinion favors X Search, while a factual question favors Web Search.

FeatureWeb SearchX Search
SourceEntire webX/Twitter only
FilteringBy domain (5 max)By handle (10 max)
DatesUnavailablefrom_date / to_date
Imagesenable_image_understandingenable_image_understanding
VideoUnavailableenable_video_understanding
Cost$5 / 1,000 calls$5 / 1,000 calls

Video understanding is exclusive to X Search. This feature lets the model analyze the content of videos posted on X.

Pricing as of August 5, 2026 — prices change regularly: before calculating any budget, check the current pricing table on the official xAI models and pricing page.

Key takeaways

  • X Search is an exclusive advantage of the Grok API
  • Activation uses {"type": "x_search"} in the tools array
  • Four search modes: keywords, semantic, users, threads
  • Combinable with Web Search to cross-reference information
  • Supports image and video understanding (exclusive)