Skip to main content
POST /v4/interact/stream answers with server-sent events instead of JSON, so your interface can show the agent’s reply while the model is still writing it. Each frame is one trace, and the stream closes with a single end event. This recipe opens a session, streams a turn with completionEvents on, reassembles the reply from the token deltas, and checks that the frames really did arrive one at a time rather than in a single buffered lump. It needs nothing but curl and jq.
Last verified 2026-08-13 by executing the recipe end to end.

The recipe

main.sh

How it works

  • Interact (stream) sends one event: trace frame per trace and closes with a single event: end, whose data is an empty object.
  • The frames carry the same trace types that the non-streaming endpoint returns as an array, so a renderer written for one works for the other.
  • config.completionEvents replaces the finished text trace with completion deltas. Completion events describes the start, content, and end states you stitch back together.
  • Every streamed request authorizes with the session key from start session, never with the project API key. See Authentication.
  • If you only need the finished reply, the non-streaming endpoint is simpler: see Run your first conversation turn.

When it fails