# X.com

> Connect X.com (formerly Twitter) to your agents.

**URL:** https://inference.sh/docs/credentials/x
**Last updated:** 2026-09-24

---

Connect X.com (formerly Twitter) to your agents.

---

## Overview

X.com credentials let 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:

1. An X.com (Twitter) account
2. A verified phone number on that account
3. An X Developer account (free tier available)
4. An X Developer app with OAuth 2.0 configured

---

## Step 1: Create an X Developer Account

1. Go to the [X Developer Portal](https://developer.x.com/)
2. Click **Sign up** (or **Sign in** if you have an account)
3. Complete the application:
   - Describe your use case (e.g., "Building AI agents to help manage social media")
   - Agree to the Developer Agreement
4. Wait for approval (usually instant for free tier)

---

## Step 2: Create a Project and App

1. In the Developer Portal, go to **Projects & Apps**
2. Click **+ Create Project**
3. Name your project (e.g., "Inference.sh Agents")
4. Select your use case
5. Click **Create App**
6. Name your app (e.g., "My Agent Bot")
7. Save your **API Key** and **API Secret** — you'll need these

---

## Step 3: Configure OAuth 2.0

1. In your app settings, go to **User authentication settings**
2. Click **Set up**
3. 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) |

4. Click **Save**
5. Copy your **Client ID** and **Client Secret**

> **Important:** The callback URI must match exactly, including the `/x` at the end which identifies the provider.

---

## Step 4: Connect in inference shell

### Configure credentials

1. Go to **vaults → credentials**
2. Find **X.com** and click **Configure**
3. Enter your OAuth 2.0 credentials from Step 3:
   - **Client ID**
   - **Client Secret**
4. Click **Save credentials**

> These are stored securely as encrypted secrets (`X_CLIENT_ID` and `X_CLIENT_SECRET`).

### Authorize the connection

1. Click **Connect** (now available after configuring)
2. You'll be redirected to X.com to authorize
3. Review the permissions and click **Authorize app**
4. Done! Your X.com credential 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:

```yaml
# inf.yml
credentials:
  - key: x.tweet.write
    description: Post automated tweets

  - key: x.dm.read
    description: Read incoming DMs
    optional: true
```

At runtime, your app receives:

```bash
X_ACCESS_TOKEN=oauth2-access-token
X_ACCESS_TOKEN_EXPIRES_AT=2024-01-15T10:30:00Z
```

### Example: Post a tweet

```python
import tweepy
import os

# OAuth 2.0 user context
client = tweepy.Client(bearer_token=os.environ["X_ACCESS_TOKEN"])

client.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](https://developer.x.com/en/portal/products).

---

## 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](https://twitter.com/settings/connected_apps) or in inference shell

---

## 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 `/x` provider suffix

### "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.

---

## Next

→ [Back to Credentials Overview](/docs/credentials/overview)
→ [Slack](/docs/credentials/slack)

