> ## 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 队列统计

> 读取 self-hosted Environment 的队列深度和 worker polling 统计。

`GET /api/v1/cloud/environments/{environment_id}/work/stats`

返回 `self_hosted` Environment 的 work 队列统计。

## 路径参数

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

## 请求头

| 头部              | 必选 | 说明                  |
| --------------- | -- | ------------------- |
| `Authorization` | 是  | `Bearer $QODER_PAT` |

## 示例请求

```bash theme={null}
curl -X GET "https://api.qoder.com/api/v1/cloud/environments/env_019e64e01a137caf953ac2ac7b42ec5c/work/stats" \
  -H "Authorization: Bearer $QODER_PAT"
```

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "type": "work_queue_stats",
  "depth": 3,
  "pending": 1,
  "oldest_queued_at": "2026-07-01T08:15:01Z",
  "workers_polling": 2
}
```

## 响应字段

返回 [Work queue stats 对象](/zh/cloud-agents/api/environments/work/schemas#work-queue-stats-对象)。

## 错误码

| HTTP | type                    | 触发条件                         |
| ---- | ----------------------- | ---------------------------- |
| 400  | `invalid_request_error` | Environment 不是 `self_hosted` |
| 401  | `authentication_error`  | PAT 无效或过期                    |
| 403  | `permission_error`      | 无权限执行此操作                     |
| 404  | `not_found_error`       | Environment 不存在              |

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

## 注意事项

* `depth` 统计当前可 claim 的 queued item。
* `pending` 统计最近已投递但尚未 ack 的 queued item。
* `workers_polling` 只统计带有 `Worker-ID` 的 poll 请求。

## 相关

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