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

# Initialization

> Connect to the SX Bet real-time WebSocket API using Ably

<Warning>
  This WebSocket API will be deprecated on July 1, 2026. See the [Migration Guide](/api-reference/centrifugo-migration) to move to the Centrifuge-based API.
</Warning>

We use the Ably SDK to allow users to connect to our API. It supports pretty much every major language but all of the examples on this page will be in JavaScript. The API is relatively identical across languages though. See [this link](https://ably.com/docs) for a basic overview of the API in other languages.

<Info>You only need one instance of the `ably` object to connect to the API. Connections to multiple channels are multiplexed though the single network connection. If you create too many individual connections, you will be forcefully unsubscribed from all channels and disconnected.</Info>

All the examples following assume you have a `realtime` object in scope following the initialization code to the right.

***

```javascript theme={null}
import * as ably from "ably";

async function createTokenRequest() {
  const response = await fetch("https://api.sx.bet/user/token", {
    headers: {
      "X-Api-Key": process.env.SX_BET_API_KEY,
    },
  });
  return response.json();
}

async function initialize() {
  const realtime = new ably.Realtime.Promise({
    authCallback: async (tokenParams, callback) => {
      try {
        const tokenRequest = await createTokenRequest();
        // Make a network request to GET /user/token passing in
        // `X-Api-Key: [YOUR_API_KEY]` as a header
        callback(null, tokenRequest);
      } catch (error) {
        callback(error, null);
      }
    },
  });
  await ablyClient.connection.once("connected");
}
```
