Zaroz
Units API guide

Events

Every unit transition and every scaling change is written to an append-only log, in the same database transaction as the change. Read it with a cursor.

curl

TerminalCode
# long-poll: returns as soon as an event after cursor 0 exists, or after 30 s curl -sS -G "$UNITS/events" -H "$AUTH" \ --data-urlencode "after=0" --data-urlencode "wait=30" --data-urlencode "limit=100" \ --data-urlencode "types=unit.ready,unit.exited,unit.destroyed"

TypeScript

TypeScriptCode
let after = 0; for (;;) { const { status, body } = await call( "GET", `${UNITS}/events?after=${after}&wait=30&types=unit.ready,unit.exited,unit.destroyed`, ); if (status === 410) { after = body.resume_after; continue; } // cursor_expired for (const e of body.events) { console.log(e.seq, e.type, e.unit?.key, e.data); // persist e.seq next to your own state: it is the dedupe key } after = body.next_after; }

Python

Code
after = 0 while True: status, body = call( "GET", f"{UNITS}/events", params={"after": after, "wait": 30, "types": "unit.ready,unit.exited,unit.destroyed"}, ) if status == 410: # cursor-expired after = body["resume_after"] continue for e in body["events"]: print(e["seq"], e["type"], (e["unit"] or {}).get("key"), e["data"]) # persist e["seq"] next to your own state: it is the dedupe key after = body["next_after"]

The envelope (contract v1)

JSONCode
{ "seq": 1042, "id": "evt_0e8b5c6a-6f43-4b6b-8d36-6c9c1f2ad711", "type": "unit.exited", "contract_version": 1, "occurred_at": "2026-10-14T10:31:07Z", "service_instance_id": "6c9d...", "unit": {"id": "3f2a...", "key": "job-81", "labels": {"queue": "render"}}, "data": {"code": 0, "restarted": false} }

seq is gapless and strictly increasing per Workload, so a cursor never skips an event that commits late. Consumers must ignore unknown fields and unknown event types: additions are never a new version.

Typedata
unit.stopped{reason} and the facts in How a unit ended
unit.created, unit.starting, unit.ready, unit.idle, unit.busy, unit.draining
unit.accepting, unit.not_accepting
unit.allocated, unit.allocation_delivered, unit.allocation_undelivered
unit.exited{code, restarted} and the facts in How a unit ended
unit.failed{reason} and the same facts
unit.destroyed{reason} (expired when destroyed after being stopped too long, start_deadline when a unit created stopped was not started in time) and the same facts
units.scaled{from, to, reason}; unit is null
rollout.started, rollout.completed, rollout.pausedunit is null
webhook.ping (webhook deliveries only)
events.gap (webhook deliveries only){from_seq, to_seq}: events a re-enabled webhook missed because they were no longer kept

unit.ready and unit.allocated carry the unit's private name and public address, so a matchmaker needs no second read. idle and busy are emitted on transitions only.

Why a unit stopped

unit.stopped carries data.reason:

reasonMeaning
requestedyour program (or you, through the API) stopped it
exitedits process exited and the unit's on_exit is stop
service_stoppedthe whole Workload was stopped
memory_limitit stayed over its memory budget for a sustained period. A unit created by your program is stopped alone; see Limits
idleit sat idle past its idle timeout and the policy is stop
ready_timeoutit did not become ready within its ready timeout

Events written before the reason was recorded have none, and new reasons may be added: treat an unknown value as a plain stop.

How a unit ended

The events that end a unit (unit.stopped, unit.exited, unit.failed and unit.destroyed) all carry the same facts in data, next to their own fields. The same facts are on the unit itself, as termination, so you can read them without the log.

JSONCode
{ "type": "unit.stopped", "data": { "reason": "memory_limit", "ordered_by": {"kind": "platform"}, "phase": "ready", "exit_code": 137, "oom_killed": true, "last_heartbeat_at": "2026-10-31T12:04:51Z", "on_exit": "stop" } }
FieldMeaning
ordered_bywho ended it. kind is program (your code, through the unit control API), person (a member of your organization; user_id says which), staff (Zaroz staff acting on your service; no id is given), platform (memory enforcement, the scaling policy, a rollout, a service stop) or process (the process ended by itself)
reasonthe same word as the event's own reason. unit.exited has exited
phasehow far the unit got: starting (it never became ready), ready, or draining (it was winding down). null if it never had a pod
exit_codethe process exit code, when one was recorded
oom_killedtrue when the container was killed for running out of memory
last_heartbeat_atwhen the unit's agent last reported before the end. null if the agent never reported
on_exitthe unit's on_exit at that time: restart, stop or destroy

Use ordered_by to tell a stop you ordered from one the platform ordered. A health check of your own that fails shows as program; a memory stop shows as platform. last_heartbeat_at comes from the unit's own reports, never from a guess, so a null means the unit never said anything.

unit.destroyed has a reason too: removed (a destroy call), memory_limit, exited, scaled_in, service_deleted, idle, ready_timeout, expired or start_deadline (a unit created stopped with start_within_seconds that never started; see Reservations that never start). Events written before these fields existed carry only their reason (and code for an exit). Their ordered_by is then the usual one for that reason, oom_killed is false and the other facts are null.

Parameters

ParameterMeaning
afterthe last seq you saw; 0 starts at the oldest kept event
typescomma-separated list to keep
limitup to 500
wait0 to 30 seconds: with nothing new, hold the request and return the moment an event arrives

The response is {events, next_after, oldest_retained_seq}. Send next_after as the next after. Events are kept 30 days. A cursor older than that answers 410 cursor_expired with resume_after.

Delivery is at-least-once

Persist the last seq you processed in the same transaction as your own effect, and treat a repeated seq as already done. This is the same rule that makes webhooks safe.

Last modified on