Documentation Index
Fetch the complete documentation index at: https://docs.x.com/llms.txt
Use this file to discover all available pages before exploring further.
The TypeScript XDK is the official client library for the X API v2. Full type safety, automatic pagination, and event-driven streaming.
GitHub repository
Source code, issues, and releases.
Installation
npm install @xdevplatform/xdk
Requires Node.js 16+ and TypeScript 4.5+ (if using TypeScript).
Quick start
import { Client } from '@xdevplatform/xdk';
const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });
const userResponse = await client.users.getByUsername('XDevelopers');
console.log(userResponse.data?.username);
Key features
| Feature | Description |
|---|
| Type safety | Complete TypeScript definitions for all endpoints and parameters |
| Authentication | Bearer Token, OAuth 2.0 with PKCE, and OAuth 1.0a |
| Automatic pagination | Async iteration support for paginated endpoints |
| Streaming | Event-driven streaming with automatic reconnection |
| Full API coverage | Users, Posts, Lists, Bookmarks, Communities, and more |
Authentication
Bearer Token
OAuth 2.0
OAuth 1.0a
import { Client } from '@xdevplatform/xdk';
const client = new Client({ bearerToken: 'YOUR_BEARER_TOKEN' });
import { Client, OAuth2, generateCodeVerifier, generateCodeChallenge } from '@xdevplatform/xdk';
const oauth2 = new OAuth2({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
redirectUri: 'https://your-app.com/callback',
scope: ['tweet.read', 'users.read', 'offline.access'],
});
const codeVerifier = generateCodeVerifier();
const codeChallenge = await generateCodeChallenge(codeVerifier);
oauth2.setPkceParameters(codeVerifier, codeChallenge);
const authUrl = await oauth2.getAuthorizationUrl('state');
const tokens = await oauth2.exchangeCode(authCode, codeVerifier);
const client = new Client({ accessToken: tokens.access_token });
import { Client, OAuth1 } from '@xdevplatform/xdk';
const oauth1 = new OAuth1({
apiKey: 'YOUR_API_KEY',
apiSecret: 'YOUR_API_SECRET',
accessToken: 'YOUR_ACCESS_TOKEN',
accessTokenSecret: 'YOUR_ACCESS_TOKEN_SECRET'
});
const client = new Client({ oauth1: oauth1 });
Common methods
| Category | Method |
|---|
| Posts | client.posts.search() |
| Users | client.users.getMe() |
| Spaces | client.spaces.findSpaceById() |
| Lists | client.lists.getList() |
| DMs | client.directMessages.lookup() |
Learn more
Installation
Package managers, TypeScript setup, and requirements.
Authentication
Detailed guide for all auth methods.
Pagination
Async iteration and paginated responses.
Streaming
Event-driven streaming with reconnection.
API Reference
Complete client, interface, and type reference.
For code examples, see the samples repo.