---
title: WatchFor hosts API — add servers, rotate agent tokens, read metrics
description: Add servers and get their agent tokens from automation, rotate and remove them, read liveness and current CPU, memory and disk gauges, and pull metric time series — the same hosts the dashboard shows.
canonical: https://watchfor.io/docs/api/hosts
---

# WatchFor hosts API — add servers, rotate agent tokens, read metrics

Add servers and get their agent tokens from automation, rotate and remove them, read liveness and current CPU, memory and disk gauges, and pull metric time series — the same hosts the dashboard shows.

A **host** is a server running [watchfor-agent](/docs/hosts). Adding one
issues the token the agent sends with; the API does that the way **Hosts →
New host** does, so Ansible, a script or your provisioning pipeline can
enrol a whole fleet without a click. Rotating a token and removing a host
work the same way, and everything the Hosts page shows is here — liveness,
the latest gauges and the metric history.

| Method | Path | Scope | operationId |
| --- | --- | --- | --- |
| GET | `/v1/hosts` | read | `listHosts` |
| POST | `/v1/hosts` | write | `createHost` |
| GET | `/v1/hosts/{id}` | read | `getHost` |
| DELETE | `/v1/hosts/{id}` | write | `deleteHost` |
| POST | `/v1/hosts/{id}/rotate-token` | write | `rotateHostToken` |
| GET | `/v1/hosts/{id}/metrics` | read | `getHostMetrics` |

Adding, rotating and removing need a key with the `write` scope; with an
OAuth token, the user must be an owner or admin of the organization, as in
the dashboard. Each one lands in the [Activity Log](/docs/organization/activity-log)
exactly like the dashboard's ("API key: fleet added a host db-01").

The host object:

```json
{
  "id": "7c1e…",
  "object": "host",
  "name": "db-01",
  "host_id": "f0a3…",
  "description": null,
  "status": "online",
  "last_seen_at": "2026-09-22T14:02:11.000Z",
  "agent_version": "0.8.0",
  "os": "Ubuntu 24.04.3 LTS",
  "kernel": "6.8.0-79-generic",
  "arch": "arm64",
  "tags": ["role=db", "env=prod"],
  "push_interval_seconds": 15,
  "monitor_id": "0b0f6a41-…",
  "hardware": "Amazon EC2 t4g.small",
  "cpu_model": "Neoverse-N1",
  "cpu_cores": 2,
  "memory_bytes": 2013265920,
  "virtualization": "kvm",
  "addresses": {
    "primary": "172.31.4.20",
    "primary_v6": null,
    "public": ["16.171.2.40"],
    "reporting_from": "16.171.2.40"
  },
  "metrics": { "cpu_pct": 7.4, "memory_pct": 61.2, "disk_pct": 48.9, "sampled_at": "2026-09-22T14:02:11.000Z" },
  "created_at": "2026-09-14T09:30:00.000Z"
}
```

- `status` — the agent's liveness: `online` (batches arriving), `stale`
  (three push intervals missed, never sooner than 90 s), `offline` (none for
  10 minutes, or twice the stale threshold when the push interval is
  longer), `never` (the agent has not reported yet). Same thresholds as the
  dashboard.
- `monitor_id` — the host's internal monitor. Its alert rules, incidents and
  uptime hang on it, so pass this id wherever a monitor id is expected:
  [status-page components](/docs/api/status-pages), maintenance windows,
  `GET /v1/incidents?monitor_id=`, `GET /v1/monitors/{id}/uptime` and
  [`/v1/monitors/{id}/alert-rules`](/docs/api/alert-rules) (its CPU, memory,
  disk and Agent Silent rules). It is not a probe monitor: it isn't in
  `GET /v1/monitors`, and `GET /v1/monitors/{id}` and the other
  `/v1/monitors/{id}/…` routes (checks, check-now, pause, resume, reset,
  suggested thresholds) answer `404`, like an id of another organization.
- `metrics` — the latest CPU, memory and fullest-mount disk usage from the
  last five minutes, `null` when the host is silent.
- A removed host is not listed. The agent token is never part of the host
  object: it is in the response that issues it, and nowhere else.

## Add a host

`POST /v1/hosts` with a `name` — the one shown in WatchFor; the server's
hostname is a fine default — and optional `description` (notes shown under
the name, what the server runs or who owns it):

```bash
curl -X POST https://watchfor.io/api/v1/hosts \
  -H "Authorization: Bearer wf_live_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "db-01", "description": "Primary Postgres" }'
```

The answer is `201` with the host — `status` is `never` until the agent's
first batch — plus `token`:

```json
{
  "id": "7c1e…",
  "object": "host",
  "name": "db-01",
  "description": "Primary Postgres",
  "status": "never",
  "push_interval_seconds": 60,
  "monitor_id": "0b0f6a41-…",
  "metrics": null,
  "created_at": "2026-11-25T09:30:00.000Z",
  "token": "wfh_3f9c…"
}
```

- **The token is in this response only.** WatchFor keeps a hash of it, so
  nothing can show it again — keep it out of logs, and if it is lost,
  [rotate it](#rotate-a-token).
- With an [`Idempotency-Key`](/docs/api/errors#idempotency--safe-retries),
  a retry of a create that went through answers the same `201` with
  `Idempotency-Replay: true` and `token: null` — no second host, and the
  token is not kept for replays either.
- `name`: 1–253 characters, letters, digits, dot, underscore and dash,
  starting with a letter or digit; unique among the organization's hosts
  (`409` otherwise — a removed host's name is free again). `description`:
  up to 500 characters.
- The host comes with its alert rules switched on — Agent Silent, Disk
  Almost Full and Memory Pressure — routed to your Default contact group,
  like one added in the dashboard. Route a rule elsewhere with
  [`PATCH /v1/monitors/{monitor_id}/alert-rules/{ruleId}`](/docs/api/alert-rules).
- Tags are not set here: the agent reports them from its `agent.yml`
  (`host.tags`) with every batch, so `tags` in the body is a `400` that
  says so.
- Your plan decides how many hosts you can have (`max_hosts` on
  [`GET /v1/plan`](/docs/api/plan)). One over is a `403`: "Your plan
  includes 5 hosts and this organization has 5. Upgrade to add more."

## Install the agent with the token

The installer takes the token two ways. On a terminal, `--token -` asks for
it without echoing it — paste the token from the response. For automation,
put it in the `WATCHFOR_TOKEN` environment variable and add `--yes` (no
questions; it also turns on daily auto-update unless you add
`--no-auto-update`) and `--plain` for log-friendly output. Either way the
token goes to `/etc/watchfor-agent/token` (mode 0600), never on a command
line. All installer options: [Installer options](/docs/hosts#installer-options).

Keep the write API key where your automation runs, not on the servers: a
server only ever needs its own host token.

### Ansible

The API call runs on the control node, the install on the server; a host
whose agent already has a token is left alone, so the play can run again:

```yaml
- name: Enrol servers in WatchFor
  hosts: servers
  become: true
  vars:
    watchfor_api_key: "{{ lookup('ansible.builtin.env', 'WATCHFOR_API_KEY') }}"
  tasks:
    - name: Does the agent already have a token?
      ansible.builtin.stat:
        path: /etc/watchfor-agent/token
      register: watchfor_token_file

    - name: Add the host in WatchFor (the token comes back once)
      ansible.builtin.uri:
        url: https://watchfor.io/api/v1/hosts
        method: POST
        headers:
          Authorization: "Bearer {{ watchfor_api_key }}"
        body_format: json
        body:
          name: "{{ inventory_hostname_short }}"
          description: "Managed by Ansible"
        status_code: 201
      delegate_to: localhost
      become: false
      register: watchfor_host
      no_log: true
      when: not watchfor_token_file.stat.exists

    - name: Install watchfor-agent with that token
      ansible.builtin.shell: >-
        set -o pipefail &&
        curl --proto '=https' --tlsv1.2 -fsSL https://watchfor.io/agent/install.sh
        | sh -s -- --yes --plain
      args:
        executable: /bin/bash
      environment:
        WATCHFOR_TOKEN: "{{ watchfor_host.json.token }}"
      no_log: true
      when: not watchfor_token_file.stat.exists
```

`no_log` keeps the token out of Ansible's output. If a run stops between
the two tasks, the host exists in WatchFor but the server has no token:
the next run's create answers `409`. Rotate the host's token and run the
installer with the new one, or remove the host and run the play again.

### Shell

From your workstation, with the API key in `WATCHFOR_API_KEY` and `jq`
installed — the token reaches the server on standard input over SSH:

```bash
set -euo pipefail
TOKEN=$(curl -fsS -X POST https://watchfor.io/api/v1/hosts \
  -H "Authorization: Bearer $WATCHFOR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "name": "db-01" }' | jq -r .token)
test "$TOKEN" != null

printf '%s\n' "$TOKEN" | ssh root@db-01.example.com \
  'read -r WATCHFOR_TOKEN && export WATCHFOR_TOKEN &&
   curl --proto "=https" --tlsv1.2 -fsSL https://watchfor.io/agent/install.sh | sh -s -- --yes --plain'
unset TOKEN
```

## Rotate a token

`POST /v1/hosts/{id}/rotate-token`, no body. The answer is the host with a
new `token`, shown once like the first; the old token stops working within
a minute. Put the new one on the server: run the installer again with it
(it keeps `agent.yml` and restarts the agent), or replace
`/etc/watchfor-agent/token` — agent 0.9 and newer pick up the changed file
within 30 seconds. With an `Idempotency-Key`, a replay answers
`token: null`; rotate again if the first response was lost.

```bash
curl -X POST https://watchfor.io/api/v1/hosts/7c1e…/rotate-token \
  -H "Authorization: Bearer wf_live_YOUR_KEY"
```

## Remove a host

`DELETE /v1/hosts/{id}` does what **Remove** on the host page does: the
token stops working, the host's monitor goes with its alert rules, open
incidents and dead-man timer, and its metric history is deleted. A host
that has reported keeps its name in past incidents and the Activity Log.
The answer is `200` with `{ "object": "deleted", "id": "…", "deleted": true }`;
a repeat is a `404`.

```bash
curl -X DELETE https://watchfor.io/api/v1/hosts/7c1e… \
  -H "Authorization: Bearer wf_live_YOUR_KEY"
```

This does not touch the server: uninstall the agent there with
`sudo watchfor-agent uninstall` (until then it keeps sending and is
refused).

## List hosts

`GET /v1/hosts?status=offline` narrows to one liveness state. Newest first,
cursor-paginated like every list.

```bash
curl https://watchfor.io/api/v1/hosts?status=offline \
  -H "Authorization: Bearer wf_live_YOUR_KEY"
```

## Metric time series

`GET /v1/hosts/{id}/metrics?metrics=cpu.usage_pct,mem.used_pct,disk.used_pct&range=24h`

| Parameter | Required | Notes |
| --- | --- | --- |
| `metrics` | yes | Comma-separated, 1–28 names from the agent's catalogue (below). A name the agent doesn't report returns no series for it — a `200`, not an error |
| `range` | no | `1h`, `6h`, `24h` (default), `7d`, `30d` |

Points are `[unix seconds, value]`, bucketed to the range's step exactly
like the host page's charts (raw samples for short ranges, minute and hour
rollups beyond). A metric with labels — `disk.used_pct` per mount,
`net.rx_bytes_per_s` per interface — comes back as one series per label
set:

```json
{
  "object": "host_metrics",
  "host_id": "7c1e…",
  "range": "24h",
  "step_seconds": 300,
  "from": "2026-09-21T14:05:00.000Z",
  "to": "2026-09-22T14:05:00.000Z",
  "series": [
    { "metric": "cpu.usage_pct", "labels": {}, "points": [[1790000100, 6.1], [1790000400, 7.4]] },
    { "metric": "disk.used_pct", "labels": { "mount": "/" }, "points": [[1790000100, 48.9]] }
  ]
}
```

Metric names the agent reports:

| Family | Names |
| --- | --- |
| CPU and load | `cpu.usage_pct`, `cpu.user_pct`, `cpu.system_pct`, `cpu.iowait_pct`, `cpu.steal_pct`, `cpu.idle_pct`, `cpu.count`, `load.1`, `load.5`, `load.15` |
| Memory and swap | `mem.used_pct`, `mem.used_bytes`, `mem.total_bytes`, `mem.available_bytes`, `mem.free_bytes`, `mem.cached_bytes`, `mem.buffers_bytes`, `swap.used_pct`, `swap.used_bytes`, `swap.total_bytes` |
| Disk (per mount) | `disk.used_pct`, `disk.used_bytes`, `disk.free_bytes`, `disk.total_bytes`, `disk.inodes_used_pct` |
| Disk I/O (per device) | `diskio.read_bytes_per_s`, `diskio.write_bytes_per_s`, `diskio.read_ops_per_s`, `diskio.write_ops_per_s`, `diskio.util_pct`, `diskio.await_ms`, `diskio.in_progress` |
| Network (per interface) | `net.rx_bytes_per_s`, `net.tx_bytes_per_s`, `net.rx_packets_per_s`, `net.tx_packets_per_s`, `net.rx_errors_per_s`, `net.tx_errors_per_s`, `net.rx_dropped_per_s`, `net.tx_dropped_per_s` |
| Sockets | `net.tcp_in_use`, `net.tcp_time_wait`, `net.tcp_orphan`, `net.udp_in_use`, `net.sockets_used` |
| Processes | `proc.total`, `proc.running`, `proc.sleeping`, `proc.stopped`, `proc.blocked`, `proc.zombie`, and per top or watched process `proc.cpu_pct`, `proc.rss_bytes`, `proc.threads` |
| System | `sys.uptime_s`, `sys.context_switches_per_s`, `sys.forks_per_s`, `sys.procs_running`, `sys.procs_blocked` |

See [what is collected](/docs/hosts#what-is-collected).

## Still in the dashboard

Renaming a host and editing its notes after it is added — the host's
**Settings** tab. `PATCH /v1/hosts/{id}` is a `405` that says so.

## For agents

The same data is available as the MCP tools `list_hosts`, `get_host` and
`get_host_metrics`, and as the A2A skill `check-hosts`. Adding, rotating
and removing hosts are REST calls (above); there are no MCP tools for them.

---

Canonical page: https://watchfor.io/docs/api/hosts · All docs: https://watchfor.io/docs · Site guide: https://watchfor.io/llms.txt
