Skip to main content
Work APIs are used by external workers attached to a self_hosted Environment. A worker polls for queued Session work, acknowledges the item it will run, keeps the lease alive with heartbeats, and stops the item when the work is complete or must be aborted.

Work item object

Returned by list, poll, get, update metadata, acknowledge, and stop endpoints.
FieldTypeDescription
idstringWork item ID with the work_ prefix
typestringAlways "work"
environment_idstringEnvironment ID with the env_ prefix
dataobjectWork payload descriptor
data.typestringCurrently always "session"
data.idstringSession ID with the sess_ prefix
statestringWork item state. See Work states
created_atstringCreation time in UTC
acknowledged_atstring|nullTime when a worker acknowledged the item, or null before ack
started_atstring|nullTime when the first heartbeat moved the item to active, or null before start
latest_heartbeat_atstring|nullLatest heartbeat timestamp, or null before the first heartbeat
stop_requested_atstring|nullTime when a graceful stop was requested, or null
stopped_atstring|nullTime when the item reached stopped, or null while live
metadataobjectString-only metadata associated with the work item

Work states

StateDescription
queuedThe work item is available to poll, or was delivered but not yet acknowledged
startingA worker acknowledged the item and should begin executing it
activeA worker sent a heartbeat and owns the current lease
stoppingA graceful stop was requested; the worker should drain and confirm stop
stoppedThe item is no longer live and cannot be heartbeated

Work metadata

Work metadata is a string-only map. When a Session creates a work item, the Session metadata is projected into this string map. Use Update work item metadata to merge changes:
  • String values upsert a key.
  • null deletes a key.
  • Omitting metadata leaves the current metadata unchanged.

Work heartbeat object

Returned by Send work heartbeat.
FieldTypeDescription
typestringAlways "work_heartbeat"
last_heartbeatstringServer timestamp for the accepted heartbeat
lease_extendedbooleanAlways true for a successful heartbeat
statestringCurrent work item state after the heartbeat
ttl_secondsintegerCurrent lease TTL in seconds

Work queue stats object

Returned by Get work queue stats.
FieldTypeDescription
typestringAlways "work_queue_stats"
depthintegerQueued items currently claimable by workers
pendingintegerQueued items delivered recently but not yet acknowledged
oldest_queued_atstring|nullCreation time of the oldest queued item, or null when the queue is empty
workers_pollingintegerDistinct Worker-ID values that polled this environment in the last 30 seconds

Cloud environment setup

Choose the container, network, and dependencies your agent runs in.