# Delete a crew that ended, with its work.

> Only a crew that ended (`completed`, `failed` or `canceled`): a live one answers `409 crew_live`; cancel it first with `POST /crews/{id}/cancel`.
> https://koi.dog/docs/api/crews/delete-crew/

`DELETE /api/v1/crews/{id}` · Scopes: `crews`, `approve`

An ended crew is refused (`409 crew_busy`) while an agent is still stopping on its machine, a preview of it runs or a pull request Koidog opened for it is still open: one `details` entry per reason, each with its `code` (`agent_stopping`, `preview_running`, `pull_request_open`) and the `next` actions that resolve it. `GET /deletions/check?kind=crew&id=` answers the same without deleting. Removes its tasks, agents, runs and their logs, approvals, steering messages, previews, its pull request records, its artifacts and run bundles (on this disk and in the file store) and its branches in the server's git mirror. Kept: its timeline events (they still name the crew's id), its VM and cost records, and every branch and pull request on GitHub. Answers what was removed; deleting it again answers the same record with `alreadyDeleted: true`; an id that never existed is `404`. Destructive, so a key needs `approve` as well as `crews`. The timeline records the key ID, action and outcome.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The crew's id. |

## Headers.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Idempotency-Key` | `string` | no | Retry the same request with the same key. [Retry rules](https://koi.dog/docs/api/#retries). |

## Response.

200 OK · JSON object

## Request.

```sh
curl -X DELETE "https://api.koi.dog/api/v1/crews/$ID" \
    -H "Authorization: Bearer $KOIDOG_API_KEY"
```

```js
const res = await fetch(`https://api.koi.dog/api/v1/crews/${process.env.ID}`, {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
  },
});
console.log(await res.json());
```

```python
import os

import requests

r = requests.delete(
    f"https://api.koi.dog/api/v1/crews/{os.environ['ID']}",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "kind": "crew",
  "id": "string",
  "name": "string",
  "projectId": "string",
  "crewId": "string",
  "deletedAt": "string",
  "deletedBy": "string",
  "trigger": "request",
  "removed": {
    "crews": 0,
    "tasks": 0,
    "agents": 0,
    "runs": 0,
    "logLines": 0,
    "artifacts": 0,
    …
  },
  "kept": [],
  "alreadyDeleted": false,
  …
}
```
