Skip to content
QwryAI
Documentation
Pages

iOS SDK

Conversations & History

Start and continue conversations, list them, and page through their messages with the iOS SDK

The SDK keeps track of the conversation you're in, and can list the user's past conversations and load their messages a page at a time. This page covers newConversation, listConversations, listMessages and the Page they return.

Starting and continuing conversations

  1. Send a message

    The first send on a new client starts a new conversation. The server creates it.

    Swift
    let response = try await client.send("Hello!")
  2. Keep the conversation ID if you need it
    Swift
    let conversationId = response.conversationId

    The client also keeps it as currentConversationId.

  3. Continue the conversation

    The next send continues currentConversationId by itself. Pass an ID only to continue a different conversation:

    Swift
    let followUp = try await client.send("Tell me more")
    let elsewhere = try await client.send("Any update?", conversationId: olderConversationId)

newConversation

Swift
public func newConversation()

Clears currentConversationId, so the next send starts a new conversation.

Swift
await client.newConversation()
try await client.send("Brand new conversation!")

listConversations

Swift
public func listConversations(
    cursor: String? = nil,
    limit: Int = 20
) async throws -> Page<Conversation>

Lists the signed-in user's conversations, or this device's while anonymous, most recently active first.

ParameterTypeRequiredDescription
cursorString?NoThe cursor from the previous page. Leave it out to start with the most recent conversations.
limitIntNoHow many per page, from 1 to 100. Defaults to 20.
Swift
let page = try await client.listConversations(limit: 20)
for conversation in page.items {
    print("\(conversation.title ?? "New conversation")")
    print("  Status: \(conversation.status)")
    print("  Updated: \(conversation.updatedAt.formatted())")
}
print("Total: \(page.total)")
print("Has more: \(page.hasMore)")

See Conversation for the full type.

listMessages

Swift
public func listMessages(
    conversationId: String,
    cursor: String? = nil,
    limit: Int = 20
) async throws -> Page<Message>

Loads a page of a conversation's messages.

ParameterTypeRequiredDescription
conversationIdStringYesThe conversation to load. It must belong to the current user or device.
cursorString?NoThe cursor from the previous page. Leave it out to start with the latest messages.
limitIntNoHow many per page, from 1 to 100. Defaults to 20.
Swift
let page = try await client.listMessages(conversationId: conversationId, limit: 50)
for message in page.items {
    let who = message.role == .user ? "You" : "Agent"
    print("\(who): \(message.text)")
}

Each Message has a plain text (all its text parts joined) and a parts list, so you can show tool activity alongside the text:

Swift
for part in message.parts {
    switch part {
    case .text(let text):
        renderBubble(text)
    case .toolCall(let call):
        renderToolCard(call.name, input: call.input)
    case .toolResult(let result):
        attachToolOutput(result.output)
    }
}

Private notes your team adds in the Inbox are never returned. Replies a person sends after taking over the conversation come back with the role .assistant.

See Message for the full type.

Page

Swift
public struct Page<Item: Sendable & Decodable>: Sendable, Decodable {
    public let items: [Item]
    public let cursor: String?
    public let hasMore: Bool
    public let total: Int
}
PropertyTypeDescription
items[Item]The items on this page.
cursorString?Pass it back to get the next page. nil on the last page.
hasMoreBoolWhether there are more pages.
totalIntHow many items there are in all.

Loading the next page

Pass cursor back with the same method to get the next page. Each page holds only its own items; add them to your own array, at the bottom for conversations or the top for older messages.

Swift
var page = try await client.listConversations(limit: 20)
var all = page.items
while page.hasMore, let cursor = page.cursor {
    page = try await client.listConversations(cursor: cursor, limit: 20)
    all.append(contentsOf: page.items)
}
print("Loaded \(all.count) of \(page.total)")

Infinite scroll in SwiftUI

Swift
struct ConversationList: View {
    @State var list: ConversationListState

    var body: some View {
        List {
            ForEach(list.conversations) { conversation in
                ConversationRow(conversation)
            }
            if list.hasMore {
                ProgressView()
                    .task { await list.loadMore() }
            }
        }
        .task { await list.load() }
    }
}

Conversation status

A conversation that has ended, or that a person has taken over, can't take new messages. Sending to one fails with 403 CHAT_CONVERSATION_NOT_ONGOING. Check the status before showing a text field:

Swift
if conversation.status == .ongoing {
    showComposer()
} else {
    showReadOnlyBanner()
}
StatusWhat it means
.ongoingOpen, and answered by your agent.
.endedClosed. Start a new conversation.
.takenOverA person on your team took it over from the Inbox.

Explore the documentation