# API reference: machines

Machines and everything done to one, including exec, files, the terminal, endpoints and usage.

[API conventions](../api.md) explains auth, IDs, lists, errors and idempotency. The examples read the API key from `ARVM_API_KEY`.

## Operations

| Operation | Request |
|---|---|
| [Create a machine](#create-a-machine) | `POST /v1/machines` |
| [List machines](#list-machines) | `GET /v1/machines` |
| [Get a machine](#get-a-machine) | `GET /v1/machines/{machine}` |
| [Change a machine](#change-a-machine) | `PATCH /v1/machines/{machine}` |
| [Delete a machine](#delete-a-machine) | `DELETE /v1/machines/{machine}` |
| [Start a machine](#start-a-machine) | `POST /v1/machines/{machine}/start` |
| [Stop a machine](#stop-a-machine) | `POST /v1/machines/{machine}/stop` |
| [Restart a machine](#restart-a-machine) | `POST /v1/machines/{machine}/restart` |
| [List or follow a machine's events](#list-or-follow-a-machines-events) | `GET /v1/machines/{machine}/events` |
| [Get a machine's metrics](#get-a-machines-metrics) | `GET /v1/machines/{machine}/metrics` |
| [Run a command in a machine](#run-a-command-in-a-machine) | `POST /v1/machines/{machine}/exec` |
| [Read a file](#read-a-file) | `GET /v1/machines/{machine}/files` |
| [Write a file](#write-a-file) | `PUT /v1/machines/{machine}/files` |
| [Delete a file or directory](#delete-a-file-or-directory) | `DELETE /v1/machines/{machine}/files` |
| [List a directory](#list-a-directory) | `GET /v1/machines/{machine}/files/list` |
| [Open a terminal](#open-a-terminal) | `GET /v1/machines/{machine}/terminal` |
| [List a machine's endpoints](#list-a-machines-endpoints) | `GET /v1/machines/{machine}/endpoints` |
| [Expose a port](#expose-a-port) | `PUT /v1/machines/{machine}/endpoints/{port}` |
| [Stop exposing a port](#stop-exposing-a-port) | `DELETE /v1/machines/{machine}/endpoints/{port}` |
| [Get what a machine used](#get-what-a-machine-used) | `GET /v1/machines/{machine}/usage` |

## Create a machine

`POST /v1/machines`

Every field is optional: `{}` creates a machine of the default size, image and region with a
generated three-word name. The machine starts at once; pass `?wait=running` to get the
response when it is up. The machine has a host by the time the request answers, so the first
phase a response shows is `scheduled`.

Refused with `insufficient_balance` (402) when the org has no balance, `subscription_required`
(402) when its subscription ended, `limit_exceeded` (403)
at a plan limit, `name_taken` (409), and `no_capacity` (503) when no host can take it.

`no_capacity` is answered as soon as it is known, with or without `?wait=`, and comes with
`Retry-After`. Nothing was created: no machine is listed, the name is free, and nothing counts
toward a limit. A request with the same `Idempotency-Key` and body gets the same refusal until
the `Retry-After` has passed. After that the key is free, and the same request is tried again.

With `from_snapshot`, the disk starts as a copy of the snapshot. A snapshot stays on the host
that made it, so the machine is created on that host: `region` is the snapshot's, and the
request is refused with `no_capacity` when that one host has no room, and with
`snapshot_unreachable` (503) and `Retry-After` when the snapshot's data cannot be reached
right now. The snapshot must be `ready` and not deleted (`snapshot_not_ready`, 409).

With `setup_script`, the machine runs the script once, as the login user, when it first
runs: after the guest is ready for connections, so the machine is `running` before the
script has ended, and `?wait=running` does not wait for it. The response has `setup`, which
says where the script is. Pass `wait_setup=true` to hold the response until the script has
ended, or follow the machine's events for `setup.finished`. A script that fails, or runs past
its limit, does not fail the machine: the machine stays `running`, and `setup` says what
happened. The script is never run again: not after a stop and a start, a restart or a
resize. A machine created from a snapshot of this one runs a script only if its own create
gives it one.

- Operation ID: `createMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `Idempotency-Key` | header | string | no | A value the client chooses, such as a UUID. For 24 hours after a request succeeded, a request with the same key and the same body returns the first request's response instead of creating again. A request that failed leaves the key free, with one exception: a `createMachine` refused with `no_capacity` returns the same 503 until its `Retry-After` has passed, and is tried again after. The same key with a different body is `idempotency_key_reused` (409). Minimum length: `1`. Maximum length: `255`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `wait_setup` | query | boolean | no | With `true`, hold the response until the machine's setup script has ended, or until `timeout`. With `wait` as well, both must hold. On timeout the response is still successful, with `setup` as it is: a script may run for 30 minutes and `timeout` is at most 300 seconds, so a client that waits for a long script asks again. A machine that was given no script has nothing to wait for. Without `wait`, a machine that is not wanted running ends the wait: a script runs only in a machine that runs. Default: `false`. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Request body**

`application/json`: [MachineCreate](schemas.md#machinecreate)

**Responses**

| Status | Description | Body |
|---|---|---|
| 201 | The machine was created. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `402`, `403`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Idempotency-Key: $(uuidgen)" \
    -H "Content-Type: application/json" \
    -d '{"size": "default"}'
```

Another request body: every field.

```json
{
  "name": "api-staging",
  "size": "large",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "labels": {
    "env": "staging",
    "team": "web"
  },
  "env": {
    "DATABASE_URL": "postgres://db.internal/app"
  },
  "idle_timeout_seconds": null,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "from_snapshot": "snap_01jcz3k8x0e5v9w2r4t6y8a0bq"
}
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "running",
  "phase": "running",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T20:31:09Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T20:31:08Z"
}
```

## List machines

`GET /v1/machines`

Newest first. A machine is left out from the moment its deletion is asked for.

- Operation ID: `listMachines`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `label` | query | array of string | no | Keep machines that have this label, as `key=value`. Repeat it to require several. |
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of machines. | `application/json`: [MachineList](schemas.md#machinelist) |

Errors: `400`, `401`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "name": "calm-river-otter",
      "dns_label": "calm-river-otter-x7k2",
      "size": "default",
      "image": "ubuntu-24.04",
      "region": "us-east",
      "desired": "running",
      "phase": "running",
      "boot_generation": 1,
      "observed_boot_generation": 1,
      "labels": {
        "env": "staging"
      },
      "env": {},
      "idle_timeout_seconds": 3600,
      "ssh_key_ids": [
        "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
      ],
      "ssh": "ssh calm-river-otter@ssh.arvm.dev",
      "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
      "ipv6": "2001:db8:42:1::5",
      "inbound": "open",
      "last_activity_at": "2026-11-10T20:31:09Z",
      "created_at": "2026-11-10T20:31:07Z",
      "updated_at": "2026-11-10T20:31:08Z"
    }
  ],
  "next_cursor": null
}
```

## Get a machine

`GET /v1/machines/{machine}`

By ID, a deleted machine still answers, so a client can watch it reach `deleted`. By name it is 404.

- Operation ID: `getMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `wait_setup` | query | boolean | no | With `true`, hold the response until the machine's setup script has ended, or until `timeout`. With `wait` as well, both must hold. On timeout the response is still successful, with `setup` as it is: a script may run for 30 minutes and `timeout` is at most 300 seconds, so a client that waits for a long script asks again. A machine that was given no script has nothing to wait for. Without `wait`, a machine that is not wanted running ends the wait: a script runs only in a machine that runs. Default: `false`. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "running",
  "phase": "running",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T20:31:09Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T20:31:08Z"
}
```

## Change a machine

`PATCH /v1/machines/{machine}`

A field left out is not changed. `labels` replaces the whole set. `size` can change only while
the machine is stopped: its phase is `stopped`, and nothing has asked it to run since its host
reported that. Otherwise the request is refused with `machine_not_stopped` (409), which
includes a machine that was asked to start and has not started yet, and one that was started
and asked to stop again and has not stopped yet.
A size with a larger disk grows the disk on the next start and is refused with `limit_exceeded`
(403) when the org's disks would then pass the plan's `max_disk_bytes`. A size with a smaller
disk is refused with `disk_cannot_shrink` (409); moving to a size with the same disk and fewer
vCPUs or less memory is allowed. Any change of size is refused with `subscription_required`
(402) when the org's subscription ended, `machine_restoring` (409) while its disk is coming
back from the archive, `no_capacity` (503) with `Retry-After` when the machine's host or drive
lacks room for the new size, or `disk_unreachable` (503) with `Retry-After` when the machine's
drive cannot be reached right now.
`idle_timeout_seconds: null` turns idle-stop off. `inbound` can change at any time, and a
running machine is not restarted for it.

- Operation ID: `updateMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |

**Request body**

`application/json`: [MachineUpdate](schemas.md#machineupdate)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine after the change. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X PATCH "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"name": "api-staging", "labels": {"env": "staging"}}'
```

Another request body: turn idle-stop off.

```json
{
  "idle_timeout_seconds": null
}
```

Another request body: resize a stopped machine.

```json
{
  "size": "large"
}
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "running",
  "phase": "running",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T20:31:09Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T20:31:08Z"
}
```

## Delete a machine

`DELETE /v1/machines/{machine}`

Deletes the machine and its disk. This cannot be undone; snapshots of it are kept. The name is
free for a new machine at once. Deleting a machine that is already deleted is 404.

A snapshot that is still `creating` is not a copy yet. While the machine has one, the delete
is refused with `snapshot_in_progress` (409): wait until the snapshot is `ready` or `failed`,
or delete the snapshot first.

- Operation ID: `deleteMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 202 | Deletion was accepted. The machine has `desired` `deleted`. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `403`, `404`, `409`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "deleted",
  "phase": "deleting",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "inbound": "open",
  "last_activity_at": "2026-11-10T21:40:00Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T22:00:00Z"
}
```

## Start a machine

`POST /v1/machines/{machine}/start`

Sets `desired` to `running`. Starting a running machine is 200. Refused with
`insufficient_balance` (402) when the org has no balance, and `subscription_required` (402)
when its subscription ended.

A stopped machine keeps its disk on one host and starts there. That host runs only so many
machines at once, and when it is full the start is refused with `no_capacity` (503) and
`Retry-After`, as soon as that is known and whatever `?wait=` asks for. A start whose disk
cannot be reached right now is refused the same way with `disk_unreachable` (503): its data
is not known to be lost. Nothing changed:
the machine is still stopped, `desired` is still `stopped`, and nothing is billed. Room
appears when another machine on the host has stopped or is gone: a machine that was asked
to stop holds its room until its phase is `stopped`.

A machine with nothing to boot is refused with `machine_has_no_disk` (409): one whose disk
is lost (`failure.code` `disk_lost`), and one placed on a drive that failed for good before
its disk was made, which reads `stopped`, holds no data, and can only be deleted. So is a
machine that has no host, which was never given a disk. No machine this API creates is in
that state.

A machine whose disk is coming back from the archive, after its org subscribed again, is
refused with `machine_restoring` (409) until the disk is back on a host and the machine is
`stopped`.

- Operation ID: `startMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine, wanted running. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/start" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "running",
  "phase": "running",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T20:31:09Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T20:31:08Z"
}
```

## Stop a machine

`POST /v1/machines/{machine}/stop`

Sets `desired` to `stopped`. The guest is shut down and the disk is kept. Billing for compute stops at the request. Stopping a stopped machine is 200.

- Operation ID: `stopMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine, wanted stopped. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `403`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/stop" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "stopped",
  "phase": "stopping",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T21:40:00Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T21:45:30Z"
}
```

## Restart a machine

`POST /v1/machines/{machine}/restart`

Reboots the machine. The disk and the machine's addresses are kept; processes and memory are
not. Restarting a stopped machine starts it, and is refused as a start is: with
`insufficient_balance` (402) or `subscription_required` (402), with `no_capacity` (503) and `Retry-After` when the machine's
host is full, or with `disk_unreachable` (503) when its disk cannot be reached right now, in
which case the machine is still stopped and was not restarted, or with
`machine_has_no_disk` (409) for a machine with nothing to boot, or `machine_restoring` (409)
for one whose disk is coming back from the archive, as for a start.

The response comes as soon as the restart is asked for, while the machine may still report
`running` from before it. Pass `?wait=running` to hold the response until the machine is
running again after the reboot. Each call is one more reboot, so a retry after a timeout can
reboot the machine twice.

- Operation ID: `restartMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wait` | query | [MachinePhase](schemas.md#machinephase) | no | Hold the response until the machine reaches this phase, or until `timeout`. On timeout the response is still successful, with the phase the machine is in. A machine that is deleted ends the wait. A wait for `running` ends when the machine is not wanted running: its owner or the platform stopped it, and `stop` says why, which is how a failure ends it. A wait for `stopped` ends when the machine's disk is lost and nothing of it runs: it stays `failed` with `disk_lost`. `failed` ends no other wait: a machine wanted running whose phase is `failed` is starting again after a failure, and a stop or a delete goes on until it is done. |
| `timeout` | query | integer (int32) | no | The longest to hold the response for `wait` and `wait_setup`, in seconds. Default: `60`. Minimum: `1`. Maximum: `300`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine, restarting. | `application/json`: [Machine](schemas.md#machine) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/restart" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "name": "calm-river-otter",
  "dns_label": "calm-river-otter-x7k2",
  "size": "default",
  "image": "ubuntu-24.04",
  "region": "us-east",
  "desired": "running",
  "phase": "running",
  "boot_generation": 1,
  "observed_boot_generation": 1,
  "labels": {
    "env": "staging"
  },
  "env": {},
  "idle_timeout_seconds": 3600,
  "ssh_key_ids": [
    "sshkey_01jcz3k8x0e5v9w2r4t6y8a0bq"
  ],
  "ssh": "ssh calm-river-otter@ssh.arvm.dev",
  "ssh_host_key": "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIAfP9T3r3Cm+LUkbF/xP8j0LHHso46lqge/yM3xaeRJ0",
  "ipv6": "2001:db8:42:1::5",
  "inbound": "open",
  "last_activity_at": "2026-11-10T20:31:09Z",
  "created_at": "2026-11-10T20:31:07Z",
  "updated_at": "2026-11-10T20:31:08Z"
}
```

## List or follow a machine's events

`GET /v1/machines/{machine}/events`

The machine's activity feed, oldest first: each request that changed it, each phase it reached
and each step a host took, with how long the step took. `MachineEventAttributes` lists the
event types and the attributes of each.

With `follow=true` the response is a server-sent event stream that stays open. Each message has
`event: machine_event`, the event's ID as `id:`, and a `MachineEvent` as JSON in `data:`. Send
`Last-Event-ID` to continue after an event already seen. A comment line (`: keepalive`) is sent
every 15 seconds.

- Operation ID: `listMachineEvents`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `follow` | query | boolean | no | Keep the response open and stream new events. Default: `false`. |
| `Last-Event-ID` | header | [EventID](schemas.md#eventid) | no | With `follow=true`, the ID of the last event received. The stream continues after it. |
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of events, or with `follow=true` a stream of them. | `application/json`: [MachineEventList](schemas.md#machineeventlist), `text/event-stream`: string |

Errors: `400`, `401`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/events" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "id": "evt_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "type": "disk.cloned",
      "at": "2026-11-10T20:31:07.412Z",
      "duration_ms": 12,
      "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
      "attributes": {
        "image": "ubuntu-24.04@2026-11-10"
      }
    },
    {
      "id": "evt_01jcz3k8x1a2b3c4d5e6f7g8h9",
      "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "type": "guest.ready",
      "at": "2026-11-10T20:31:08.630Z",
      "duration_ms": 1090,
      "trace_id": "4bf92f3577b34da6a3ce929d0e0e4736",
      "attributes": {}
    }
  ],
  "next_cursor": null
}
```

Response body, `text/event-stream`:

```text
event: machine_event
id: evt_01jcz3k8x0e5v9w2r4t6y8a0bq
data: {"id":"evt_01jcz3k8x0e5v9w2r4t6y8a0bq","machine_id":"m_01jcz3k8x0e5v9w2r4t6y8a0bq","type":"disk.cloned","at":"2026-11-10T20:31:07.412Z","duration_ms":12,"attributes":{}}

: keepalive
```

## Get a machine's metrics

`GET /v1/machines/{machine}/metrics`

CPU, memory, disk and network over a time range, as evenly spaced points. One sample is kept
per minute, for 30 days, so a step under 60 gives no more points. A point covers `step_seconds` from its `at`: CPU is the average of its
samples, memory and disk are the highest, and network is the average rate. A point with no
sample, for example while the machine was stopped, is left out.

- Operation ID: `getMachineMetrics`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `starts_at` | query | string (date-time) | no | The start of the time range, inclusive. |
| `ends_at` | query | string (date-time) | no | The end of the time range, exclusive. |
| `step_seconds` | query | integer (int32) | no | The spacing of the points. The default gives about 120 points for the range. Minimum: `15`. Maximum: `86400`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The series. | `application/json`: [MachineMetrics](schemas.md#machinemetrics) |

Errors: `400`, `401`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/metrics" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "starts_at": "2026-11-10T20:00:00Z",
  "ends_at": "2026-11-10T20:02:00Z",
  "step_seconds": 60,
  "points": [
    {
      "at": "2026-11-10T20:00:00Z",
      "cpu_utilization": 0.12,
      "memory_used_bytes": 1503238553,
      "disk_used_bytes": 6442450944,
      "network_rx_bytes_per_second": 18230,
      "network_tx_bytes_per_second": 4096
    },
    {
      "at": "2026-11-10T20:01:00Z",
      "cpu_utilization": 0.87,
      "memory_used_bytes": 2147483648,
      "disk_used_bytes": 6444450944,
      "network_rx_bytes_per_second": 912004,
      "network_tx_bytes_per_second": 20480
    }
  ]
}
```

## Run a command in a machine

`POST /v1/machines/{machine}/exec`

Runs `command` in the guest through the guest agent, with no SSH involved, as the user `dev`
unless `user` says otherwise. `command` is an argument vector: for a shell line send
`["sh", "-c", "..."]`.

Without `stream`, the response comes when the command exits, with its output and exit code.
Output is text: bytes that are not UTF-8 are replaced, and each of `stdout` and `stderr` is cut
at 8 MiB (`truncated` says so). Read binary output with the files operations instead.

With `"stream": true` the response is a server-sent event stream: `event: stdout` and
`event: stderr` messages carry an `ExecOutput`, and one final message says how the command
ended: `event: exit` with an `ExecExit`, or `event: outcome_unknown` with a `Problem`. A
comment line (`: keepalive`) is sent every 15 seconds, so a command that prints nothing for
a long time keeps its stream open. A stream cannot be resumed: if the client's connection
drops, the command is killed.

Each answer says one of four things:

- **The command did not start.** A problem, never a 200, and nothing ran: it is safe to
  send again. `machine_not_running` (409) when the machine is not running,
  `invalid_request` (400) when the machine refused it, such as for a `user` that does not
  exist, and `machine_unreachable` (503, with `Retry-After`) when the request could not
  be sent to the machine's host at all. A streamed exec answers 200 only once the command
  has started.
- **It exited.** `exit_code` is its exit status. A program that is not found or not
  executable exits 127 or 126 with the reason on stderr, as a shell would.
- **It was killed at its timeout.** After `timeout_seconds` the command is sent SIGKILL,
  and `timed_out` is `true` when the exit that follows is that kill's: `exit_code` is 137.
- **Whether it ran is unknown** (`exec_outcome_unknown`, 502, or the stream's
  `outcome_unknown`). The request reached the host's connection, and then no sign that the
  command started came back within 10 seconds (or within `timeout_seconds`, if that is
  shorter), or the connection to it was lost before its exit. It may not have started, may
  have run to its end, or may still be running. There is no exit code. Check what the
  command changes before running it again. With no sign of a start, the API drops the
  call, which kills a command that did reach the machine unless the network to its host is
  cut; a stream answers this before any 200.

- Operation ID: `execMachine`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |

**Request body**

`application/json`: [ExecRequest](schemas.md#execrequest)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The command's result, or with `stream` its output as it is produced. | `application/json`: [ExecResult](schemas.md#execresult), `text/event-stream`: string |
| 502 | Whether the command ran is unknown (`exec_outcome_unknown`): the request reached the host's connection, and then no sign of a start came back, or the connection was lost before the command's exit. Unlike other 5xx answers, this one is not safe to retry as it is: check what the command changes first. Only the API's own problem documents say what happened to the command. An answer the API did not write (a 502 or 504 from a proxy or the gateway, whose body is not `application/problem+json`), and a connection that ends with no answer, say nothing about it: treat them as `exec_outcome_unknown`. | `application/problem+json`: [Problem](schemas.md#problem) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X POST "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/exec" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"command": ["uname", "-r"]}'
```

Another request body: a shell line, streamed.

```json
{
  "command": [
    "sh",
    "-c",
    "cd /srv/app && make test"
  ],
  "env": {
    "CI": "true"
  },
  "timeout_seconds": 600,
  "stream": true
}
```

Response body, `application/json`:

```json
{
  "exit_code": 0,
  "stdout": "6.8.0-48-generic\n",
  "stderr": "",
  "truncated": false,
  "timed_out": false,
  "oom_killed": false,
  "duration_ms": 41
}
```

Response body, `text/event-stream`:

```text
event: stdout
data: {"data":"go test ./...\n"}

: keepalive

event: stderr
data: {"data":"warning: no test files\n"}

event: exit
data: {"exit_code":0,"timed_out":false,"oom_killed":false,"duration_ms":5210}
```

## Read a file

`GET /v1/machines/{machine}/files`

The file's bytes. A path that does not exist is `file_not_found` (404); a directory is `not_a_file` (409).

- Operation ID: `readMachineFile`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `path` | query | string | yes | An absolute path in the machine. Maximum length: `4096`. Matches `^/`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The file's content. | `application/octet-stream`: string (binary) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/files?path=/home/dev/app/.env" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/octet-stream`:

```text
PORT=8080
```

## Write a file

`PUT /v1/machines/{machine}/files`

Creates the file or replaces its content with the request body. The file is owned by the user `dev`.
The request needs a `Content-Length`: the file takes the new content only once that many bytes have
arrived, and an upload that ends short leaves the file as it was.

- Operation ID: `writeMachineFile`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `path` | query | string | yes | An absolute path in the machine. Maximum length: `4096`. Matches `^/`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |
| `mode` | query | string | no | Permission bits in octal, applied when the file is created. Default: `0644`. Matches `^[0-7]{3,4}$`. |
| `make_parents` | query | boolean | no | Create missing parent directories. Default: `false`. |

**Request body**

`application/octet-stream`: string (binary)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The file as written. | `application/json`: [FileInfo](schemas.md#fileinfo) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `411`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X PUT "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/files?path=/home/dev/app/.env" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/octet-stream" \
    --data-binary @./local-file
```

Response body, `application/json`:

```json
{
  "path": "/home/dev/app/.env",
  "name": ".env",
  "type": "file",
  "size_bytes": 10,
  "mode": "0600",
  "modified_at": "2026-11-10T20:40:12Z"
}
```

## Delete a file or directory

`DELETE /v1/machines/{machine}/files`

A directory that is not empty needs `recursive=true`.

- Operation ID: `deleteMachineFile`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `path` | query | string | yes | An absolute path in the machine. Maximum length: `4096`. Matches `^/`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |
| `recursive` | query | boolean | no | Delete a directory with everything in it. Default: `false`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 204 | Deleted. |  |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/files?path=/home/dev/app/.env" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

## List a directory

`GET /v1/machines/{machine}/files/list`

The entries of one directory, by name. Not recursive.

- Operation ID: `listMachineFiles`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `path` | query | string | yes | An absolute path in the machine. Maximum length: `4096`. Matches `^/`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | A page of entries. | `application/json`: [FileList](schemas.md#filelist) |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/files/list?path=/home/dev/app/.env" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "path": "/home/dev/app/.env",
      "name": ".env",
      "type": "file",
      "size_bytes": 10,
      "mode": "0600",
      "modified_at": "2026-11-10T20:40:12Z"
    },
    {
      "path": "/home/dev/app/src",
      "name": "src",
      "type": "directory",
      "size_bytes": 4096,
      "mode": "0755",
      "modified_at": "2026-11-10T20:12:55Z"
    }
  ],
  "next_cursor": null
}
```

## Open a terminal

`GET /v1/machines/{machine}/terminal`

A WebSocket upgrade (`Connection: Upgrade`, `Upgrade: websocket`) to an interactive shell in the
machine, as the user `dev`. Offer the subprotocol `acre.terminal.v1`.

OpenAPI cannot describe WebSocket messages, so they are described here:

- **Binary frames** carry terminal bytes: client to server is what the user typed, server to
  client is what the shell printed.
- **Text frames** carry one JSON control message. Client to server: a `TerminalResize`,
  `{"type": "resize", "cols": 120, "rows": 40}`. Server to client: a `TerminalExit`,
  `{"type": "exit", "exit_code": 0}`, sent once before the server closes with status 1000.
- The server sends a ping every 30 seconds and closes a connection that does not answer.
- A close with status 4409 means the machine stopped running.
- A close with status 1001 means the server is stopping, as it does in a deploy. Open the terminal
  again: it is a new shell.

A browser authenticates with the session cookie; the server checks `Origin`. A program sends
`Authorization` on the upgrade request. The machine must be running.

- Operation ID: `openMachineTerminal`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `wake` | query | boolean | no | When `true`, if the machine is not running, start it idempotently and wait up to 60 seconds (bounded by the request timeout) for it to reach `running` before forwarding the request. Start refusals (`402`, `403`, `409`, `503` with `Retry-After`) are returned unchanged. Default: `false`. |
| `cols` | query | integer (int32) | no | Terminal width at start. Default: `80`. Minimum: `1`. Maximum: `1000`. |
| `rows` | query | integer (int32) | no | Terminal height at start. Default: `24`. Minimum: `1`. Maximum: `1000`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 101 | Switching to the WebSocket protocol. |  |

Errors: `400`, `401`, `402`, `403`, `404`, `409`, `429`, `503`. [Error responses](index.md#error-responses) says what each status means.

## List a machine's endpoints

`GET /v1/machines/{machine}/endpoints`

- Operation ID: `listMachineEndpoints`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `limit` | query | integer (int32) | no | The most items to return. Default: `50`. Minimum: `1`. Maximum: `200`. |
| `cursor` | query | string | no | The `next_cursor` of the previous page. Opaque. Maximum length: `512`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The ports of the machine that have an HTTPS URL. | `application/json`: [EndpointList](schemas.md#endpointlist) |

Errors: `400`, `401`, `403`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/endpoints" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "data": [
    {
      "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
      "port": 8080,
      "visibility": "private",
      "url": "https://8080-calm-river-otter-x7k2.apps.arvm.dev",
      "signed_url": "https://8080-calm-river-otter-x7k2.apps.arvm.dev/?_acre_token=eyJwIjo4MDgwfQ.c2lnbmF0dXJl",
      "created_at": "2026-11-10T20:45:00Z"
    }
  ],
  "next_cursor": null
}
```

## Expose a port

`PUT /v1/machines/{machine}/endpoints/{port}`

Gives the port an HTTPS URL, `https://<port>-<dns_label>.<apps domain>`, or changes who can
open it. A `private` endpoint answers only a request that carries the token in `signed_url`
(after the first such request, a cookie); a `public` one answers anyone. Putting the same
endpoint again is 200 and changes nothing.

- Operation ID: `putMachineEndpoint`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `port` | path | integer (int32) | yes | A TCP port in the machine. Minimum: `1`. Maximum: `65535`. |

**Request body**

`application/json`: [EndpointPut](schemas.md#endpointput)

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The endpoint. | `application/json`: [Endpoint](schemas.md#endpoint) |

Errors: `400`, `401`, `403`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X PUT "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/endpoints/8080" \
    -H "Authorization: Bearer $ARVM_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{"visibility": "private"}'
```

Response body, `application/json`:

```json
{
  "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "port": 8080,
  "visibility": "private",
  "url": "https://8080-calm-river-otter-x7k2.apps.arvm.dev",
  "signed_url": "https://8080-calm-river-otter-x7k2.apps.arvm.dev/?_acre_token=eyJwIjo4MDgwfQ.c2lnbmF0dXJl",
  "created_at": "2026-11-10T20:45:00Z"
}
```

## Stop exposing a port

`DELETE /v1/machines/{machine}/endpoints/{port}`

The URL stops answering at once. Removing an endpoint that does not exist is 404.

- Operation ID: `deleteMachineEndpoint`
- Auth: an API key, or the web app's session cookie
- API key scope: a full key. A read-only key is answered 403 `read_only_key`.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `port` | path | integer (int32) | yes | A TCP port in the machine. Minimum: `1`. Maximum: `65535`. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 204 | Removed. |  |

Errors: `400`, `401`, `403`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s -X DELETE "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/endpoints/8080" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

## Get what a machine used

`GET /v1/machines/{machine}/usage`

The machine's running time and its cost over a time range. The default range is the current calendar month, in UTC.

- Operation ID: `getMachineUsage`
- Auth: an API key, or the web app's session cookie
- API key scope: any. A read-only key may call this.

**Parameters**

| Name | In | Type | Required | Description |
|---|---|---|---|---|
| `machine` | path | string | yes | The machine's ID or its name. Minimum length: `1`. Maximum length: `63`. |
| `starts_at` | query | string (date-time) | no | The start of the time range, inclusive. |
| `ends_at` | query | string (date-time) | no | The end of the time range, exclusive. |

**Responses**

| Status | Description | Body |
|---|---|---|
| 200 | The machine's usage. | `application/json`: [MachineUsage](schemas.md#machineusage) |

Errors: `400`, `401`, `404`, `429`. [Error responses](index.md#error-responses) says what each status means.

**Example**

```console
$ curl -s "https://api.arvm.dev/v1/machines/m_01jcz3k8x0e5v9w2r4t6y8a0bq/usage" \
    -H "Authorization: Bearer $ARVM_API_KEY"
```

Response body, `application/json`:

```json
{
  "machine_id": "m_01jcz3k8x0e5v9w2r4t6y8a0bq",
  "starts_at": "2026-11-01T00:00:00Z",
  "ends_at": "2026-12-01T00:00:00Z",
  "seconds": 86400,
  "amount_micros": 480000
}
```
