Skip to main content
Prerequisites: npm 8+, Node.js 16+, credentials from CometChat Dashboard SSR: SDK requires browser APIs — initialize client-side only (useEffect / mounted)

Prerequisites

Get your credentials from the CometChat Dashboard:
  • App ID
  • Region
  • Auth Key (for development)
Auth Key is for development/testing only. In production, generate Auth Tokens on your server using the REST API. Never expose Auth Keys in production client code.

Installation

Package Manager

Then import wherever needed:

CDN

When using the CDN, CometChat is available as a global variable.

Initialization

The init() method initializes the SDK and must be called before any other CometChat method. Call it once at app startup, typically in your entry file (index.js, main.js, or App.js).
Replace APP_ID and APP_REGION with your credentials from the Dashboard.
CometChat.init() must be called before any other SDK method. Calling login(), sendMessage(), or registering listeners before init() will fail.

Parameters

AppSettings Options

Presence Subscription

Choose how to subscribe to user presence (online/offline status):
See User Presence for more details.

WebSocket Connection

By default, the SDK manages WebSocket connections automatically. To manage them manually:
See Managing WebSocket Connections for manual control.

Session Storage

Use session storage instead of local storage (data clears when browser closes):

SSR Compatibility

The CometChat SDK requires browser APIs (window, WebSocket) and cannot run on the server. For SSR frameworks, initialize the SDK only on the client side.
Import the SDK dynamically in useEffect:

Next Steps

Authentication

Log in users with Auth Key or Auth Token

Send Messages

Send your first message