Streaming events in the iOS SDK

Reference for every StreamEvent the iOS SDK emits while an answer streams: messageDelta, messageDone, toolCall and error, with handling advice.

Working draft. These docs are illustrative: names, endpoints and examples describe the intended behaviour and can change before launch.

streamChat emits StreamEvent values. This page lists each case, the server event it comes from and what your app should do with it. For a full loop that handles them, see Streaming.

The StreamEvent type

public enum StreamEvent: Sendable {
    case messageDelta(String)
    case messageDone(message: Message, conversationId: String)
    case toolCall(callId: String, name: String, arguments: [String: JSONValue])
    case error(OctoError)
}
Case Server event Meaning
.messageDelta message.delta The next piece of the answer text.
.messageDone message.done The answer is complete. Carries the final Message and the conversation id.
.toolCall tool.call The agent wants to run a client tool in your app.
.error error The stream failed after it had started.

After the server sends its [DONE] marker, the stream finishes and your for try await loop ends. You do not receive a separate event for it.

Event order

A normal answer is a run of .messageDelta events followed by one .messageDone. When the agent calls a tool, a .toolCall can arrive between deltas. The agent then waits for the tool result before it writes the rest of the answer.

Handle each case

messageDelta

Append the string to what you already show. Deltas are plain text pieces and may split a word in the middle, so do not trim or format each one on its own.

messageDone

Replace the partial text with message.content. Read message.sources to show where the answer came from, and store conversationId if this was the first message of a new thread.

toolCall

If you registered a matching client tool, the SDK runs it for you and sends the result back. You still receive the event, which is useful for showing a status line such as "Checking your order". If no tool with that name is registered, the SDK reports the failure to the agent so it can answer without it. The arguments dictionary holds JSONValue items.

error

An .error event means the answer cannot be completed. Show a retry control and keep the text received so far. The associated value is an OctoError, the same type thrown by chat.

Note: Errors that happen before the first byte, such as a bad agent id or no network, are thrown from the loop instead of being emitted as .error. Wrap the loop in do and catch as well as handling the case.

  • Chat response for the non-streaming version of the same result.

Something unclear or missing? Tell us and we will fix the page.