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

# ChatbaseClient

> Initializer, properties, and methods of ChatbaseClient, the main entry point of the Chatbase iOS SDK.

`final class ChatbaseClient`

The main entry point. You can call it from any task or actor.

## init

```swift theme={null}
public init(
    agentId: String,
    baseURL: String = "https://www.chatbase.co/api/sdk",
    configuration: URLSessionConfiguration = .default,
    maxToolLoopSteps: Int = 10
)
```

**agentId** `String` *required*

The Chatbase agent ID to connect to.

**baseURL** `String` (default: [https://www.chatbase.co/api/sdk](https://www.chatbase.co/api/sdk))

The Chatbase API address. Leave this at its default.

**configuration** `URLSessionConfiguration` (default: .default)

The `URLSessionConfiguration` used for every request. Set timeouts and caching here.

**maxToolLoopSteps** `Int` (default: 10)

How many times a single `send` or `retry` may run tools before giving up. Going over throws `ChatError.toolLoopLimitExceeded(limit:)`. See [Client-Side Tools](https://chatbase.co/docs/ios-sdk/client-side-tools.md#tool-loop-limit).

```swift theme={null}
// Custom timeouts
let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 30
config.timeoutIntervalForResource = 300

let client = ChatbaseClient(
    agentId: "YOUR_AGENT_ID",
    configuration: config,
    maxToolLoopSteps: 20
)
```

> [!TIP]
>
> `timeoutIntervalForRequest` measures the gap between pieces of data, not the length of the whole response. A long streaming reply will not be cut off by a 30 second timeout as long as data keeps arriving.

## Properties

| Property | Type | Description |
| - | - | - |
| `deviceId` | `String` | The device ID. Always available. |
| `authState` | `AuthState` | `.anonymous` or `.identified(token:)`. |
| `currentConversationId` | `String?` | The last conversation the client saw, or `nil`. |
| `currentUserId` | `String?` | The user ID the server confirmed on the last completed reply. |

## Methods

| Method | Description |
| - | - |
| `send(_:conversationId:configure:)` | Send a message, stream the reply, run tools. See [Streaming](https://chatbase.co/docs/ios-sdk/streaming.md#send). |
| `retry(conversationId:messageId:configure:)` | Ask the AI agent to answer again. See [Streaming](https://chatbase.co/docs/ios-sdk/streaming.md#retry). |
| `sendNonStreaming(_:conversationId:)` | Get the whole reply at once, with no streaming and no tools. See [Streaming](https://chatbase.co/docs/ios-sdk/streaming.md#sendnonstreaming). |
| `tool(_:handler:)` | Register a tool the AI agent can run. See [Client-Side Tools](https://chatbase.co/docs/ios-sdk/client-side-tools.md). |
| `identify(token:)` | Sign a user in with a JWT. See [User Identity](https://chatbase.co/docs/ios-sdk/user-identity.md). |
| `logout()` | Go back to anonymous. See [User Identity](https://chatbase.co/docs/ios-sdk/user-identity.md#logout). |
| `newConversation()` | Clear `currentConversationId`. See [Conversations](https://chatbase.co/docs/ios-sdk/conversations.md#newconversation). |
| `listConversations(cursor:limit:)` | List past conversations. See [Conversations](https://chatbase.co/docs/ios-sdk/conversations.md#listconversations). |
| `listMessages(conversationId:cursor:limit:)` | Load a conversation's messages. See [Conversations](https://chatbase.co/docs/ios-sdk/conversations.md#listmessages). |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.