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

# Delete an environment

> Delete an Environment.

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

Deletes an Environment and returns a deletion confirmation. If the Environment is still referenced by Sessions or tool calls, the API returns `409` and you should archive it instead.

## Headers

| Header          | Required | Description    |
| --------------- | -------- | -------------- |
| `Authorization` | Yes      | `Bearer <PAT>` |

## Path parameters

| Parameter        | Type   | Required | Description                                            |
| ---------------- | ------ | -------- | ------------------------------------------------------ |
| `environment_id` | string | Yes      | Environment unique identifier (with the `env_` prefix) |

## Example request

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

## Example response

**HTTP 200 OK**

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

Successful deletion is signalled by `"type": "environment_deleted"` in the response body.

## Errors

| HTTP | Type                    | Trigger                                                   |
| ---- | ----------------------- | --------------------------------------------------------- |
| 401  | `authentication_error`  | PAT invalid or expired                                    |
| 403  | `permission_error`      | Not authorized for this resource                          |
| 404  | `not_found_error`       | Environment with the given ID does not exist              |
| 409  | `invalid_request_error` | Environment is still referenced by Sessions or tool calls |

**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."
  }
}
```

See [Errors](/cloud-agents/api/conventions/errors) for the full error envelope.

## Related

<CardGroup cols={2}>
  <Card title="Cloud environment setup" icon="server" href="/cloud-agents/environments">
    Choose the container, network, and dependencies your agent runs in.
  </Card>
</CardGroup>
