> ## 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.

# 删除 Environment

> 删除一个 Environment。

`DELETE /api/v1/cloud/environments/{environment_id}`

删除 Environment 并返回删除确认。如果该 Environment 仍被 Session 或 tool call 引用，API 会返回 `409`，此时应改为归档该 Environment。

## 请求头

| 头部              | 必选 | 说明             |
| --------------- | -- | -------------- |
| `Authorization` | 是  | `Bearer <PAT>` |

## 路径参数

| 参数               | 类型     | 必选 | 说明                  |
| ---------------- | ------ | -- | ------------------- |
| `environment_id` | string | 是  | 环境的唯一标识（前缀为 `env_`） |

## 示例请求

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

## 示例响应

**HTTP 200 OK**

```json theme={null}
{
  "id": "env_019e3bb39b6774d8878cd0b9d237574b",
  "type": "environment_deleted"
}
```

删除成功通过响应体中的 `"type": "environment_deleted"` 标识。

## 错误码

| HTTP | type                    | 说明                                    |
| ---- | ----------------------- | ------------------------------------- |
| 401  | `authentication_error`  | 认证失败，PAT 无效或过期                        |
| 403  | `permission_error`      | 无权访问此资源                               |
| 404  | `not_found_error`       | 指定 ID 的环境不存在                          |
| 409  | `invalid_request_error` | Environment 仍被 Session 或 tool call 引用 |

**HTTP 404 Not Found**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "not_found_error",
    "message": "Environment 'env_does_not_exist_0000000000000000000000000000' was not found."
  }
}
```

**HTTP 409 Conflict**

```json theme={null}
{
  "type": "error",
  "request_id": "cb80235f-76a2-4ff3-9e28-5aa2da12dc14",
  "error": {
    "type": "invalid_request_error",
    "message": "Environment 'env_019e3bb39b6774d8878cd0b9d237574b' is in use and cannot be deleted: 1 session still reference it. Archive the environment instead."
  }
}
```

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

## 相关

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