> ## 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
)
```

<ParamField body="agentId" type="String" required>
  The Chatbase agent ID to connect to.
</ParamField>

<ParamField body="baseURL" type="String" default="https://www.chatbase.co/api/sdk">
  The Chatbase API address. Leave this at its default.
</ParamField>

<ParamField body="configuration" type="URLSessionConfiguration" default=".default">
  The `URLSessionConfiguration` used for every request. Set timeouts and caching here.
</ParamField>

<ParamField body="maxToolLoopSteps" type="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](/docs/ios-sdk/client-side-tools#tool-loop-limit).
</ParamField>

```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.
</Tip>

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


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