---
title: "Stream responses in real-time Code Agent SDK"
source: https://docs.autohand.ai/agent-sdk/io/streaming
---

# Stream responses in real-time

\`streamPrompt\` returns an async iterable of structured events. Use it to render assistant text as it generates, surface tool runs, and respond to permission requests without blocking the event loop.

## Basic streaming

Loop over the stream and pull \`delta\` from \`message\_update\` events. The full text is also available on \`message\_end.content\` when the message finishes.

## Event types you will see

The CLI emits the same set of events on every SDK. Match on \`event.type\` (TS/Python) or the sealed event subtype (Go/Java) and ignore the rest.

-   \`agent\_start\` / \`agent\_end\`: brackets the whole run.
-   \`turn\_start\` / \`turn\_end\`: brackets a single agent turn.
-   \`message\_start\` / \`message\_update\` / \`message\_end\`: assistant text. \`delta\` carries each new chunk; \`content\` carries the full final message.
-   \`tool\_start\` / \`tool\_update\` / \`tool\_end\`: tool execution. Use \`toolName\` (or \`tool\_name\`) for routing.
-   \`permission\_request\`: pause; respond with \`permissionResponse\` / \`respond\_to\_permission\`.
-   \`file\_modified\`: the agent wrote to disk. Useful for invalidating caches or refreshing editors.
-   \`error\`: transport, runtime, or tool failure. Always handle this.

## Render a full chat loop

A typical chat surface routes message text to the transcript, tool runs to a side panel, and permission requests to a modal. Here is the same shape across SDKs.

## Cancel an in-flight stream

Call \`abort()\` to end the run. The stream loop closes and any pending permission request is cancelled. Use this when the user cancels in your UI or when a parent task is unwound.

## When to stream vs await

-   Stream when the user is watching: chat UIs, terminal sessions, long-running refactors.
-   Await with \`agent.run()\` when you only need the final result: scripts, batch jobs, JSON pipelines.
-   Combine the two: stream for UI rendering, then call \`run.wait()\` (TS) / \`run.waitForResult()\` (Java) for the structured \`RunResult\`.