# Stop one VM: cancel its agents, stop its previews, delete it at Boat.

> The emergency stop for one VM; other VMs and crews are not touched, and the crew is not held, so its queued agents may still get a new VM.
> https://koi.dog/docs/api/cloud/stop-vm/

`POST /api/v1/vms/{id}/stop` · Scope: `crews`

Agents running on it are canceled (not requeued), previews on it are stopped, then the VM is deleted at Boat and waited for (up to the fleet's delete timeout) and its cost is settled once Boat confirms it gone. `result` says whether that was confirmed; if not, Koidog keeps trying and `GET /vms/{id}` shows when it is gone. Stopping a VM that already ended answers `already_gone`. Allowed to anyone who can control crews, as the emergency stop is: it only ends spending. The timeline records the key ID, action and outcome.

## Path parameters.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | yes | The VM'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 POST "https://api.koi.dog/api/v1/vms/$ID/stop" \
    -H "Authorization: Bearer $KOIDOG_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)"
```

```js
const res = await fetch(`https://api.koi.dog/api/v1/vms/${process.env.ID}/stop`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KOIDOG_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
console.log(await res.json());
```

```python
import os
import uuid

import requests

r = requests.post(
    f"https://api.koi.dog/api/v1/vms/{os.environ['ID']}/stop",
    headers={
        "Authorization": f"Bearer {os.environ['KOIDOG_API_KEY']}",
        "Idempotency-Key": str(uuid.uuid4()),
    },
)
r.raise_for_status()
print(r.json())
```

## Response example.

```json
{
  "vm": {
    "id": "string",
    "provider": "boat",
    "providerId": "string",
    "state": "intended",
    "type": "small",
    "baseTemplate": "string",
    …
  },
  "runsCanceled": 0,
  "previewsStopped": 0,
  "result": "deleted",
  "detail": "string",
  …
}
```
