Claude Platform Docs

Trabalho

Obter item de trabalho
client.beta.environments.work.retrieve(workID, params, options?): BetaSelfHostedWork
GET/v1/environments/{environment_id}/work/{work_id}

Retrieve detailed information about a specific work item.

Fazer polling por trabalho
client.beta.environments.work.poll(environmentID, params?, options?): BetaSelfHostedWork | null
GET/v1/environments/{environment_id}/work/poll

Observação: esses endpoints são chamados automaticamente pelo worker de ambiente pré-construído fornecido nos SDKs e na CLI, para orquestrar sessões com ambientes sandbox auto-hospedados. Eles estão incluídos aqui como referência; você não precisa invocá-los diretamente.

Confirmar recebimento de trabalho
client.beta.environments.work.ack(workID, params, options?): BetaSelfHostedWork
POST/v1/environments/{environment_id}/work/{work_id}/ack

Observação: esses endpoints são chamados automaticamente pelo worker de ambiente pré-construído fornecido nos SDKs e na CLI, para orquestrar sessões com ambientes sandbox auto-hospedados. Eles estão incluídos aqui como referência; você não precisa invocá-los diretamente.

Registrar heartbeat
client.beta.environments.work.heartbeat(workID, params, options?): BetaSelfHostedWorkHeartbeatResponse
POST/v1/environments/{environment_id}/work/{work_id}/heartbeat

Observação: esses endpoints são chamados automaticamente pelo worker de ambiente pré-construído fornecido nos SDKs e na CLI, para orquestrar sessões com ambientes sandbox auto-hospedados. Eles estão incluídos aqui como referência; você não precisa invocá-los diretamente.

Parar trabalho
client.beta.environments.work.stop(workID, params, options?): BetaSelfHostedWork
POST/v1/environments/{environment_id}/work/{work_id}/stop

Stop a work item, initiating graceful or forced shutdown.

Listar itens de trabalho
client.beta.environments.work.list(environmentID, params?, options?): PageCursor<BetaSelfHostedWork>
GET/v1/environments/{environment_id}/work

List work items in an environment.

Atualizar item de trabalho
client.beta.environments.work.update(workID, params, options?): BetaSelfHostedWork
POST/v1/environments/{environment_id}/work/{work_id}

Update work item metadata with merge semantics.

Obter estatísticas da fila
client.beta.environments.work.stats(environmentID, params?, options?): BetaSelfHostedWorkQueueStats
GET/v1/environments/{environment_id}/work/stats

Obtenha estatísticas sobre a fila de trabalho de um ambiente.

Models
interface BetaHeartbeatPreconditionFailedErrorDetails { current_state; error_code }
current_state: BetaWorkLeaseState { last_heartbeat; lease_extended; state; ttl_seconds }

The lease as the server holds it.

last_heartbeat: string | null

RFC 3339 timestamp of the stored heartbeat, or null if there has been none

lease_extended: boolean

Always false: a refused heartbeat does not extend the lease

state: "queued" | "starting" | "active" | 2 more

Current state of the work item

One of the following:
"queued"
"starting"
"active"
"stopping"
"stopped"
ttl_seconds: number

TTL of the lease

error_code: "heartbeat_precondition_failed"
interface BetaSelfHostedWork { type: "work"; id; acknowledged_at; /* 10 more */ }

Work resource representing a unit of work in a self-hosted environment.

Work items are queued when sessions are created or when long-dormant sessions receive new messages. The environment worker polls for work to execute in a self-hosted sandbox.

interface BetaSelfHostedWorkHeartbeatResponse { type: "work_heartbeat"; last_heartbeat; lease_extended; /* 2 more */ }

Response after recording a heartbeat for a work item.

type: "work_heartbeat"

The type of response

defaultwork_heartbeat
last_heartbeat: string

RFC 3339 timestamp of the most recent heartbeat recorded for this work item, or an empty string if none has been recorded

lease_extended: boolean

Whether the heartbeat succeeded in extending the lease

state: "queued" | "starting" | "active" | 2 more

Current state of the work item (active/stopping/stopped)

One of the following:
"queued"
"starting"
"active"
"stopping"
"stopped"
ttl_seconds: number

Effective TTL applied to the lease

interface BetaSelfHostedWorkListResponse { data; next_page }

Response when listing work items with cursor-based pagination.

interface BetaSelfHostedWorkQueueStats { type: "work_queue_stats"; depth; oldest_queued_at; /* 2 more */ }

Statistics about the work queue for an environment.

type: "work_queue_stats"

The type of object

defaultwork_queue_stats
depth: number

Number of work items waiting to be picked up

oldest_queued_at: string | null

RFC 3339 timestamp of oldest item in the work stream (includes both queued and pending items), null if stream empty

pending: number

Number of work items being processed (polled but not acknowledged)

default0
workers_polling: number | null

Number of workers that have polled for work in the last 30 seconds. Requires worker_id to be sent with poll requests.

interface BetaSelfHostedWorkStopRequest { force }

Request to stop a work item.

force?: boolean

If true, immediately stop work without graceful shutdown

defaultfalse
interface BetaSelfHostedWorkUpdateRequest { metadata }

Request to update work item metadata.

metadata: Record<string, string | null>

Metadata patch. Set a key to a string to upsert it, or to null to delete it. Omit the field to preserve existing metadata.

interface BetaSessionWorkData { type: "session"; id }

Work data for session work items.

This resource type is used when work represents a session that needs to be executed in a self-hosted environment.

type: "session"

Type of work data

id: string

Session identifier (e.g., 'session_...')

interface BetaWorkLeaseState { last_heartbeat; lease_extended; state; ttl_seconds }

A work item's lease as the server holds it.

last_heartbeat: string | null

RFC 3339 timestamp of the stored heartbeat, or null if there has been none

lease_extended: boolean

Always false: a refused heartbeat does not extend the lease

state: "queued" | "starting" | "active" | 2 more

Current state of the work item

One of the following:
"queued"
"starting"
"active"
"stopping"
"stopped"
ttl_seconds: number

TTL of the lease

Errors
class BetaHeartbeatPreconditionFailedError extends PreconditionFailedError { errorCode; details }⁠HTTP status 412

expected_last_heartbeat does not match the stored heartbeat, so another worker may hold the lease.

errorCode: "heartbeat_precondition_failed"
details: BetaHeartbeatPreconditionFailedErrorDetails { current_state; error_code }
current_state: BetaWorkLeaseState { last_heartbeat; lease_extended; state; ttl_seconds }

The lease as the server holds it.

last_heartbeat: string | null

RFC 3339 timestamp of the stored heartbeat, or null if there has been none

lease_extended: boolean

Always false: a refused heartbeat does not extend the lease

state: "queued" | "starting" | "active" | 2 more

Current state of the work item

One of the following:
"queued"
"starting"
"active"
"stopping"
"stopped"
ttl_seconds: number

TTL of the lease

error_code: "heartbeat_precondition_failed"