By default, a model's reply is delivered as a single complete message at the end of each turn. With streaming output enabled, the SDK pushes fine-grained incremental chunks as the model generates them — useful for typewriter effects, or for rendering reasoning and tool-invocation progress separately.
Enable partial messages in options (
Java has no typed stream events. Incremental chunks arrive as
The model's text reply arrives as a sequence of incremental chunks; printing each chunk as it lands gives a typewriter effect:
Reasoning-capable models emit "thinking" chunks before their final reply:
Tool-call arguments are also generated incrementally — for example, you can use this to render the file content the model is writing in real time:
The Java examples above pull messages one at a time with a cursor. You can also let the SDK push them:
Each message stream can be consumed only once. Use either a cursor or
Enable
Enable partial messages in options (includePartialMessages in TypeScript, include_partial_messages in Python, includePartialMessages(true) in Java):
PartialMessage, and you parse the event from rawJson(). The Java examples below use a delta(...) helper to extract the event's delta object; the next two sections reuse it.
Typewriter effect
The model's text reply arrives as a sequence of incremental chunks; printing each chunk as it lands gives a typewriter effect:
Reasoning
Reasoning-capable models emit "thinking" chunks before their final reply:
Tool invocation arguments
Tool-call arguments are also generated incrementally — for example, you can use this to render the file content the model is writing in real time:
Push consumption (Java)
The Java examples above pull messages one at a time with a cursor. You can also let the SDK push them: messages().consume(handler, executor) calls the handler on the given executor for each message in order, delivering the next message only after the previous one is handled. The returned stage completes normally when the stream ends.
Java
consume(); a second subscription throws MessageStreamAlreadyConsumedException. If the handler throws, the stage returned by consume() completes with CallbackExecutionException and the owning query or session is closed. Do not block inside the handler, and do not call the blocking close() there.
For the full event structure, see SDK References. For Java message types, see Message Types.