Skip to main content

ChatResponse

struct ChatResponse: Sendable What send, retry, and sendNonStreaming give you back.
Message
required
The agent’s reply. See Message.
String
required
The conversation this reply belongs to. Pass it to your next send to continue.
String?
The server’s ID for the user message that prompted this reply.
FinishReason
required
Why the reply ended. See FinishReason.
Usage
required
How many credits it used. See Usage.
When the agent uses tools, the reply takes several rounds. message.text is all the text from every round joined together, and message.id is the ID of the final message.

Message

struct Message: Identifiable, Sendable Used both for the reply inside ChatResponse and for each item from listMessages.
String
required
The message ID.
String
required
All the text joined together, which is handy for a plain bubble.
MessageSender
required
.user or .agent.
Date
required
When the message was created. Falls back to the current time if the server does not send one.
MessageFeedback?
.positive, .negative, or nil. Set for messages loaded from history.
Double?
A score from the server, when there is one.
[MessagePart]
required
The message broken into pieces: text, tool calls, and tool results, in order.
Use text for a simple chat log. Use parts when you want to show tool activity in the conversation. ConversationState uses parts. See SwiftUI.

MessagePart

.text

Text written by the agent, or sent by the user.
The value is the text itself.

MessageSender

Anything that is not from the user counts as .agent, including messages typed by a person who has taken over the conversation.

MessageFeedback

FinishReason

After send or retry, this is almost always .stop, because the SDK runs the tools for you and waits for the real answer. You will see .toolCalls from sendNonStreaming, which skips tools: the agent wanted one and never got an answer.Any finish reason the SDK does not recognize is treated as .stop.

Usage

Double
required
How many message credits this reply used. 0 if the server did not report any.

Streaming

The methods that return a ChatResponse

Conversation & Pagination

Conversation, status, and paging types

JSONValue

Reading tool data

Streaming Types

Callbacks and stream types