SPB Git

Repository Public

poll.md 5.4 KB 253 lines markdown

1---2title: Poll for Work3url: https://platform.claude.com/docs/en/api/beta/environments/work/poll4---56# Poll for Work78**GET** `/v1/environments/{environment_id}/work/poll`910Note: these endpoints are called automatically by the pre-built environment worker provided in the SDKs and CLI, for orchestrating sessions with self-hosted sandbox environments. They are included here as a reference; you do not need to invoke them directly.1112Long poll for work items in the queue.1314## Path parameters1516- `environment_id: string`1718## Query parameters1920- `block_ms: optional number`2122  How long to wait for work to arrive before returning. Must be 1-999 in milliseconds. Defaults to non-blocking (returns immediately if no work is available).2324  minimum: 12526- `reclaim_older_than_ms: optional number`2728  Reclaim unacknowledged work items older than this many milliseconds. If omitted, uses the default (5000ms).2930  minimum: 13132## Headers3334- `"anthropic-beta": optional array of AnthropicBeta`3536  Optional header to specify the beta version(s) you want to use.3738  - `string`3940  - `"message-batches-2024-09-24" or "prompt-caching-2024-07-31" or "computer-use-2024-10-22" or 43 more`4142    - `"message-batches-2024-09-24"`4344    - `"prompt-caching-2024-07-31"`4546    - `"computer-use-2024-10-22"`4748    - `"computer-use-2025-01-24"`4950    - `"pdfs-2024-09-25"`5152    - `"token-counting-2024-11-01"`5354    - `"token-efficient-tools-2025-02-19"`5556    - `"output-128k-2025-02-19"`5758    - `"files-api-2025-04-14"`5960    - `"mcp-client-2025-04-04"`6162    - `"mcp-client-2025-11-20"`6364    - `"dev-full-thinking-2025-05-14"`6566    - `"interleaved-thinking-2025-05-14"`6768    - `"code-execution-2025-05-22"`6970    - `"extended-cache-ttl-2025-04-11"`7172    - `"context-1m-2025-08-07"`7374    - `"context-management-2025-06-27"`7576    - `"model-context-window-exceeded-2025-08-26"`7778    - `"skills-2025-10-02"`7980    - `"fast-mode-2026-02-01"`8182    - `"output-300k-2026-03-24"`8384    - `"user-profiles-2026-03-24"`8586    - `"user-profiles-2026-08-18"`8788    - `"user-profiles-2026-09-04"`8990    - `"advisor-tool-2026-03-01"`9192    - `"managed-agents-2026-04-01"`9394    - `"cache-diagnosis-2026-04-07"`9596    - `"dreaming-2026-04-21"`9798    - `"thinking-token-count-2026-05-13"`99100    - `"server-side-fallback-2026-06-01"`101102    - `"server-side-fallback-2026-07-01"`103104    - `"fallback-credit-2026-06-01"`105106    - `"fallback-credit-2026-07-01"`107108    - `"agent-memory-2026-07-22"`109110    - `"mid-conversation-tool-changes-2026-07-01"`111112    - `"compact-2026-01-12"`113114    - `"computer-use-2025-11-24"`115116    - `"mcp-tunnels-2026-06-22"`117118    - `"structured-outputs-2025-11-13"`119120    - `"task-budgets-2026-03-13"`121122    - `"thinking-display-updates-2026-08-18"`123124    - `"ce-user-management-2026-07-13"`125126    - `"mid-conversation-output-config-2026-07-01"`127128    - `"thinking-binding-controls-2026-08-01"`129130    - `"mid-conversation-system-clear-at-2026-08-21"`131132    - `"compact-2026-09-04"`133134- `"Anthropic-Worker-ID": optional string`135136  Unique identifier for the specific worker polling, used to track aggregated environment-level work metrics in Console137138## Returns139140- `BetaSelfHostedWork object`141142  Work resource representing a unit of work in a self-hosted environment.143144  Work items are queued when sessions are created or when long-dormant sessions145  receive new messages. The environment worker polls for work to execute in a146  self-hosted sandbox.147148  - `type: "work"`149150    The type of object (always 'work')151152    default: work153154  - `id: string`155156    Work identifier (e.g., 'work_...')157158  - `acknowledged_at: string or null`159160    RFC 3339 timestamp when the work item was acknowledged and assigned to a self-hosted sandbox161162  - `created_at: string`163164    RFC 3339 timestamp when work was created165166  - `data: BetaSessionWorkData`167168    The actual work to be performed169170    - `type: "session"`171172      Type of work data173174    - `id: string`175176      Session identifier (e.g., 'session_...')177178  - `environment_id: string`179180    Environment identifier this work belongs to (e.g., `env_...`)181182  - `latest_heartbeat_at: string or null`183184    RFC 3339 timestamp of the most recent heartbeat185186  - `metadata: map[string]`187188    User-provided metadata key-value pairs associated with this work item189190  - `secret: string or null`191192    Credential payload used by the environment worker to execute this work item. May be populated when polling for work; null on all other retrieval paths.193194  - `started_at: string or null`195196    RFC 3339 timestamp when work execution started197198  - `state: "queued" or "starting" or "active" or 2 more`199200    Current state of the work item201202    - `"queued"`203204    - `"starting"`205206    - `"active"`207208    - `"stopping"`209210    - `"stopped"`211212  - `stop_requested_at: string or null`213214    RFC 3339 timestamp when stop was requested215216  - `stopped_at: string or null`217218    RFC 3339 timestamp when work execution stopped219220## Example221222```bash223curl https://api.anthropic.com/v1/environments/$ENVIRONMENT_ID/work/poll \224    -H 'anthropic-version: 2023-06-01' \225    -H 'anthropic-beta: managed-agents-2026-04-01' \226    -H "X-Api-Key: $ANTHROPIC_API_KEY"227```228229### Response (200)230231```json232{233  "id": "id",234  "acknowledged_at": "acknowledged_at",235  "created_at": "created_at",236  "data": {237    "id": "id",238    "type": "session"239  },240  "environment_id": "environment_id",241  "latest_heartbeat_at": "latest_heartbeat_at",242  "metadata": {243    "foo": "string"244  },245  "secret": "secret",246  "started_at": "started_at",247  "state": "queued",248  "stop_requested_at": "stop_requested_at",249  "stopped_at": "stopped_at",250  "type": "work"251}252```253
Files main
Menu

Theme