Chat response in the iOS SDK
Read the ChatResponse returned by the iOS OctoClient: the answer text in Swift, the sources the agent used, the conversation id and credit usage.
Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.
Every call to chat returns a ChatResponse. It carries the agent's answer, the sources behind it and the id you need to continue the conversation. Use this page when you render an answer in your own UI.
Send a message
let response: ChatResponse = try await octo.chat(
text: "Where is my order?",
conversationId: nil
)
Leave conversationId as nil to start a new conversation. Pass the id from an earlier response to add to an existing one.
The ChatResponse type
public struct ChatResponse: Sendable, Codable {
public let conversationId: String
public let message: Message
public let usage: Usage
}
| Field | Type | Description |
|---|---|---|
conversationId |
String |
The conversation the answer belongs to, for example conv_8f2a. Store it to continue the thread. |
message |
Message |
The assistant message: id, role, content and sources. |
usage |
Usage |
Resource use of this request. usage.credits is the number of credits it consumed. |
The same fields appear in the JSON of the chat endpoint, so you can compare SDK output with raw API output while debugging.
Show the answer and its sources
let answer = response.message.content
let titles = response.message.sources.map(\.title)
answerLabel.text = answer
sourcesLabel.text = titles.joined(separator: "\n")
Each Source has an id such as src_42 and a title. The list is empty when the agent answered from a procedure or from the conversation itself and did not need a source. Show sources as small labels under the answer so customers can see where it came from.
Continue the conversation
let first = try await octo.chat(text: "I want to return a jacket")
let second = try await octo.chat(
text: "It arrived last week",
conversationId: first.conversationId
)
Both calls land in one conversation, so the agent keeps the context of the first message.
Note: A response can arrive while the conversation is already handed off to your team. Check the conversation
statuswith Conversations if your UI should tell the customer that a person will reply.
Related pages
- Conversation models lists the fields of
MessageandConversation. - Streaming shows how to receive the same answer in pieces.
- Error handling covers the failures
chatcan throw.