Connect X.com (formerly Twitter) to your agents.
Overview
The X.com integration lets your agents post tweets, read timelines, manage follows, and interact with the X API v2.
Why "Bring Your Own Key" (BYOK)?
X.com's API has strict rate limits and requires developer account approval. Instead of sharing our API quota across all users (which would quickly hit limits), you use your own X Developer app credentials.
Benefits:
- Your own rate limits — not shared with other users
- Full control — you decide what permissions to grant
- Direct billing — API costs go to your X developer account
Prerequisites
Before connecting, you'll need:
- An X.com (Twitter) account
- A verified phone number on that account
- An X Developer account (free tier available)
- An X Developer app with OAuth 2.0 configured
Step 1: Create an X Developer Account
- Go to the X Developer Portal
- Click Sign up (or Sign in if you have an account)
- Complete the application:
- Describe your use case (e.g., "Building AI agents to help manage social media")
- Agree to the Developer Agreement
- Wait for approval (usually instant for free tier)
Step 2: Create a Project and App
- In the Developer Portal, go to Projects & Apps
- Click + Create Project
- Name your project (e.g., "Inference.sh Agents")
- Select your use case
- Click Create App
- Name your app (e.g., "My Agent Bot")
- Save your API Key and API Secret — you'll need these
Step 3: Configure OAuth 2.0
- In your app settings, go to User authentication settings
- Click Set up
- Configure these settings:
App permissions
Choose based on what you need:
| Permission | Allows |
|---|---|
| Read | Read tweets and profile info |
| Read and write | Read + post tweets |
| Read, write, and Direct message | Full access including DMs |
Type of App
Select Web App, Automated App or Bot (Confidential client)
App info
| Field | Value |
|---|---|
| Callback URI | https://app.inference.sh/settings/secrets/oauth/x |
| Website URL | Your website or https://inference.sh |
| Terms of service | (optional) |
| Privacy policy | (optional) |
- Click Save
- Copy your Client ID and Client Secret
Important: The callback URI must match exactly, including the
/xat the end which identifies the provider.
Step 4: Connect in inference.sh
Configure credentials
- Go to Settings → Secrets → Integrations
- Find X.com and click Configure
- Enter your OAuth 2.0 credentials from Step 3:
- Client ID
- Client Secret
- Click Save credentials
These are stored securely as encrypted secrets (
X_CLIENT_IDandX_CLIENT_SECRET).
Authorize the connection
- Click Connect (now available after configuring)
- You'll be redirected to X.com to authorize
- Review the permissions and click Authorize app
- Done! Your X.com integration is now active.
Capabilities
| Capability | Description | Required Scopes |
|---|---|---|
x.tweet.read | Read tweets | tweet.read, users.read |
x.tweet.write | Post tweets | tweet.read, tweet.write, users.read |
x.user.read | Read user profiles | users.read |
x.follow.read | Read followers/following | follows.read, users.read |
x.follow.write | Follow/unfollow users | follows.write, users.read |
x.dm.read | Read direct messages | dm.read, users.read |
x.dm.write | Send direct messages | dm.write, users.read |
x.like.read | Read liked tweets | like.read, users.read |
x.like.write | Like/unlike tweets | like.write, users.read |
Using in apps
Declare X.com requirements in your app:
1requirements:2 integrations:3 - key: x.tweet.write4 description: Post automated tweets5 6 - key: x.dm.read7 description: Read incoming DMs8 optional: trueAt runtime, your app receives:
1X_ACCESS_TOKEN=oauth2-access-token2X_ACCESS_TOKEN_EXPIRES_AT=2024-01-15T10:30:00ZExample: Post a tweet
1import tweepy2import os3 4# OAuth 2.0 user context5client = tweepy.Client(bearer_token=os.environ["X_ACCESS_TOKEN"])6 7client.create_tweet(text="Hello from my AI agent! 🤖")Rate Limits
X.com has strict rate limits. Free tier includes:
| Endpoint | Limit |
|---|---|
| POST tweets | 50/day |
| GET tweets | 100/month |
| GET users | 100/month |
For higher limits, consider X's Basic or Pro tiers.
Security
- Your credentials — API keys are encrypted at rest
- Scoped access — OAuth 2.0 with PKCE for secure authorization
- Revocable — revoke access from X's app settings or in inference.sh
Troubleshooting
"Callback URL mismatch"
- Ensure the callback URL in your X app settings matches exactly:
- Production:
https://app.inference.sh/settings/secrets/oauth/x - The URL is case-sensitive and must include the
/xprovider suffix
- Production:
"Rate limit exceeded"
- Check your X Developer dashboard for current usage
- Consider upgrading your X API tier
- Space out requests in your agent logic
"Invalid credentials"
- Verify your API Key, API Secret, Client ID, and Client Secret
- Make sure you copied the full values without extra spaces
- Regenerate credentials if needed
"App not approved"
- Some X API features require app approval
- Check the Developer Portal for any pending reviews
Callback URLs
Each provider has its own callback URL under the settings path:
| Environment | Callback URL |
|---|---|
| Production | https://app.inference.sh/settings/secrets/oauth/x |
| Staging | https://app.staging.inference.sh/settings/secrets/oauth/x |
| Local dev | http://localhost:3000/settings/secrets/oauth/x |
You can add multiple callback URLs in your X app settings to support different environments.