# What scheduling maintenance would do

> GET /v1/maintenance-windows/preview. .

Source: https://legion.ambient.xyz/docs/api/hosts/preview-maintenance

`GET https://api.legion.ambient.xyz/v1/maintenance-windows/preview`

Authenticate with an API key: `Authorization: Bearer $LEGION_API_KEY`.

. For each host (up to 100), the rentals the window would stop (the same set the closing step stops), how many
renter organizations would be emailed, the notice the rentals need, whether the window would be penalty-free
and the earliest start that would be. `may_restart` counts stopped rentals with files that could still start before
the window closes; they are not in `rentals`. A host `scheduleMaintenance` would skip carries `skip` with the same
code (`maintenance_exists`, `maintenance_quota`, `host_removing`, `host_removed`) and is never `penalty_free`. Changes nothing and sends nothing. A host that does not exist or is not the organization's is 404 for the whole
request. Needs the `hosts.manage` permission.

## Query parameters

- `host_id`, array of string (uuid), required: The hosts (`?host_id=A&host_id=B`), 1 to 100.
- `start`, string (date-time), required: The start, RFC 3339 on a whole minute, 5 minutes to 90 days from now (as `scheduleMaintenance`).
- `duration_minutes`, integer, required: The planned length in minutes, 15 to 4320 (72 hours).
- `window_id`, string (uuid): The preview of moving this window (the reschedule dialog) to `start` for `duration_minutes`, instead of scheduling a new one. `host_id` names its host only. The window is the one moved: no `maintenance_exists` skip for it and no quota count of it; its notice counts as `rescheduleMaintenance` counts it (an earlier or longer window restarts it from now); `skip` uses `rescheduleMaintenance`'s codes; `penalty_free_before` and `reschedules_left` are set. Unknown or another organization's window: 404.

## Responses

### 200

The preview.

- `items`, array of MaintenancePreviewItem, required
  - `host_id`, string (uuid), required: The host.
  - `host_name`, string, required: The host's name (or hostname).
  - `rentals`, MaintenanceTierCounts, required: The rentals a window would stop now, by tier (the closing step's set).
  - `may_restart`, integer, required: Stopped rentals their renters could still start before closing; if one does, it counts at closing (see `MaintenanceWindow.may_restart`).
  - `required_notice_seconds`, integer, required: The notice those rentals are owed: 72 hours with an on-demand one, 1 hour with only interruptible ones, 0 for none.
  - `notice_seconds`, integer, required: The notice the start gives from now.
  - `penalty_free`, boolean, required: Whether a window at this start would be penalty-free for the rentals now on the host; false for a skipped host.
  - `earliest_penalty_free_start`, string (date-time): The earliest start that would be penalty-free; absent for a skipped host.
  - `renters_notified`, integer, required: The renter organizations that would be told.
  - `skip`, MaintenanceSkip: Present when `scheduleMaintenance` would skip the host, with the same code (with `window_id`: when `rescheduleMaintenance` would skip the window).
  - `penalty_free_before`, boolean: With `window_id` only: whether the window is penalty-free now. With `penalty_free` (after the move) it says whether the move keeps or loses it.
  - `reschedules_left`, integer: With `window_id` only: how many changes of the window's times are left after this move (a move that changes nothing uses none).

Example:

```json
{
  "items": [
    {
      "host_id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
      "host_name": "string",
      "rentals": {
        "on_demand": 0,
        "interruptible": 0
      },
      "may_restart": 0,
      "required_notice_seconds": 0,
      "notice_seconds": 0,
      "penalty_free": false,
      "earliest_penalty_free_start": "2026-10-15T12:00:00Z",
      "renters_notified": 0,
      "skip": {
        "id": "0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b",
        "code": "host_removed",
        "detail": "string"
      },
      "penalty_free_before": false,
      "reschedules_left": 0
    }
  ]
}
```

### 400

The request is malformed or fails validation. An image reference that
is not a container image reference answers `invalid_image_reference`.

### 401

Missing, unknown, expired or revoked credentials.

### 403

The caller lacks the permission this operation requires (`forbidden`),
or signed in without having joined an organization yet
(`no_organization`; `getOnboarding` and the invitation and
organization operations under it work), or could not sign in
(`email_unverified`, `account_conflict`, and `domain_not_allowed`). `not_invited` is no longer returned to
session tokens.

`access_not_approved`: a signed-in person who is not approved
for the beta yet. Every operation that takes a credential answers it to
them, except `getMe` and `joinMyWaitlist`; the problem carries
`access` (`waitlisted` or `not_requested`, and the email). Approved
means a member of an organization, holding a pending invitation, or Legion; an API key always belongs to a member.

`oauth_token_mcp_only`: the caller sent an OAuth access token (`lgo_`), which is accepted
only by `mcpMessage` and the tool calls it dispatches. Every other operation answers it, whatever
the token's scope. Use an API key or the Legion web app.

`org_suspended`: the caller's organization is suspended. Every operation that takes a
credential answers it, by session or API key, except `getMe` (which shows `org.suspended_at` and
`org.suspension_reason`) and the support operations under `/v1/support/`.

`terms_not_accepted`: an approved caller who has not accepted
the current version of the Terms of Use and the Acceptable Use Policy. Every operation that takes a credential answers it, except `getMe`,
`acceptLegalDocuments`, `joinMyWaitlist` and the wind-down operations
(`listRentals`, `stopRental`, `deleteRental`, `listHosts`,
`updateListing` with `listed` false, `removeHost`); the problem
carries `legal`. An API key acts for the person who created it, so it
is refused until that person accepts. Terminal
operations also return
`session_required` (called with an API key) and `step_up_required`
(neither a sign-in nor a step-up challenge within the step-up window).

### 404

The resource does not exist or belongs to another organization.

### 500

An unexpected server error. Safe to retry.

## Errors

- 400 [`invalid_maintenance_window`](https://legion.ambient.xyz/docs/errors#invalid_maintenance_window)
- 403 [`no_organization`](https://legion.ambient.xyz/docs/errors#no_organization)

## Example request

```sh
curl -s "https://api.legion.ambient.xyz/v1/maintenance-windows/preview?host_id=0192f1a2-7c3d-7e4f-8a9b-0c1d2e3f4a5b&start=2026-10-15T12%3A00%3A00Z&duration_minutes=15" \
  -H "Authorization: Bearer $LEGION_API_KEY"
```
