Stream run events
Start the run with "wait": false, then read its events as
Server-Sent Events :
RUN=$(curl -s https://api.ngamia.com/v1/agents/duka-helper/runs \
-H "Authorization: Bearer $NGAMIA_KEY" -H 'content-type: application/json' \
-d '{"input":"Bei ya simu ya Tecno Spark ni ngapi?","user":"customer-42","wait":false}' | jq -r .run_id)
curl -N "https://api.ngamia.com/v1/runs/$RUN/events?user=customer-42" \
-H "Authorization: Bearer $NGAMIA_KEY"id: 0
event: run.started
data: {"agent":"duka-helper","thread_id":null,"previous_run_id":null,"run_id":"…","seq":0,"at_ms":1764240000000}
id: 1
event: model.replied
data: {"text":null,"tool_calls":[{"id":"call_1","name":"knowledge_search","args":{"query":"bei Tecno Spark"}}],"input_tokens":812,"output_tokens":24,"run_id":"…","seq":1,"at_ms":…}
id: 2
event: tool.started
…
event: run.completed
data: {"output":"…","run_id":"…","seq":5,"at_ms":…}| Event | data fields |
|---|---|
run.started | agent, thread_id, previous_run_id |
model.replied | text, tool_calls (id, name, args), input_tokens, output_tokens |
tool.started | call_id |
tool.finished | call_id, is_error, output |
approval.requested, approval.resolved | approval details (not used by platform agents in this release) |
run.completed | output |
run.failed | error |
run.cancelled | reason |
Every event also has run_id, seq (also the SSE id) and at_ms.
- Resume after a dropped connection with the
Last-Event-IDheader set to the lastidyou saw. No events are lost. - The stream ends after a terminal event (
run.completed,run.failed,run.cancelled). - Pass the same
userthe run was started with. - In browsers, stream through your own server so the API key stays private.