Stream token deltas and tool-call events turn-by-turn from the Agent SDK.
Not yet available. The Agent SDK is tracked to be built — today, use the Client SDKs against the live chat completions API. The docs below describe the intended design.
Set stream: true in callModel() to receive token deltas as they arrive. The SDK handles SSE reassembly, tool-call buffering, and result injection — the streaming interface is the same as the non-streaming one, with an added event emitter for incremental output.
The onToken callback fires for each text delta. The returned result is the same TurnResult as non-streaming — output is the fully assembled string, items is complete, usage is final.
When the model makes tool calls mid-stream, the SDK pauses the token stream, executes the tool, injects the result, and resumes. You can observe this with onEvent:
| Event type | Fired when |
|---|---|
token | A text delta arrives. |
tool_call_start | The model begins a tool call (name and arguments may be partial). |
tool_call_end | A tool call has been executed and the result injected. |
turn_end | The turn is complete (same as result being returned). |
error | A mid-stream error was received. |
The SDK also exposes an async iterator for environments where callbacks are awkward:
stream: true applies per callModel() call. You can mix streaming and non-streaming turns freely — the item list works the same way either way.
If the upstream model sends an error event, the SDK emits an error event and resolves callModel() with stopReason: "error". The item list up to that point is still valid and can be used to resume.
callModel() API.