Skip to main content
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).

Basic Initialization

Replace APP_ID with your CometChat App ID and APP_REGION with your Region 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):

Next Steps

Authentication

Log in users with Auth Key or Auth Token

SSR Compatibility

Setup for Next.js, Nuxt, and Ionic