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

# Client

> Reference for the main Client class in the X API TypeScript SDK, the entry point exposing specialized clients for every X API v2 endpoint group.

Main client class for the X API

This is the primary entry point for interacting with the X API. It provides
access to all API endpoints through specialized client modules and handles
authentication, request configuration, and error handling.

**`Example`**

```typescript theme={null}
import { Client } from '@xdevplatform/xdk';

const client = new Client({
  bearerToken: 'your-bearer-token'
});

// Get user information
const user = await client.users.getUser('783214');

// Get followers with pagination
const followers = await client.users.getFollowers('783214', {
  maxResults: 10,
  userFields: ['id', 'name', 'username']
});

// Iterate through followers
for await (const follower of followers) {
  console.log(follower.username);
}
```

## Constructors

### constructor

• **new Client**(`config`): [`Client`](/xdks/typescript/reference/classes/Client)

Creates a new X API client instance

#### Parameters

| Name     | Type  | Description                          |
| :------- | :---- | :----------------------------------- |
| `config` | `any` | Configuration options for the client |

#### Returns

[`Client`](/xdks/typescript/reference/classes/Client)

**`Example`**

```typescript theme={null}
// Bearer token authentication
const client = new Client({
  bearerToken: 'your-bearer-token'
});

// OAuth2 authentication
const client = new Client({
  accessToken: 'your-access-token'
});

// OAuth1 authentication
const client = new Client({
  oauth1: oauth1Instance
});
```

[client.ts:401](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/client.ts#L401)

## Properties

<ResponseField name="baseUrl" type="string" required>
  Base URL for API requests
</ResponseField>

<ResponseField name="bearerToken" type="string">
  Bearer token for authentication
</ResponseField>

<ResponseField name="accessToken" type="string">
  OAuth2 access token
</ResponseField>

<ResponseField name="oauth1" type="any">
  OAuth1 instance for authentication
</ResponseField>

<ResponseField name="headers" type="Headers" required>
  Headers for requests
</ResponseField>

<ResponseField name="timeout" type="number" required>
  Request timeout in milliseconds
</ResponseField>

<ResponseField name="retry" type="boolean" required>
  Whether to automatically retry failed requests
</ResponseField>

<ResponseField name="maxRetries" type="number" required>
  Maximum number of retry attempts
</ResponseField>

<ResponseField name="httpClient" type="HttpClient = httpClient" required>
  HTTP client for making requests
</ResponseField>

<ResponseField name="general" type="GeneralClient" required>
  general client
</ResponseField>

<ResponseField name="accountActivity" type="AccountActivityClient" required>
  account activity client
</ResponseField>

<ResponseField name="communityNotes" type="CommunityNotesClient" required>
  community notes client
</ResponseField>

<ResponseField name="compliance" type="ComplianceClient" required>
  compliance client
</ResponseField>

<ResponseField name="connections" type="ConnectionsClient" required>
  connections client
</ResponseField>

<ResponseField name="users" type="UsersClient" required>
  users client
</ResponseField>

<ResponseField name="news" type="NewsClient" required>
  news client
</ResponseField>

<ResponseField name="spaces" type="SpacesClient" required>
  spaces client
</ResponseField>

<ResponseField name="activity" type="ActivityClient" required>
  activity client
</ResponseField>

<ResponseField name="usage" type="UsageClient" required>
  usage client
</ResponseField>

<ResponseField name="trends" type="TrendsClient" required>
  trends client
</ResponseField>

<ResponseField name="posts" type="PostsClient" required>
  posts client
</ResponseField>

<ResponseField name="directMessages" type="DirectMessagesClient" required>
  direct messages client
</ResponseField>

<ResponseField name="communities" type="CommunitiesClient" required>
  communities client
</ResponseField>

<ResponseField name="media" type="MediaClient" required>
  media client
</ResponseField>

<ResponseField name="webhooks" type="WebhooksClient" required>
  webhooks client
</ResponseField>

<ResponseField name="stream" type="StreamClient" required>
  stream client
</ResponseField>

<ResponseField name="lists" type="ListsClient" required>
  lists client
</ResponseField>

<ResponseField name="request" type="Promise<T>" required>
  Make an authenticated request to the X API

  This method handles authentication, request formatting, and error handling
  for all API requests. It automatically adds the appropriate authentication
  headers based on the client configuration.
</ResponseField>

<ResponseField name="isTokenExpired" type="boolean" required>
  Check if the OAuth2 token is expired
</ResponseField>

<ResponseField name="refreshToken" type="Promise<void>" required>
  Refresh the OAuth2 token
</ResponseField>

<ResponseField name="isAuthenticated" type="boolean" required>
  Get the current authentication status
</ResponseField>

<ResponseField name="mapSecuritySchemeToAuthTypes" type="string[]" required>
  Map OpenAPI security scheme names to internal authentication types
</ResponseField>

<ResponseField name="validateAuthentication" type="void" required>
  Validate that the required authentication method is available
</ResponseField>

<ResponseField name="getAvailableAuthTypes" type="string[]" required>
  Get available authentication types
</ResponseField>
