OctoClient for iOS
Create and configure OctoClient in the iOS SDK: initializer settings, the methods it exposes, concurrency and how to shut it down.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
OctoClient is the entry point of the iOS SDK. It holds the agent id, the current user identity and the network session, and every other call goes through it. Create one instance per agent and share it across your app.
Create a client
import Askocto
let octo = OctoClient(
agentId: "agt_123",
userIdentity: nil,
requestTimeout: 30
)
Initializer settings
| Setting | Type | Description |
|---|---|---|
agentId |
String |
The agent to talk to, for example agt_123. Required. |
userIdentity |
UserIdentity? |
Optional identity to attach from the first request. See User identity. |
baseURL |
URL |
Defaults to https://api.askocto.co. Change it only if support tells you to. |
requestTimeout |
TimeInterval |
How long a non-streaming request may take, in seconds, before it fails with OctoError.network. |
The SDK authenticates with the agent id. It does not use a workspace API key. Keys such as oc_live_ act on the whole workspace, so keep them on your server. See Authentication.
Methods
| Method | Returns | Use it to |
|---|---|---|
chat(text:conversationId:) |
ChatResponse |
Send one message and wait for the full answer. |
streamChat(text:conversationId:) |
AsyncThrowingStream of StreamEvent |
Receive the answer as it is written. |
conversation(id:) |
Conversation |
Load one conversation. |
conversations(limit:cursor:) |
Page of Conversation |
List conversations for the current user. |
messages(conversationId:limit:cursor:) |
Page of Message |
Load the messages of a conversation. |
registerTool(_:) |
Nothing | Make a ClientTool available to the agent. |
identify(_:) |
Nothing | Attach a verified UserIdentity. |
clearIdentity() |
Nothing | Forget the user, for example on sign-out. |
close() |
Nothing | Cancel running requests and release resources. |
chat, conversation, conversations and messages are async throws. streamChat returns its stream immediately, and nothing is sent until you start iterating.
Concurrency
OctoClient is a Sendable class, so you can call it from any task or actor. Network work runs off the main thread, so calling it from a @MainActor view model does not block the interface. Cancelling the calling task cancels the request.
Tip: Keep the client in one place, such as your app's dependency container. Creating a new client for every screen loses the registered tools and the identity.
Next steps
Send a message with Chat response, or register code the agent can call with Client side tools.