# 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 } ``` | Property | Type | Description | | - | - | - | | `message` | `Message` | The agent's answer. See [Message](#message). | | `conversationId` | `String` | The conversation this answer belongs to. The client also keeps it as `currentConversationId`. | | `userMessageId` | `String?` | The ID the server gave the message you sent. | | `userId` | `String?` | The signed-in user, or `nil` while anonymous. | | `finishReason` | `FinishReason` | Why the answer ended. See [FinishReason](#finishreason). | | `credits` | `Double` | Message 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) ``` > [!NOTE] > > When the agent uses tools, the answer takes several rounds. `message` is the message from the final round, and `message.id` is that message's ID. Your `onTextDelta` handler receives the text of every round as it arrives. ## Message `struct Message: Sendable, Equatable, Identifiable, Decodable` Used both for the answer inside `ChatResponse` and for each item from [`listMessages`](/docs/ios-sdk/conversations). ```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 } } ``` | Property | Type | Description | | - | - | - | | `id` | `String` | The message ID. | | `role` | `Role` | `.user` or `.assistant`. | | `parts` | `[MessagePart]` | The message in pieces, in order: text, tool calls and tool results. | | `createdAt` | `Date?` | When the message was created. For a fresh answer, the time it arrived on the device. | | `feedback` | `Feedback?` | `.positive` or `.negative` when someone rated the answer, otherwise `nil`. Set on messages loaded from history. | | `score` | `Double?` | The agent's confidence in this answer, when it reported one. Set on messages loaded from history. | | `text` | `String` | All the text parts joined together. Handy for a plain bubble. | > [!TIP] > > Use `text` for a simple chat log. Use `parts` when you want to show tool activity in the conversation. See [SwiftUI](/docs/ios-sdk/swiftui). ## 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) } ``` > [tab] text > > **.text** > > Text the agent wrote, or the user sent. > > ```swift > case text(String) > ``` > > The value is the text itself. > [tab] toolCall > > **.toolCall** > > The agent calling a tool. > > ```swift > case toolCall(ToolCall) > ``` > > A [`ToolCall`](/docs/ios-sdk/streaming-events) holds the call's `id`, the tool's `name` (the action's **Action name**) and the `input` the agent passed, as a [`JSONValue`](/docs/ios-sdk/json-value). `input` is `.null` when the agent passed nothing. > [tab] toolResult > > **.toolResult** > > What the tool returned. > > ```swift > case toolResult(ToolResult) > ``` > > A [`ToolResult`](/docs/ios-sdk/streaming-events) holds the `id` of the call it answers, the tool's `name` and its `output`. An object with an `error` key means the tool failed. ```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`. > [!NOTE] > > After `send`, `retry` or `sendNonStreaming` this is almost always `.stop`, because the SDK runs your tools and waits for the real answer. `sendNonStreaming` returns `.error` when the answer failed on the server; `send` and `retry` throw instead. > > Any finish reason the SDK doesn't recognize is read as `.stop`. ## Related > [card] Streaming | /docs/ios-sdk/streaming | The methods that return a ChatResponse. > [card] Conversation & Pagination | /docs/ios-sdk/conversation-models | Conversation, status and paging types. > [card] JSONValue | /docs/ios-sdk/json-value | Reading tool data. > [card] Streaming Types | /docs/ios-sdk/streaming-events | Handlers, ToolCall and ToolResult.