SDK Examples

Example: Live UI

Render the unified live Session Mutation stream with session.subscribe()

Example: Live UI

const unsubscribe = session.subscribe((mutation) => {
  if (mutation.variant === "delta" && mutation.type === "text") {
    render(mutation.delta);
  }
});

const turn = await session.prompt({
  query: "Continue",
});

await turn.finished;
unsubscribe();

If you also want to show tool activity, handle:

  • part Mutations for tool call and result parts
  • message Mutations for assistant, action, and error Messages
  • turn Mutations for lifecycle state
  • session Mutations for Session state such as title

This pattern is especially good for terminal live output and web-based real-time chat UI.

Table of Contents