Skip to main content
Beta Release. The Chatbase iOS SDK is currently in beta (v0.1.0-beta.1). APIs may change in future releases.
Conversation methods apply exclusively to conversations created through the mobile SDKs (iOS and Android). Conversations generated through the widget, the API, or external integrations cannot be accessed using the SDK. A user identified on both platforms sees their iOS and Android SDK conversations together.

What is the Chatbase iOS SDK?

The Chatbase iOS SDK is a Swift library that lets you add Chatbase agents to your iOS or macOS app. It gives you:
  • Real-time streaming with async/await and per-chunk callbacks
  • Client-side tools that let the agent run functions on the device
  • User identity with JWT sign-in and an automatic device ID
  • Conversation management with paginated history
  • Ready-made SwiftUI state through ConversationState and ConversationListState
  • Typed errors for everything that can go wrong
Requirements:
Everything in the SDK lives in one module, ChatbaseSDK. A single import ChatbaseSDK gives you every type in these docs.

Installation

The SDK ships as a Swift Package.
  1. FileAdd Package Dependencies…
  2. Paste the repository URL:
  3. Choose version 0.1.0-beta.1 (or Up to Next Minor) and add the ChatbaseSDK library to your app target.
Then import it:
No Info.plist changes are needed. The SDK talks to https://www.chatbase.co over HTTPS, which iOS allows by default.

Quick Start

1

Get your Agent ID

  1. Go to the Chatbase Dashboard
  2. Select your agent
  3. Go to SettingsGeneral
  4. Copy the Agent ID
2

Enable the iOS SDK channel

In the dashboard, go to DeployiOS SDK and enable the channel for your agent.
If the iOS SDK channel is not enabled, every SDK request fails with a 404 AGENT_NOT_FOUND error, even when the agent ID is correct.
3

Create a client

Create the client once and keep it around, in a view model, an app-level dependency, or a @State property. A new client starts anonymous, tied to a device ID that stays the same across launches.
4

Send your first message

5

Continue the conversation

For UI code, use ConversationState instead. It keeps the conversation ID for you, along with the message list.
There is no close() or cleanup call. The client shuts down its network session when it goes out of scope.

ChatbaseClient

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

init

String
required
The Chatbase agent ID to connect to.
String
default:"https://www.chatbase.co/api/sdk"
The Chatbase API address. Leave this at its default.
URLSessionConfiguration
default:".default"
The URLSessionConfiguration used for every request. Set timeouts and caching here.
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.
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

Methods

Logging

The SDK writes to Apple’s logging system under the subsystem com.chatbase.sdk, in three categories: View them in Console.app, or run log stream --predicate 'subsystem == "com.chatbase.sdk"'. Message text is never logged.

Rate Limits

Chatbase allows 1,000 requests every 10 seconds per device. Going over throws an APIError.httpError with status 429. See Error Handling.

Next Steps

Streaming

Stream replies with async/await and callbacks

SwiftUI

Ready-made state for chat screens

Client-Side Tools

Let the agent run functions on the device

Conversations

Conversations, history, and pagination

User Identity

Sign users in with JWT tokens

Error Handling

Error types and how to handle them