x_search
Search and analyze X content using Grok's AI to extract insights from posts, images, and videos with customizable filters.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | ||
| model | No | grok-4-1-fast-reasoning | |
| allowed_x_handles | No | ||
| excluded_x_handles | No | ||
| from_date | No | ||
| to_date | No | ||
| enable_image_understanding | No | ||
| enable_video_understanding | No | ||
| include_inline_citations | No | ||
| max_turns | No |
Implementation Reference
- src/server.py:294-327 (handler)Implementation of the x_search tool handler in src/server.py.
async def x_search( prompt: str, model: str = "grok-4-1-fast-reasoning", allowed_x_handles: Optional[List[str]] = None, excluded_x_handles: Optional[List[str]] = None, from_date: Optional[str] = None, to_date: Optional[str] = None, enable_image_understanding: bool = False, enable_video_understanding: bool = False, include_inline_citations: bool = False, max_turns: Optional[int] = None ): if allowed_x_handles and excluded_x_handles: raise ValueError("Cannot specify both allowed_x_handles and excluded_x_handles") if allowed_x_handles and len(allowed_x_handles) > 10: raise ValueError("allowed_x_handles max 10") if excluded_x_handles and len(excluded_x_handles) > 10: raise ValueError("excluded_x_handles max 10") client = Client(api_key=XAI_API_KEY) tool_params = build_params( allowed_x_handles=allowed_x_handles, excluded_x_handles=excluded_x_handles, from_date=datetime.strptime(from_date, "%d-%m-%Y") if from_date else None, to_date=datetime.strptime(to_date, "%d-%m-%Y") if to_date else None, enable_image_understanding=enable_image_understanding, enable_video_understanding=enable_video_understanding, ) include_options = [] if include_inline_citations: include_options.append("inline_citations")