> ## 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` を返します。その場合は、削除ではなくアーカイブしてください。

## ヘッダー

| ヘッダーフィールド     | 値                   | 必須 | 説明         |
| ------------- | ------------------- | -- | ---------- |
| Authorization | `Bearer $QODER_PAT` | はい | 個人アクセストークン |

## パスパラメータ

| パラメータ            | 型      | 必須 | 説明                                 |
| ---------------- | ------ | -- | ---------------------------------- |
| `environment_id` | string | はい | Environment の一意識別子（`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 ステータスコード | エラータイプ                  | 説明                                           |
| ------------- | ----------------------- | -------------------------------------------- |
| 401           | `authentication_error`  | 認証失敗、PAT が無効または期限切れ                          |
| 403           | `permission_error`      | このリソースにアクセスする権限がない                           |
| 404           | `not_found_error`       | 指定 ID の Environment が存在しない                   |
| 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."
  }
}
```

[エラー](/ja/cloud-agents/api/conventions/errors)で完全なエラーエンベロープを参照してください。

## 関連項目

<CardGroup cols={2}>
  <Card title="クラウド環境" icon="server" href="/ja/cloud-agents/environments">
    Agent が動作するコンテナ、ネットワーク、依存関係を選択する。
  </Card>
</CardGroup>
