> ## Documentation Index
> Fetch the complete documentation index at: https://docs.qoder.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 确认 Work

> 执行 work item 前确认已接收。

`POST /api/v1/cloud/environments/{environment_id}/work/{work_id}/ack`

确认一个已投递的 work item，并将其从 `queued` 推进到 `starting`。worker 应在 poll 后、执行 Session work 前调用该接口。

对已经处于 `starting` 或 `active` 的 item，ack 可安全重试。对 `stopping` 或 `stopped` item，ack 会冲突。

## 路径参数

| 参数               | 类型     | 说明                        |
| ---------------- | ------ | ------------------------- |
| `environment_id` | string | Environment ID，前缀为 `env_` |
| `work_id`        | string | Work item ID，前缀为 `work_`  |

## 请求头

| 头部              | 必选 | 说明                                                    |
| --------------- | -- | ----------------------------------------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT`                                   |
| `Worker-ID`     | 否  | 稳定的 worker 标识。如果 poll 已记录了不同的 `Worker-ID`，ack 会返回 409 |

## 示例请求

```bash theme={null}
curl -X POST "https://api.qoder.com/api/v1/cloud/environments/env_019e64e01a137caf953ac2ac7b42ec5c/work/work_019f3be4fd2475d9a784bf2c739e1194/ack" \
  -H "Authorization: Bearer $QODER_PAT" \
  -H "Worker-ID: byoc-worker-01"
```

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "id": "work_019f3be4fd2475d9a784bf2c739e1194",
  "type": "work",
  "environment_id": "env_019e64e01a137caf953ac2ac7b42ec5c",
  "data": {
    "type": "session",
    "id": "sess_019f3be3fa66750bb9a1fbcde85b5fe1"
  },
  "state": "starting",
  "created_at": "2026-07-01T08:15:01Z",
  "acknowledged_at": "2026-07-01T08:15:04Z",
  "started_at": null,
  "latest_heartbeat_at": null,
  "stop_requested_at": null,
  "stopped_at": null,
  "metadata": {}
}
```

## 响应字段

返回已 ack 的 [Work item 对象](/zh/cloud-agents/api/environments/work/schemas#work-item-对象)。

## 错误码

| HTTP | type                    | 触发条件                                                         |
| ---- | ----------------------- | ------------------------------------------------------------ |
| 400  | `invalid_request_error` | Environment 不是 `self_hosted`                                 |
| 401  | `authentication_error`  | PAT 无效或过期                                                    |
| 403  | `permission_error`      | 无权限执行此操作                                                     |
| 404  | `not_found_error`       | Environment 或 work item 不存在                                  |
| 409  | `invalid_request_error` | Work item 已被其他 worker claim、状态并发变化，或已处于 `stopping`/`stopped` |

完整错误信封格式见 [错误参考](/zh/cloud-agents/api/conventions/errors)。

## 注意事项

* ack 后，第一次 heartbeat 通常使用 `expected_last_heartbeat=NO_HEARTBEAT`。
* ack 会触发一次即时 dispatch，让 work 无需等待下一次 dispatcher tick 即可继续。

## 相关

<CardGroup cols={2}>
  <Card title="云端环境" icon="server" href="/zh/cloud-agents/environments">
    选择 Agent 运行的容器、网络与依赖。
  </Card>
</CardGroup>
