Ροές συμβάντων
Three kinds of streams use server-sent events (text/event-stream): an agent run answering a message, a code run, and a space’s live changes. Each event has a name (event:) and JSON data (data:). Ignore event names you don’t know: new ones can be added within /v1 (see Versioning).
Browsers’ EventSource can’t send an Authorization header, so read these streams from your server, for example with curl -N, the JavaScript SDK or any HTTP client that reads the body as it arrives.
Runs keep going without you
Agent runs and code runs are background work. Closing the connection doesn’t stop them; only cancelling does (cancelAgentRun, cancelCodeRun). Their events are kept for 24 hours, so you can follow a run from another process or reconnect after a dropped connection:
- Every event of a run has an
id:, its position in the run’s event log. - To resume, open the run’s events again with the
idof the last event you processed in aLast-Event-IDheader. You get only the events after it. Without the header you get them all from the start. - A
Last-Event-IDthat isn’t an event ID gets422withvalidation_failed. - While a run is quiet, Ivy sends a comment line (starting with
:) every 15 seconds to keep the connection open.
A run’s stream ends after its done or error event. When a finished run’s events are no longer kept, the stream sends only the outcome: done, or error with the run’s error code.
Agent runs
sendAgentMessage (POST …/conversations/{conversation_id}/messages) answers with the run’s stream straight away. Its Ivy-Run-Id response header names the run. To follow the run again, use streamAgentRun (GET …/conversations/{conversation_id}/runs/{run_id}/events), or send the same message again with the same client_message_id. Both need conversations:read or conversations:write.
| Event | Data |
|---|---|
message_start |
message_id, model: the reply has started. |
text_delta |
text: the next piece of the reply. |
thinking |
text: a short progress note. |
tool_call |
id, name, input: the agent uses a tool. |
tool_result |
id, status, summary, invalidates: the tool finished; invalidates names lists to refetch. |
tool_progress |
tool_use_id, event, data: live output of a running tool, such as a command or a code run. |
sandbox_status |
state, reason: the conversation’s sandbox is starting, ready, stopping, stopped, … |
changes_saved |
checkpoint, files, skipped: files the sandbox created or changed, saved as new versions. |
changes_pending |
change_set_id, deletes, conflicts: deletes and conflicting overwrites held for confirmation. |
done |
message: the complete reply. The stream ends. |
error |
code, message. The stream ends. |
A run started with an API key has no person to confirm a delete or a conflicting overwrite, so Ivy refuses those changes instead of leaving them waiting.
Common error codes are cancelled, usage_limit_reached, billing_restricted, rate_limited (the AI provider was overloaded; send the message again after a short wait) and reply_unavailable (the run finished but its reply can’t be found; read the conversation).
id: 1
event: message_start
data: {"message_id":"…","model":"…"}
id: 2
event: text_delta
data: {"text":"Last week"}
id: 3
event: text_delta
data: {"text":" there were 42 tickets."}
id: 4
event: done
data: {"message":{…}}
Code runs
streamCodeRun (GET …/spaces/{space_id}/runs/{run_id}/events) follows a run that startCodeRun started. It needs code_runs:read or code_runs:write.
| Event | Data |
|---|---|
run_status |
status: starting, running, collecting (saving outputs), then how the run ended. |
stdout, stderr |
data: the next piece of output. |
output_truncated |
stream, limit_bytes: the stream reached its output limit; later output isn’t sent. |
output_file |
path, file_id, version_id, media_type, size: an output saved as a file version. |
output_skipped |
path, code: an output that wasn’t saved, and why. |
usage |
cpu_millis, wall_millis, billed_cpu_seconds, credits: what the run used. |
done |
status, exit_code, outputs, cpu_millis, credits. The stream ends. |
error |
code, message. The stream ends. |
done comes for every run that ran, whether its code succeeded or not: its status is succeeded, failed, timeout or oom, and exit_code is the program’s. error means the run didn’t finish normally, for example cancelled, sandbox_busy (the organisation already runs as many code runs as its plan allows) or sandbox_interrupted. The run’s full output stays available afterwards from getCodeRunLog.
Space changes
streamSpaceEvents (GET …/spaces/{space_id}/events) tells you when something in a space changes, so you can read it again instead of polling. It needs workspaces:read. The events are hints to refetch, not the data itself:
| Event | Data |
|---|---|
entries |
parent_ids: folders whose contents changed; empty when any folder may have changed. |
file |
file_id: a file changed (new version, rename, move, trash or restore). |
scan |
file_id, version_id, scan_status: a version’s malware scan finished. |
members |
The space’s members changed. |
workspace |
The space’s name or settings changed, or it was archived or unarchived. |
trash |
The trash changed. |
revoked |
The service identity lost access to the space. The stream ends. |
These events have no IDs and can’t be resumed. After a reconnect, read again everything you show of the space. A comment line arrives every 25 seconds. When live events aren’t available, the request answers 503 with live_unavailable: poll instead.