> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/ably/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Realtime SDK

The Ably Realtime SDK provides a persistent, stateful connection to Ably's realtime messaging infrastructure. This SDK is ideal for applications that require bidirectional communication, presence, and automatic reconnection handling.

## Overview

The Realtime SDK enables you to:

* Establish persistent connections to Ably
* Publish and subscribe to messages in realtime
* Track presence of users on channels
* Automatically handle connection state and recovery
* Subscribe to connection and channel state changes

## Getting Started

To use the Realtime SDK, first instantiate a client:

<Code>
  ```javascript theme={null}
  const realtime = new Ably.Realtime('your-api-key');
  ```

  ```python theme={null}
  realtime = AblyRealtime('your-api-key')
  ```

  ```java theme={null}
  AblyRealtime realtime = new AblyRealtime("your-api-key");
  ```
</Code>

## Core Concepts

### Constructor

The Realtime SDK constructor creates a new client instance and establishes a connection to Ably. You can instantiate the client using an API key string or a `ClientOptions` object for more advanced configuration.

See the full [constructor documentation](/docs/api/realtime-sdk) for detailed information.

### Authentication

The Realtime SDK supports both Basic and Token authentication:

* **Basic Authentication**: Use your API key directly (recommended for server-side only)
* **Token Authentication**: Use temporary tokens for enhanced security (recommended for client-side)

Learn more about [authentication](/docs/api/realtime-sdk/authentication).

### Channels

Channels are the primary way to organize and route messages in Ably. Each channel provides:

* Message publishing and subscription
* Presence functionality
* History retrieval
* State management

Explore the [Channels API](/docs/api/realtime-sdk/channels).

### Messages

Messages are the data payloads sent and received on channels. Each message contains:

* Optional event name
* Data payload
* Metadata (timestamp, client ID, etc.)

Read about [Messages](/docs/api/realtime-sdk/messages).

### Presence

Presence allows you to track which clients are present on a channel:

* Enter and leave presence
* Update presence data
* Subscribe to presence events
* Query current presence set

Learn about [Presence](/docs/api/realtime-sdk/presence).

## Key Features

### Connection Management

The Realtime SDK automatically manages your connection:

* Automatic reconnection on network failures
* Connection state recovery
* Fallback host support
* Heartbeat monitoring

### Message Delivery Guarantees

Messages published via the Realtime SDK benefit from:

* Guaranteed delivery when connection is established
* Automatic message queueing during disconnection
* Message ordering preservation

### Real-time Events

Subscribe to events for:

* Connection state changes
* Channel state changes
* Incoming messages
* Presence updates

## API Reference Sections

<Tiles>
  {[
    {
      title: 'Authentication',
      description: 'Manage authentication and token lifecycle',
      link: '/docs/api/realtime-sdk/authentication',
    },
    {
      title: 'Channels',
      description: 'Create, configure, and manage channels',
      link: '/docs/api/realtime-sdk/channels',
    },
    {
      title: 'Messages',
      description: 'Publish and subscribe to messages',
      link: '/docs/api/realtime-sdk/messages',
    },
    {
      title: 'Presence',
      description: 'Track and subscribe to presence events',
      link: '/docs/api/realtime-sdk/presence',
    },
    ]}
</Tiles>

## Related Resources

* [REST SDK Overview](/docs/api/rest-sdk)
* [Authentication Guide](/docs/auth)
* [Channels Guide](/docs/channels)
* [Presence Guide](/docs/presence-occupancy/presence)
