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

# Delete Environment

> Clean up an environment and its database schema

## Request

```bash theme={null}
DELETE /api/platform/env/{envId}
```

### Path Parameters

<ParamField path="envId" type="string" required>
  Environment ID from `initEnv`
</ParamField>

### Example Request

```bash theme={null}
curl -X DELETE https://api.agentdiff.dev/api/platform/env/abc123def456 \
  -H "X-API-Key: ad_live_sk_..."
```

## Response

<ResponseField name="environmentId" type="string">
  Environment identifier that was deleted
</ResponseField>

<ResponseField name="status" type="string">
  Status: `"deleted"`
</ResponseField>

### Example Response

```json theme={null}
{
  "environmentId": "abc123def456",
  "status": "deleted"
}
```

## What Happens

1. **Schema dropped**: PostgreSQL schema and all data deleted
2. **Record updated**: Environment marked as deleted in database
3. **Resources freed**: Pool slot recycled for reuse

<Tip>
  Always delete environments when done to free up resources. Environments auto-expire after their TTL, but explicit deletion is faster.
</Tip>

## Errors

| Error                         | Status | Description                     |
| ----------------------------- | ------ | ------------------------------- |
| `environment_not_found`       | 404    | Environment doesn't exist       |
| `environment_already_deleted` | 400    | Environment was already deleted |

## SDK Usage

<CodeGroup>
  ```python Python theme={null}
  # Delete environment
  client.delete_env(envId=env.environmentId)
  print("Environment cleaned up")
  ```

  ```typescript TypeScript theme={null}
  // Delete environment
  await client.deleteEnv(env.environmentId);
  console.log('Environment cleaned up');
  ```
</CodeGroup>

## Best Practices

<AccordionGroup>
  <Accordion title="Always clean up in finally blocks">
    ```python theme={null}
    env = client.init_env(...)
    try:
        run = client.start_run(envId=env.environmentId)
        # ... your test code ...
    finally:
        client.delete_env(envId=env.environmentId)
    ```
  </Accordion>

  <Accordion title="Use context managers (Python)">
    ```python theme={null}
    # Coming soon: context manager support
    # with client.environment(...) as env:
    #     ...
    ```
  </Accordion>
</AccordionGroup>
