Events

text

{ type: "text", text, final }

The complete text of a turn, once. Its streaming companion is text_delta, which arrives piece by piece while the turn is still being written.

one per turn with textfinal says if it is the answertext_delta streams
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Fields

textstring

Everything the model wrote in this turn.

finalboolean

true when the turn asked for no tool — so this is the answer, and the loop is ending.

Most text is not the answer

A model usually writes a sentence before calling a tool — « I will read the file first. » Those arrive with final: false. Only the last one, the turn with no tool call, is the answer.

onEvent: (e) => {
  if (e.type !== "text") return;
  if (e.final) showAnswer(e.text);
  else showThinkingAloud(e.text);
}
def on_event(event):
    if event["type"] == "text":
        show_answer(event["text"])

text_delta

{ type: "text_delta", delta: "I will read " }
# The Python engine emits each turn's text as one "text" event;
# to stream it token by token, call api.models.turn(on_text=...) directly.
{"type": "text", "text": "I will read the four notes…"}

One per piece as the provider produces it. It is the only event that arrives during a turn — everything else is emitted between two things.

Do not render both for the same turn

The deltas of a turn add up to exactly its text event. A display that appends the deltas and then appends the text shows every answer twice. Stream the deltas and use text to replace what you streamed, or ignore one of the two.

A delegated run emits one final text

When a message starts with @agent, the named agent does the work and its report is the answer: one text with final: true, then done.

The run returns the last one

result.text is the most recent text of the run — which on a run ending at a ceiling may not be final. Checking stopReason is what tells you whether it is an answer.

A subagent's events arrive here too

They carry parentId — the identifier of the task call that started them — and agent, its name. Their own id is prefixed with the task's, so two runs never collide. Test parentId before treating an event as the main run's.