Streaming

Server-Sent Events.

Set "mode": "stream" on interpret to receive tokens as they generate, over text/event-stream.

Event types

EventDataMeaning
status{ stage, label }Lifecycle progress (e.g. retrieval).
token{ text }A chunk of the answer.
citations{ chunks: [...] }Source provenance (just before done).
done{ usage }Terminal success; the stream closes.
error{ code, message, details }Terminal failure; the stream closes.

Raw wire format

text
event: status
data: {"stage":"rag","label":"Searching the project…"}

event: token
data: {"text":"The main conveyor "}

event: token
data: {"text":"starts when the Start PB is pressed and no E-Stop is active…"}

event: citations
data: {"chunks":[{"id":"Routine:ConveyorControl/Rung:12"}]}

event: done
data: {"usage":{"input_tokens":1840,"output_tokens":412}}

Consuming via SDK

python
for event in client.interpret_stream(project_id="prj_…", prompt="…"):
    if event.type == "token":
        print(event.text, end="", flush=True)
    elif event.type == "done":
        print("\nusage:", event.usage)
csharp
await foreach (var ev in client.InterpretStreamAsync("prj_…", "…"))
{
    if (ev.Type == "token") Console.Write(ev.Text);
    else if (ev.Type == "done") Console.WriteLine($"\nusage: {ev.Usage}");
}