Enable X Search in the API
On this page
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.
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()]
Combine X Search and Web Search
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.
Key differences from Web Search
| Feature | Web Search | X Search |
|---|---|---|
| Source | Entire web | X/Twitter only |
| Filtering | By domain (5 max) | By handle (10 max) |
| Dates | Unavailable | from_date / to_date |
| Images | enable_image_understanding | enable_image_understanding |
| Video | Unavailable | enable_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 thetoolsarray - Four search modes: keywords, semantic, users, threads
- Combinable with Web Search to cross-reference information
- Supports image and video understanding (exclusive)