X Tool enables agents to post content, reply to posts, create quote posts, manage polls, upload media, and interact with X (formerly Twitter) using the official X API v2.Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start
Get started with X Tool in three simple steps.Installation
Install the required packages to get started with X Tool.How It Works
X Tool supports three authentication modes for different use cases.| Mode | Use Case | Can Post | Can Read | Setup Required |
|---|---|---|---|---|
| OAuth 1.0a User | Full access (recommended) | ✅ | ✅ | X Developer Portal |
| OAuth 2.0 User Bearer | Read-only access | ❌ | ✅ | X Developer Portal |
| App-only Bearer | Public data only | ❌ | ✅ | X Developer Portal |
OAuth 1.0a Setup (Recommended for Posting)
Create X Developer Account
Visit developer.x.com and create a developer account.
Create App and Get Keys
- Create a new app in the X Developer Portal
- Generate API Key and API Key Secret
- Enable OAuth 1.0a with read/write permissions
- Generate Access Token and Access Token Secret
Configuration Options
Configure X Tool with your API credentials and preferences.| Option | Type | Default | Description |
|---|---|---|---|
api_key | str | None | X API key (from env var X_API_KEY if not provided) |
api_key_secret | str | None | X API secret (from env var X_API_SECRET if not provided) |
access_token | str | None | OAuth access token (from env var X_ACCESS_TOKEN if not provided) |
access_token_secret | str | None | OAuth access token secret (from env var X_ACCESS_SECRET if not provided) |
XTool Class
XTool.post() Parameters
The text content of the post (up to 280 characters for basic accounts)
ID of post to reply to
ID of post to quote (Enterprise plan required)
List of uploaded media IDs to attach
List of local file paths to upload and attach
Poll choices (2-4 options, each up to 25 chars)
Poll duration in minutes (5-10080, default 24 hours)
Function Helpers
| Function | Description | Returns |
|---|---|---|
post_to_x(text, **kwargs) | Create a new post | Post ID and URL |
reply_to_x(post_id, text, **kwargs) | Reply to a post | Reply ID and URL |
quote_x_post(post_id, text, **kwargs) | Quote a post | Quote ID and URL |
delete_x_post(post_id) | Delete a post | Success status |
search_x(query, **kwargs) | Search posts | Search results |
get_x_user(username) | Get user info | User data |
Common Patterns
- Simple Post
- Post with Media
- Thread Creation
- Poll Creation
Agent Integration Patterns
- Customer Support Bot
- Content Curator
Authentication Flow Diagram
Best Practices
Use OAuth 1.0a for Posting
Use OAuth 1.0a for Posting
OAuth 1.0a provides full posting capabilities, while app-only bearer tokens are read-only.
Handle Rate Limits Gracefully
Handle Rate Limits Gracefully
Implement exponential backoff to handle rate limits (300 posts per 15 minutes).
Manage Character Limits
Manage Character Limits
Split long content into threaded posts for better readability.
Secure Credential Management
Secure Credential Management
Store credentials in environment variables rather than hardcoding them.
Premium Features
Some features require X Premium or Enterprise plans:
- Extended character limits (Premium: up to 25,000 characters)
- Advanced search operators (Premium)
Related
Tools Overview
Explore all available PraisonAI tools
Slack Integration
Send messages to Slack channels
Telegram Bot
Send messages via Telegram bots
Custom Tools
Create your own custom tools

