Skip to main content
GET
Poll and claim a WorkItem

Headers

kimi-api-version
enum<string>

API version for this request, in YYYY-MM-DD form. Send 2026-09-01-beta for the version documented here. Required outside /v1/files*: a missing header there is rejected with 400 invalid_request_error; on /v1/files* its absence selects the compatibility behavior. An unknown value is rejected with 400 invalid_request_error on every endpoint. API versions served by the platform. New dated versions are added as they ship; a version is removed after its announced Sunset date.

Available options:
2026-09-01-beta

Path Parameters

environment_id
string
required

Environment whose queue is polled.

Query Parameters

worker_id
string
required

Worker identity the lease is taken under.

worker_version
integer<int32>

Worker protocol version.

Required range: x >= 0
block_ms
integer<int32>
default:0

Long-poll budget in milliseconds, at most 999: with 0 (default) the call returns immediately (204 when no compatible work is pending); with a positive value the call waits for work until the budget expires. Polling is not idempotent: each successful call claims the environment's oldest compatible pending item.

Required range: 0 <= x <= 999
lease_ttl_ms
integer<int32>

Requested lease length in milliseconds. Non-positive values take the platform default; larger values are clamped to it.

reclaim_older_than_ms
integer<int32>

How early this poll reclaims delivered items, in milliseconds (default 5000). Before returning work, it puts items delivered earlier than this threshold back on the queue. The ack window remains fixed at 5000ms; the background sweeper reclaims items when it expires. This parameter changes only how early this poll reclaims them. Ack immediately after delivery, and start a slow executor after ack. lease_ttl_ms controls recovery time.

Required range: x >= 0

Response

The delivered WorkItem; 204 when the block budget expired without compatible work.

One row of the self-hosted work queue: a Session whose sandbox tool calls execute on the environment owner's workers. GET /v1/environments/{environment_id}/work/poll delivers the item (still queued until acked); the generation it carries is the fencing token every later ack, heartbeat, and stop must present. user.tool_result writes need no explicit token: the session work token in secret carries the generation binding and the platform derives the fence from it.

id
string
required

WorkItem ID.

Example:

"work_01h455vb4pex5vsknk084sn02q"

session_id
string
required

Session the work item executes.

Example:

"sesn_01h455vb4pex5vsknk084sn02q"

environment_id
string
required

Environment whose workers may claim the item.

Example:

"env_01h455vb4pex5vsknk084sn02q"

status
enum<string>
required

Lifecycle status; poll only ever returns queued.

Available options:
queued,
starting,
active,
stopping,
completed,
failed,
cancelled
Example:

"queued"

generation
integer<int64>
required

The work item's session-scoped fencing token. Starts at 1 and increases; a normal release, a platform reclaim, or cancelling a live item also raises it. Use the value returned by poll for heartbeat, ack, and stop. A stale value is rejected with 412 failed_precondition_error.

Required range: x >= 1
Example:

1

lease_ttl_ms
integer<int64>
required

Lease length in milliseconds; heartbeats renew it.

Example:

300000

created_at
string<date-time>
required

When the item was enqueued.

Example:

"2026-09-20T12:00:00Z"

worker_id
string

Worker holding the lease.

Example:

"worker-1"

claimed_at
string<date-time>

When the current claim was taken.

Example:

"2026-09-20T12:00:00Z"

acknowledged_at
string<date-time>

Time when the worker acknowledged delivery. The ack call sets it within the delivery window.

Example:

"2026-09-20T12:01:00Z"

started_at
string<date-time>

When the first heartbeat activated the item (starting → active).

Example:

"2026-09-20T12:02:00Z"

latest_heartbeat_at
string<date-time>

When the most recent heartbeat landed; absent before the first one.

Example:

"2026-09-20T12:05:00Z"

stop_requested_at
string<date-time>

First stop request time; retained across lease reclamation.

Example:

"2026-09-20T12:06:00Z"

stopped_at
string<date-time>

When the item reached a terminal status; absent while live.

Example:

"2026-09-20T12:07:00Z"

secret
string

Credential bundle for the Session that owns this WorkItem. Only the poll response that leases the item includes it. The bundle is a base64url- encoded JSON object. Decode it and send its sessions_token as Authorization: Bearer for Session write endpoints (for example, POST /v1/sessions/{id}/events) and this WorkItem's ack, heartbeat, and stop requests. The token is scoped to that Session. Other bundle members are reserved; leave them unchanged. The credential expires when the item is settled or reclaimed. A reclaim gives the item to another worker with a new credential and invalidates this one. No other endpoint returns it. Treat the bundle as a secret. Do not log or persist it.

Example:

"eyJzZXNzaW9uc190b2tlbiI6InN3dC1hYmNkZWZnaGlqa2xtbm9wcXJzdHV2d3h5ejAxMjM0NTY3ODlBQkNERUZHIn0"