Skip to content
QwryAI
Documentation
Pages

iOS SDK

ChatResponse

Reference for ChatResponse, Message, MessagePart and FinishReason, the types send, retry and sendNonStreaming return

Every answer comes back as a ChatResponse. It holds the agent's Message, the conversation it belongs to, why it ended and how many credits it used.

ChatResponse

struct ChatResponse: Sendable, Equatable

What send, retry and sendNonStreaming give you back.

Swift
public struct ChatResponse: Sendable, Equatable {
    public let message: Message
    public let conversationId: String
    public let userMessageId: String?
    public let userId: String?
    public let finishReason: FinishReason
    public let credits: Double
}
PropertyTypeDescription
messageMessageThe agent's answer. See Message.
conversationIdStringThe conversation this answer belongs to. The client also keeps it as currentConversationId.
userMessageIdString?The ID the server gave the message you sent.
userIdString?The signed-in user, or nil while anonymous.
finishReasonFinishReasonWhy the answer ended. See FinishReason.
creditsDoubleMessage credits this answer used. 0 when the server reports none.
Swift
let response = try await client.send("Hello")
print(response.message.text)    // the answer
print(response.message.id)      // pass to retry(conversationId:messageId:)
print(response.conversationId)  // the conversation it belongs to
print(response.credits)

Message

struct Message: Sendable, Equatable, Identifiable, Decodable

Used both for the answer inside ChatResponse and for each item from listMessages.

Swift
public struct Message: Sendable, Equatable, Identifiable, Decodable {
    public enum Role: String, Sendable, Codable { case user, assistant }
    public enum Feedback: String, Sendable, Codable { case positive, negative }

    public let id: String
    public let role: Role
    public var parts: [MessagePart]
    public let createdAt: Date?
    public let feedback: Feedback?
    public let score: Double?
    public var text: String { get }
}
PropertyTypeDescription
idStringThe message ID.
roleRole.user or .assistant.
parts[MessagePart]The message in pieces, in order: text, tool calls and tool results.
createdAtDate?When the message was created. For a fresh answer, the time it arrived on the device.
feedbackFeedback?.positive or .negative when someone rated the answer, otherwise nil. Set on messages loaded from history.
scoreDouble?The agent's confidence in this answer, when it reported one. Set on messages loaded from history.
textStringAll the text parts joined together. Handy for a plain bubble.

Message.Role

Swift
public enum Role: String, Sendable, Codable {
    case user
    case assistant
}

Anything not from the user is .assistant, including replies typed by a person who took over the conversation.

Message.Feedback

Swift
public enum Feedback: String, Sendable, Codable {
    case positive   // "positive"
    case negative   // "negative"
}

MessagePart

Swift
public enum MessagePart: Sendable, Equatable, Codable {
    case text(String)
    case toolCall(ToolCall)
    case toolResult(ToolResult)
}

.text

Text the agent wrote, or the user sent.

Swift
case text(String)

The value is the text itself.

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

FinishReason

Swift
public enum FinishReason: String, Sendable {
    case stop                       // "stop"        finished normally
    case error                      // "error"       the answer failed
    case toolCalls = "tool-calls"   // "tool-calls"  waiting for tool results
}

ChatResponse.FinishReason is nested in ChatResponse.

Explore the documentation