# Resource Endpoints

This page covers the four endpoints that change a stopped VM's vCPU, memory, disk, and node.

Every endpoint requires a stopped VM, is subject to `ALLOW_IPS` and the disabled list, and runs on the VM's node via [Multi-Node Dispatch](/multi-node-dispatch).

## Overview

| Endpoint | Field | Validation | `qm` command | Response |
|---|---|---|---|---|
| `POST /api/vm/:id/set/cpu` | `cpu` int | required, 1–32 | `qm set --cores` | text `ok` |
| `POST /api/vm/:id/set/memory` | `memory` int | required, 512–32768 (MB) | `qm set --memory` | text `ok` |
| `POST /api/vm/:id/set/disk` | `disk` string | none | `qm disk resize scsi0 +<disk>` | text `ok` |
| `POST /api/vm/:id/set/node` | `node` string | required | `qm migrate --with-local-disks` | SSE |

These limits are fixed in code and ignore `VM_MAX_CPU` / `VM_MAX_RAM` / `VM_MAX_DISK`.

## vCPU

```bash
curl -X POST http://192.168.0.11:8080/api/vm/120/set/cpu \
  -H "Content-Type: application/json" -d '{"cpu": 4}'
# ok
```

## Memory

```bash
curl -X POST http://192.168.0.11:8080/api/vm/120/set/memory \
  -H "Content-Type: application/json" -d '{"memory": 8192}'
# ok
```

With `VM_BALLOON_MIN` set and `memory` ≥ `VM_BALLOON_MIN` + 1024, the call also sends `--numa 1 --balloon <memory − VM_BALLOON_MIN>`. Below the threshold no `--balloon` is sent and the VM's existing balloon setting stays as is.

## Disk

```bash
curl -X POST http://192.168.0.11:8080/api/vm/120/set/disk \
  -H "Content-Type: application/json" -d '{"disk": "16G"}'
# ok
```

`disk` is an **increment**: the example grows `scsi0` by 16G. Proxmox cannot shrink disks; the value goes to `qm` as is, and a malformed value returns `500` with the `qm` output. Grow the partition and filesystem inside the VM yourself afterwards.

## Node Migration

```bash
curl -N -X POST http://192.168.0.11:8080/api/vm/120/set/node \
  -H "Content-Type: application/json" -d '{"node": "pve2"}'
```

`qm migrate` output streams line by line over SSE with `step` set to `migrating`, followed by `event: close`. The target node's instruction set must cover the VM's CPU type; see [CPU Baseline](/cpu-baseline).

## Error Responses

| Case | Response |
|---|---|
| Client IP not in `ALLOW_IPS` | `403` (a single `data:` line for `set/node`) |
| VM running or on the disabled list | `400` (a single `data:` line for `set/node`) |
| Field validation fails | `400 invalid request body: ...` |
| `qm` fails | `500` (a `data:` error for `set/node`) |
