# ChatClient
The `ChatClient` interface is the main entry point for using the Ably Chat SDK. It provides access to chat rooms, connection management, and the underlying Ably Realtime client.
The Chat SDK is built on top of the Ably Pub/Sub SDK and uses that to establish a connection with Ably. Instantiate a realtime client using the Pub/Sub SDK and pass the generated client into the Chat factory function.
#### Kotlin
```
import com.ably.chat.ChatClient
import com.ably.chat.LogLevel
import io.ably.lib.realtime.AblyRealtime
import io.ably.lib.types.ClientOptions
val realtimeClient = AblyRealtime(ClientOptions().apply {
key = "your-api-key"
clientId = "
An API key is required to authenticate with Ably. API keys are used either to authenticate directly with Ably using basic authentication, or to generate tokens for untrusted clients using [JWT authentication](https://ably.com/docs/auth/token.md#jwt).
## Properties
The `ChatClient` interface has the following properties:
### Kotlin
```
import com.ably.chat.ChatClient
import com.ably.chat.buildChatClientOptions
import com.ably.chat.LogLevel
import io.ably.lib.realtime.AblyRealtime
import io.ably.lib.types.ClientOptions
val realtimeClient = AblyRealtime(ClientOptions().apply {
key = "your-api-key"
clientId = "user-123"
})
val chatClient = ChatClient(realtimeClient, buildChatClientOptions {
logLevel = LogLevel.Debug
})
```
A DSL builder overload is also available:
`ChatClient(realtimeClient: AblyRealtime, init: MutableChatClientOptions.() -> Unit): ChatClient`
### Kotlin
```
val chatClient = ChatClient(realtimeClient) {
logLevel = LogLevel.Debug
}
```
### Parameters
The `ChatClient()` factory function takes the following parameters:
### Kotlin
```
import com.ably.chat.ChatException
try {
room.messages.send(text = "Hello!")
} catch (e: ChatException) {
println("Error code: ${e.errorInfo.code}")
println("Message: ${e.errorInfo.message}")
println("Status: ${e.errorInfo.statusCode}")
}
```
## ErrorInfo
A standardized, generic Ably error object that contains an Ably-specific status code, and a generic HTTP status code. All errors thrown by the SDK are compatible with the `ErrorInfo` structure.
### Kotlin
```
import com.ably.chat.ChatClient
import com.ably.chat.LogLevel
import io.ably.lib.realtime.AblyRealtime
import io.ably.lib.types.ClientOptions
val realtimeClient = AblyRealtime(ClientOptions().apply {
key = "your-api-key"
clientId = "user-123"
})
val chatClient = ChatClient(realtimeClient) {
logLevel = LogLevel.Debug
}
// Access rooms
val room = chatClient.rooms.get("my-room")
// Check connection status
println(chatClient.connection.status)
// Get current user ID
println(chatClient.clientId)
```
## Related Topics
- [Connection](https://ably.com/docs/chat/api/kotlin/connection.md): API reference for the Connection interface in the Ably Chat Kotlin SDK.
- [Rooms](https://ably.com/docs/chat/api/kotlin/rooms.md): API reference for the Rooms interface in the Ably Chat Kotlin SDK.
- [Room](https://ably.com/docs/chat/api/kotlin/room.md): API reference for the Room interface in the Ably Chat Kotlin SDK.
- [Messages](https://ably.com/docs/chat/api/kotlin/messages.md): API reference for the Messages interface in the Ably Chat Kotlin SDK.
- [Message](https://ably.com/docs/chat/api/kotlin/message.md): API reference for the Message interface in the Ably Chat Kotlin SDK.
- [MessageReactions](https://ably.com/docs/chat/api/kotlin/message-reactions.md): API reference for the MessageReactions interface in the Ably Chat Kotlin SDK.
- [Presence](https://ably.com/docs/chat/api/kotlin/presence.md): API reference for the Presence interface in the Ably Chat Kotlin SDK.
- [Occupancy](https://ably.com/docs/chat/api/kotlin/occupancy.md): API reference for the Occupancy interface in the Ably Chat Kotlin SDK.
- [Typing](https://ably.com/docs/chat/api/kotlin/typing.md): API reference for the Typing interface in the Ably Chat Kotlin SDK.
- [RoomReactions](https://ably.com/docs/chat/api/kotlin/room-reactions.md): API reference for the RoomReactions interface in the Ably Chat Kotlin SDK.
## Documentation Index
To discover additional Ably documentation:
1. Fetch [llms.txt](https://ably.com/llms.txt) for the canonical list of available pages.
2. Identify relevant URLs from that index.
3. Fetch target pages as needed.
Avoid using assumed or outdated documentation paths.