# Cloud machines

> Cloud machines: a Linux machine at a cloud provider (boat.dev in v1) for each person, on Nexus's own provider account. Nobody opens a provider account or sees Nexus's key. Gateway charges a machine's running time to the organization as cloud compute (product `cloud`, capability `compute` in GET /v1/spend), at the provider's price per second, when it sleeps or is deleted and every 15 minutes while it runs. A machine is its person's alone: to anyone else it does not exist. One live machine per person in an organization. Without a provider account on the Gateway (`BOAT_API_KEY`), every route answers 503 `cloud_unavailable`.

## List cloud machines

`GET /v1/cloud/machines`

Your live cloud machines in this organization, one for each desktop session at most, each state read from the provider.

Permission: `cloud.machines.use` (Every member).

### Responses

- `200` OK (application/json, CloudMachineList)
  - `machines` (array of CloudMachine, required)
    - `id` (string, required): `cm_` and up to 64 base64url characters
    - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
    - `title` (string | null, required): The session's title, on one line; null when the create sent none.
    - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
    - `provider` ("boat", required)
    - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
    - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
    - `error` (string | null, required): Why it failed; null otherwise.
    - `createdAt` (string (date-time), required)
    - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
    - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
    - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
    - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines)

## Create cloud machine

`POST /v1/cloud/machines`

Create the cloud machine of a desktop session. Send `sessionId` and the session's `title`: a create for a session that has a live machine returns that machine. Nexus names and sizes every machine (`NEXUS_CLOUD_DEFAULT_SIZE`), so `name` and `size` are read and ignored. The machine starts from Nexus's image, with its own Nexus token in `~/.nexus/host/credentials`; deleting the machine revokes that token. Send an `Idempotency-Key`: the machine's id is derived from it, so a resend names the machine the first send made, and finishes it when the provider's answer was lost. A machine that cannot start now waits in the queue (202, state `queued`): Gateway runs its most machines, the person runs their share (`NEXUS_CLOUD_MAX_PER_PERSON`), the person started 20 machines and gets one more every 5 minutes, or the provider is at its limits. The meter starts the queue oldest first. A person asks for at most 200 starts (creates and wakes) in a UTC day, and an organization's people 500 together: one more answers 429 `cloud_daily_starts` until 00:00 UTC (`Retry-After`). An organization with only the free start is on the trial: it runs one machine at a time, and all trial organizations together a few. A trial machine never waits in the queue: one more answers 429 `cloud_trial_limit` or `cloud_trial_busy` (`Retry-After`), which name Billing. Credits, a card or a contract lift the trial. A person keeps at most 50 machines, asleep or not: one more answers 429 `cloud_machine_limit`. Read the queued machine (GET) while you wait: one nobody read for 10 minutes ends, `failed`. Its running time is charged as cloud compute from its start.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `x-nexus-github-token` | header | string | no | The person's own GitHub token. With `repo`, Gateway asks GitHub with it whether the person may read the repository, and only then starts the machine from the organization's saved copy of it. Used for that check only, never kept. |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `sessionId` (string): The desktop session the machine is for (`t_<uuid>`). One live machine for each session. An older app sends none, and gets a new machine each time. [pattern ^[A-Za-z0-9_-]{1,128}$]
- `title` (string): The session's title. Gateway keeps its first line, cut to 200 characters.
- `name` (string): Read and ignored: the machine's name is the session's title.
- `size` (string): Read and ignored: Nexus sizes every machine.
- `repo` (string): The repository the session clones: a URL, or a GitHub `owner/name`. With `NEXUS_CLOUD_WARM_SNAPSHOTS` on, a GitHub one starts the machine from the organization's saved copy of it, when there is one and GitHub lets the person read it (`x-nexus-github-token`). Anything else is ignored. [max length 512]

### Responses

- `200` The machine a send with this key made, or the live machine of this session (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `201` Created: the machine is starting (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `202` Accepted: the machine waits in the queue (`queued`, with `queuedUntil`) (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `400` The body is not an object, or `sessionId` is not 1 to 128 letters, digits, `_` and `-` (`invalid_session_id`).
- `402` Nothing covers 15 minutes of this machine's cloud compute (`budget_exceeded`), so no new compute starts. Nexus pays for cloud compute: it is held on the organization's Nexus balance (its subsidy, then its credits, then its contract), and on its budget. An organization past due gets `payment_past_due`. The refusal is recorded. When a running machine's next 15 minutes are refused, Gateway puts it to sleep, with `stopReason` `budget`.
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`). Only the organizations Nexus lists may start or use a machine; anyone may still list, sleep and delete their own.
- `409` The create took so long that Gateway ended it (`machine_gone`); send a new one.
- `422` This `Idempotency-Key` names another machine (`idempotency_key_reused`); send a new key.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 202 | `queued` | A machine that cannot start now waits in the queue (202, state `queued`): Gateway runs its most machines, the person runs their share (`NEXUS_CLOUD_MAX_PER_PERSON`), the person started 20 machines and gets one more every 5 minutes, or the provider is at its limits |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not an object, or `sessionId` is not 1 to 128 letters, digits, `_` and `-` (`invalid_session_id`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | Nothing covers 15 minutes of this machine's cloud compute (`budget_exceeded`), so no new compute starts. Nexus pays for cloud compute: it is held on the organization's Nexus balance (its subsidy, then its credits, then its contract), and on its budget. An organization past due gets `payment_past_due`. The refusal is recorded. When a running machine's next 15 minutes are refused, Gateway puts it to sleep, with `stopReason` `budget`. |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | The create took so long that Gateway ended it (`machine_gone`); send a new one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 |  | This `Idempotency-Key` names another machine (`idempotency_key_reused`); send a new key. |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `cloud_daily_starts` | One more answers 429 `cloud_daily_starts` until 00:00 UTC (`Retry-After`) |
| 429 | `cloud_trial_limit` | One more answers 429 `cloud_trial_limit` or `cloud_trial_busy` (`Retry-After`), which name Billing |
| 429 | `cloud_machine_limit` | One more answers 429 `cloud_machine_limit` |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "sessionId": "<sessionId>",
    "title": "<title>",
    "name": "Platform",
    "size": "<size>",
    "repo": "<repo>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines)

## Pair cloud server

`POST /v1/cloud/machines/pair`

Pair your own server, so Nexus Desktop reaches it through Gateway with no SSH and no open port. `nexus-host login` calls this with the token its device sign-in got, and that token becomes the machine's own: only it opens the machine's host connection, and deleting the machine revokes it. It reads `ready`, with provider `own`; `hostOnline` says whether it answers. Nexus never starts, stops, sizes or charges it, and any organization may pair one. A second pairing with the same token answers the same machine. A person pairs at most 10 servers (409 `own_servers_full`).

Permission: `cloud.machines.use` (Every member).

### Request body (application/json, required)

- `name` (string, required): The server's name for your list. Gateway keeps its first line, cut to 120 characters.

### Responses

- `200` OK (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `400` The name is empty (`invalid_name`), or the token may not pair a server (`not_a_host_token`) (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `409` You have 10 servers paired already (`own_servers_full`)
- `503` No provider account on this Gateway (`cloud_unavailable`), or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The name is empty (`invalid_name`), or the token may not pair a server (`not_a_host_token`) |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 409 |  | You have 10 servers paired already (`own_servers_full`) |
| 409 | `own_servers_full` | A person pairs at most 10 servers (409 `own_servers_full`) |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/pair" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Platform"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2Fpair)

## Get cloud machine

`GET /v1/cloud/machines/{id}`

One of your machines, its state read from the provider. A machine the provider no longer has is `gone`.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |

### Responses

- `200` OK (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D)

## Delete cloud machine

`DELETE /v1/cloud/machines/{id}`

Delete your machine at the provider, disk and all, and charge its running time. You may then create another.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, CloudMachineDeleted)
  - `id` (string, required)
  - `deleted` (boolean, required)
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/cloud/machines/<id>" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D)

## Wake cloud machine

`POST /v1/cloud/machines/{id}/wake`

Wake your machine from its saved disk. Its address and host key change: ask for access again. Its running time is charged from now. When Gateway runs its most machines, the person woke 20 machines and gets one more wake a minute, or the provider is at its limits, the wake waits in the queue (202, state `queued`); the meter starts it in turn. A wake counts toward the day's starts: past them it answers 429 `cloud_daily_starts`. An organization with only the free start is on the trial: it runs one machine at a time, and all trial organizations together a few. A trial machine never waits in the queue: one more answers 429 `cloud_trial_limit` or `cloud_trial_busy` (`Retry-After`), which name Billing. Credits, a card or a contract lift the trial. A trial machine sleeps 2 hours after its wake (`max_run`). A run that stops in its first minute is charged a minute.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `202` Accepted: the wake waits in the queue (`queued`, with `queuedUntil`) (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `402` Nothing covers 15 minutes of this machine's cloud compute (`budget_exceeded`), so no new compute starts. Nexus pays for cloud compute: it is held on the organization's Nexus balance (its subsidy, then its credits, then its contract), and on its budget. An organization past due gets `payment_past_due`. The refusal is recorded. When a running machine's next 15 minutes are refused, Gateway puts it to sleep, with `stopReason` `budget`.
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`). Only the organizations Nexus lists may start or use a machine; anyone may still list, sleep and delete their own.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The machine slept 14 days and the provider deleted its disk (`snapshot_data_expired`): it is now `gone`.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 202 | `queued` | When Gateway runs its most machines, the person woke 20 machines and gets one more wake a minute, or the provider is at its limits, the wake waits in the queue (202, state `queued`); the meter starts it in turn |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 402 | `budget_exceeded` | Nothing covers 15 minutes of this machine's cloud compute (`budget_exceeded`), so no new compute starts. Nexus pays for cloud compute: it is held on the organization's Nexus balance (its subsidy, then its credits, then its contract), and on its budget. An organization past due gets `payment_past_due`. The refusal is recorded. When a running machine's next 15 minutes are refused, Gateway puts it to sleep, with `stopReason` `budget`. |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The machine slept 14 days and the provider deleted its disk (`snapshot_data_expired`): it is now `gone`. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `cloud_daily_starts` | Past them it answers 429 `cloud_daily_starts` |
| 429 | `cloud_trial_limit` | One more answers 429 `cloud_trial_limit` or `cloud_trial_busy` (`Retry-After`), which name Billing |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/wake" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fwake)

## Sleep cloud machine

`POST /v1/cloud/machines/{id}/sleep`

Put your machine to sleep: the provider saves its disk and frees the machine. Its running time is charged up to now. A queued wake leaves the queue, and the machine stays asleep.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/sleep" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fsleep)

## Report cloud machine activity

`POST /v1/cloud/machines/{id}/activity`

A cloud machine's heartbeat, sent by its host (`nexus-host`) every minute with the machine's own Nexus token (the one in `~/.nexus/host/credentials`): whether its agent works, since when it is idle, the person's last interaction and the kernel's out-of-memory kill count. Gateway stores the last report. A time after now is taken as now. The report never extends the machine's longest run (`NEXUS_CLOUD_MAX_RUN_HOURS`, from the person's last create, wake or access). Gateway puts the machine to sleep (`idle`) when its agent was idle 5 minutes and its person did not interact for 20 minutes, and never while its agent works. A machine whose host sends no report for 15 minutes (or never sent one) sleeps 20 minutes after its last interaction, create, wake or access. A rise in the out-of-memory count restarts the machine one size bigger, up to `large` (`resize`).

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |

### Request body (application/json, required)

- `busy` (boolean, required): Whether an agent on the machine works now. A permission prompt counts as idle.
- `agentIdleSince` (string (date-time) | null): Since when every agent is idle; null while one works or before the first.
- `interactedAt` (string (date-time) | null): The person's last interaction with the machine's sessions; null when there is none.
- `oomKills` (integer): How many processes the kernel killed for want of memory since the machine started (its cgroup's `oom_kill`, else the system's). [min 0]

### Responses

- `200` OK (application/json, CloudMachine)
  - `id` (string, required): `cm_` and up to 64 base64url characters
  - `sessionId` (string | null, required): The desktop session the machine is for; null on a machine made before sessions.
  - `title` (string | null, required): The session's title, on one line; null when the create sent none.
  - `name` (string, required): The session's title, cut to 120 characters, or `Cloud`.
  - `provider` ("boat", required)
  - `size` ("small" | "default" | "large" | "xlarge", required): Nexus chooses it: `NEXUS_CLOUD_DEFAULT_SIZE` when made.
  - `state` ("queued" | "creating" | "starting" | "ready" | "sleeping" | "stopping" | "failed" | "gone", required): The desktop's `CloudState`. `queued` waits for a place, the person's next start or the provider; nothing runs. Running time is charged in `creating`, `starting` and `ready`.
  - `error` (string | null, required): Why it failed; null otherwise.
  - `createdAt` (string (date-time), required)
  - `sleepingSince` (string (date-time) | null, required): When it went to sleep; null unless `sleeping`.
  - `stopReason` ("budget" | "max_run" | "not_enabled" | "idle" | "resize" | null, required): Why Gateway put it to sleep: `budget` when its compute was refused, `max_run` after its longest run with no interaction (24 hours by default, from the person's last interaction, create, wake or access), `not_enabled` when the organization may no longer run machines, `idle` when nobody needs it (its agent idle 5 minutes and its person idle 20 minutes, or its host silent 15 minutes, or no report from its host in the 5 minutes after its last create, wake, access or connect), `resize` while it restarts one size bigger after it ran out of memory. Null otherwise, and cleared by a wake.
  - `queuedUntil` (string (date-time) | null, required): While `queued`: the earliest time Gateway tries to start it (the person's next start, the provider's `nextStartAt`, or the meter's next pass). Null otherwise.
  - `hostOnline` (boolean, required): The machine's host has its control connection open on this copy of Gateway: GET /v1/cloud/machines/{id}/connect can open a stream.
- `400` The body is not `{ busy, agentIdleSince, interactedAt, oomKills }`, or a time is not RFC 3339 (`invalid_time`).
- `403` The caller's token is not this machine's own (`not_machine_token`): only the machine reports its activity.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The provider has not made the machine yet (`machine_not_made`).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`).

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not `{ busy, agentIdleSince, interactedAt, oomKills }`, or a time is not RFC 3339 (`invalid_time`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The provider has not made the machine yet (`machine_not_made`). |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/activity" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "busy": false
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Factivity)

## Cloud machine setup token

`POST /v1/cloud/machines/{id}/setup-token`

The machine's own setup at boot (on with `NEXUS_CLOUD_BOOT_SETUP`). The machine's host sends the sealed grant from its `cloud.json` with the machine's own Nexus token. Gateway answers the repository and a GitHub App token that may only read it, for an hour at most. Gateway seals a grant only when GitHub lets the session's person read the repository and the organization's GitHub App reaches it. The grant works for one hour after the create, and ends sooner when the machine's setup is ready (`setup-done`). Gateway never logs the token.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |

### Request body (application/json, required)

- `grant` (string, required): The sealed grant from the machine's `cloud.json` (`setup.grant`). It holds no credential. [max length 4096]

### Responses

- `200` OK (application/json, CloudSetupToken)
  - `repo` (string, required): The repository the machine sets up (`owner/name`).
  - `token` (string, required): A GitHub App token that may only read `repo`, for an hour at most. Keep it in memory only.
- `400` The body is not `{ grant }`.
- `403` The caller's token is not this machine's own (`not_machine_token`), or the grant is not this machine's, ran out, or the setup is off (`setup_grant_refused`). The app clones the repository instead.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The organization's GitHub App no longer reaches the repository (`github_app_not_installed`), or the provider has not made the machine yet (`machine_not_made`).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` GitHub gave no token (`github_unavailable`). Try again.
- `503` No provider account on this Gateway (`cloud_unavailable`).

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not `{ grant }`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The organization's GitHub App no longer reaches the repository (`github_app_not_installed`), or the provider has not made the machine yet (`machine_not_made`). |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | GitHub gave no token (`github_unavailable`). Try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/setup-token" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "grant": "<grant>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fsetup-token)

## Cloud machine setup done

`POST /v1/cloud/machines/{id}/setup-done`

The machine's own setup at boot is ready. The machine's host sends the sealed grant from its `cloud.json` with the machine's own Nexus token, and Gateway ends the grant: no setup token is given for the machine again. A repeat is fine.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |

### Request body (application/json, required)

- `grant` (string, required): The sealed grant from the machine's `cloud.json` (`setup.grant`). It holds no credential. [max length 4096]

### Responses

- `200` OK (application/json, CloudSetupDone)
  - `ended` (boolean, required): True: the grant ended, and no setup token is given for the machine again.
- `400` The body is not `{ grant }`.
- `403` The caller's token is not this machine's own (`not_machine_token`), or the grant is not this machine's, ran out, or the setup is off (`setup_grant_refused`). The app clones the repository instead.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The provider has not made the machine yet (`machine_not_made`).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`).

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | The body is not `{ grant }`. |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The provider has not made the machine yet (`machine_not_made`). |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/setup-done" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "grant": "<grant>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fsetup-done)

## Cloud machine access

`POST /v1/cloud/machines/{id}/access`

Add this device's SSH public key to your machine. Answers where to connect and the host key to pin. Both change on every wake. An access with the machine's own Nexus token does not count as the person's activity.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `publicKey` (string, required): One SSH public key line, such as `ssh-ed25519 AAAA…`. [max length 4096]

### Responses

- `200` OK (application/json, CloudAccess)
  - `host` (string, required)
  - `port` (integer, required) [min 1; max 65535]
  - `user` (string, required)
  - `hostKey` (string, required): The machine's SSH host key, to pin.
- `400` `publicKey` is not one SSH public key line (`invalid_ssh_key`), or the machine is not running (`machine_not_running`).
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`). Only the organizations Nexus lists may start or use a machine; anyone may still list, sleep and delete their own.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `publicKey` is not one SSH public key line (`invalid_ssh_key`), or the machine is not running (`machine_not_running`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/access" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "publicKey": "<publicKey>"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Faccess)

## Cloud machine connect

`GET /v1/cloud/machines/{id}/connect`

A stream to your machine's host, a WebSocket, with your Gateway token: the desktop app's connection to its cloud session, with no SSH. Gateway asks the host to open its side and joins the two. Each text and binary frame and the close pass on as they came. Gateway reads and stores no frame. A frame is at most 16 MiB. Gateway pings every 20 seconds. When the host does not open its side within 10 seconds, the stream closes with 1013 (try again later); when Gateway stops, with 1012. A joined stream counts as an interaction, as an access does. Gateway holds the streams in memory, on one copy.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Upgrade` | header | "websocket" | yes | A WebSocket upgrade (RFC 6455). |

### Responses

- `101` Switching Protocols: Gateway asks the host to open its side.
- `400` The request is not a WebSocket upgrade (`websocket_required`).
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`).
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The machine's host is not connected (`host_offline`): it is asleep or still starting. Wake it, or try again after `Retry-After` seconds.
- `429` The machine has its most streams open, 8 (`too_many_streams`): close one first. Also over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds.
- `503` No provider account on this Gateway (`cloud_unavailable`). Also `machine_not_ready`: the provider has not made the machine yet.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 |  | The request is not a WebSocket upgrade (`websocket_required`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The machine's host is not connected (`host_offline`): it is asleep or still starting. Wake it, or try again after `Retry-After` seconds. |
| 429 |  | The machine has its most streams open, 8 (`too_many_streams`): close one first. Also over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). Also `machine_not_ready`: the provider has not made the machine yet. |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>/connect" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fconnect)

## Cloud machine host

`GET /v1/cloud/machines/{id}/host`

The control connection of a cloud machine's host (`nexus-host`), a WebSocket, with the machine's own Nexus token (the one in `~/.nexus/host/credentials`). Gateway sends it a text frame `{"type":"open","stream":"<id>"}` for each app stream, and the host opens that stream within 10 seconds (GET /v1/cloud/machines/{id}/host/streams/{stream}). The host sends nothing but pings. One per machine: a new one closes the old one (close code 1000, `replaced`). Gateway pings every 20 seconds and closes with 1012 when it stops. While it is open, the machine's `hostOnline` is true.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Upgrade` | header | "websocket" | yes | A WebSocket upgrade (RFC 6455). |

### Responses

- `101` Switching Protocols: the control connection is open.
- `400` The request is not a WebSocket upgrade (`websocket_required`).
- `403` The caller's token is not this machine's own (`not_machine_token`): only the machine's host opens it.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`).

### Errors

| Status | Code | When |
| --- | --- | --- |
| 100 | `replaced` | A new one closes the old one (close code 1000, `replaced`) |
| 400 |  | The request is not a WebSocket upgrade (`websocket_required`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>/host" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhost)

## Cloud machine host stream

`GET /v1/cloud/machines/{id}/host/streams/{stream}`

A stream from a cloud machine's host, a WebSocket, with the machine's own Nexus token: the answer to an `open` frame of its control connection. Gateway joins it to the app that waits, and passes each text and binary frame and the close on as they came. Gateway reads and stores no frame. A frame is at most 16 MiB.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `stream` | path | string | yes | The stream's id, from the control connection's `open` frame |
| `Upgrade` | header | "websocket" | yes | A WebSocket upgrade (RFC 6455). |

### Responses

- `101` Switching Protocols: the stream is joined to the app's.
- `400` The request is not a WebSocket upgrade (`websocket_required`).
- `403` The caller's token is not this machine's own (`not_machine_token`): only the machine's host opens it.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. Also `no_such_stream`: no app waits for this stream (it gave up after 10 seconds, or the id is another machine's).
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `503` No provider account on this Gateway (`cloud_unavailable`).

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 |  | The request is not a WebSocket upgrade (`websocket_required`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. Also `no_such_stream`: no app waits for this stream (it gave up after 10 seconds, or the id is another machine's). |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`). |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>/host/streams/<stream>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhost%2Fstreams%2F%7Bstream%7D)

## Cloud machine link

`POST /v1/cloud/machines/{id}/links`

A private link to a port on your machine (`{kind: "port", port}`, until it sleeps), or to its desktop stream (`{kind: "desktop"}`, for 10 minutes). On the cloud trial, a port link answers 403 `cloud_trial_no_links`.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Request body (application/json, required)

- `kind` ("port" | "desktop", required)
- `port` (integer): Required with `kind: port`. [min 1; max 65535]

### Responses

- `200` OK (application/json, CloudLink)
  - `url` (string (uri), required)
  - `expiresAt` (string (date-time) | null, required): When the link stops working; null when it lasts until the machine sleeps.
- `400` `kind` or `port` is not valid (`invalid_port`: 1 to 65535, not 22, 6080, 8090, 8911 or 47984 to 48010).
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`). Only the organizations Nexus lists may start or use a machine; anyone may still list, sleep and delete their own.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `kind` or `port` is not valid (`invalid_port`: 1 to 65535, not 22, 6080, 8090, 8911 or 47984 to 48010). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 403 | `cloud_trial_no_links` | On the cloud trial, a port link answers 403 `cloud_trial_no_links` |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/links" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "kind": "port"
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Flinks)

## Cloud machine sleep key

`POST /v1/cloud/machines/{id}/sleep-key`

A provider key that may only read and stop this one machine, for the machine's own idle timer, with the provider API it calls and the machine's id there. Gateway makes it once and keeps it sealed with the machine: each call answers the same key, a new one is made only when the provider no longer takes the old one, and the key is revoked when the machine is deleted. `key` is null when the provider refuses to make one. It is the only provider key that leaves Gateway.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `Idempotency-Key` | header | string | no | Send the same key again to retry safely: the request runs once. See [Idempotency keys](/docs/concepts/idempotency). |

### Responses

- `200` OK (application/json, CloudSleepKey)
  - `key` (string | null, required): A provider key that may only read and stop this machine; null when the provider refused.
  - `apiUrl` (string (uri), required): The provider API the key calls.
  - `providerId` (string, required): The machine's id at the provider.
- `403` Cloud machines are not turned on for this organization (`cloud_not_enabled`). Only the organizations Nexus lists may start or use a machine; anyone may still list, sleep and delete their own.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.
- `502` The cloud provider failed or did not answer (`cloud_provider_error`); try again.
- `503` No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 | `idempotency_in_progress` | A request with the same Idempotency-Key is still running |
| 409 | `idempotency_interrupted` | The first request with this Idempotency-Key was cut off and may have run in part |
| 422 | `idempotency_key_reused` | The Idempotency-Key was used with a different request |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |
| 502 |  | The cloud provider failed or did not answer (`cloud_provider_error`); try again. |
| 503 |  | No provider account on this Gateway (`cloud_unavailable`), or the provider has no free machine (`cloud_capacity`) or the machine is not ready yet (the provider's code, such as `sandbox_restoring`); try again later. |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/sleep-key" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fsleep-key)

## List cloud history threads

`GET /v1/cloud/machines/{id}/history`

The machine's workbench threads that have stored history, most recently updated first, at most 500, with each one's stored range. The machine's owner reads it, and so does the machine's own Nexus token, which backfills after the last stored event when it wakes. `enabled` is false, with no threads, while the organization's `cloudHistory` is off.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |

### Responses

- `200` OK (application/json, CloudHistoryThreads)
  - `machineId` (string, required)
  - `enabled` (boolean, required): The organization's `cloudHistory`
  - `threads` (array of CloudHistoryThread, required)
    - `threadId` (string, required)
    - `firstSeq` (integer, required): The first stored event's number
    - `lastSeq` (integer, required): The last stored event's number: every number from firstSeq to it is stored
    - `lastEventAt` (integer, required): The machine's time of the last event, in milliseconds since 1970
    - `updatedAt` (string (date-time), required)
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>/history" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhistory)

## Delete cloud history thread

`DELETE /v1/cloud/machines/{id}/history/{threadId}`

Deletes a thread's stored history, as the workbench deleted or archived the thread. The machine's owner or its own Nexus token. A repeat changes nothing.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `threadId` | path | string | yes | The workbench thread id on the machine: the session's `sessionId` (`t_…`) for its main thread |

### Responses

- `200` OK (application/json, CloudHistoryThreadDeleted)
  - `machineId` (string, required)
  - `threadId` (string, required)
  - `deleted` (boolean, required)
- `400` The thread id is not 1 to 128 letters, digits, `_` and `-` (`invalid_request`).
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 |  | The thread id is not 1 to 128 letters, digits, `_` and `-` (`invalid_request`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X DELETE "$NEXUS_URL/v1/cloud/machines/<id>/history/<threadId>" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#delete%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhistory%2F%7BthreadId%7D)

## List cloud history events

`GET /v1/cloud/machines/{id}/history/{threadId}/events`

A page of a thread's stored events, in number order, for the machine's owner only. Without `after` or `before`, the page is the thread's latest events. With `before`, it ends just before that event; with `after`, it starts just after it. A page holds at most `limit` events and about 4 MiB of bodies after its first event. An event whose body was over the per-event cap (256 KiB) has a null `body` and its size in `omittedBytes`. A thread with nothing stored answers no events and null numbers. While the organization's `cloudHistory` is off, `enabled` is false and there are no events.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `threadId` | path | string | yes | The workbench thread id on the machine: the session's `sessionId` (`t_…`) for its main thread |
| `after` | query | integer | no | Start just after this event number |
| `before` | query | integer | no | End just before this event number; not with `after` |
| `limit` | query | integer | no | The most events a page holds |

### Responses

- `200` OK (application/json, CloudHistoryEventPage)
  - `machineId` (string, required)
  - `threadId` (string, required)
  - `enabled` (boolean, required): The organization's `cloudHistory`
  - `firstSeq` (integer | null, required): The first stored event's number; null when none is stored
  - `lastSeq` (integer | null, required): The last stored event's number; null when none is stored
  - `events` (array of CloudHistoryEvent, required)
    - `seq` (integer, required): The machine's workbench event number [min 1]
    - `at` (integer, required): The machine's time of the event, in milliseconds since 1970
    - `body` (string | null, required): The workbench event's JSON text, as the machine sent it; null when it was over the per-event cap
    - `omittedBytes` (integer): The size of a body over the per-event cap; absent when `body` is there [min 0]
- `400` `after` with `before`, a number that is not a whole number, a `limit` outside 1 to 500, or a bad thread id (`invalid_request`).
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 256 | `body` | An event whose body was over the per-event cap (256 KiB) has a null `body` and its size in `omittedBytes` |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | `after` with `before`, a number that is not a whole number, a `limit` outside 1 to 500, or a bad thread id (`invalid_request`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl "$NEXUS_URL/v1/cloud/machines/<id>/history/<threadId>/events" \
  -H "Authorization: Bearer $NEXUS_API_KEY"
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#get%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhistory%2F%7BthreadId%7D%2Fevents)

## Append cloud history events

`POST /v1/cloud/machines/{id}/history/{threadId}/events`

Stores a thread's next events, sent by the machine's host (`nexus-host`) with the machine's own Nexus token as its workbench log appends them. 1 to 64 events with consecutive numbers. The first is at most one past the last stored, or 1 for a new thread. An event already stored must come back identical, so a retried batch never duplicates. All or nothing. A body over 256 KiB is stored as omitted, with its size, and never refused. While the organization's `cloudHistory` is off, nothing is stored and `enabled` is false.

Permission: `cloud.machines.use` (Every member).

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes | The machine's id (`cm_…`), as POST /v1/cloud/machines answered it |
| `threadId` | path | string | yes | The workbench thread id on the machine: the session's `sessionId` (`t_…`) for its main thread |

### Request body (application/json, required)

- `events` (array of object, required) [at most 64 items]
  - `seq` (integer, required) [min 1]
  - `at` (integer, required): Milliseconds since 1970 [min 0]
  - `body` (string): The workbench event's JSON text
  - `omittedBytes` (integer): Instead of `body`: the host dropped a body over the per-event cap, of this size [min 0]

### Responses

- `200` OK (application/json, CloudHistoryAppended)
  - `machineId` (string, required)
  - `threadId` (string, required)
  - `enabled` (boolean, required): The organization's `cloudHistory`; false, and nothing was stored
  - `lastSeq` (integer | null, required): The last stored event's number: send the next one after it; null when nothing is stored
  - `appended` (integer, required): How many events this call stored [min 0]
- `400` No events, more than 64, numbers that are not consecutive or under 1, a bad time, a body that is not JSON, or an event with both or neither of `body` and `omittedBytes` (`invalid_request`).
- `403` The caller's token is not this machine's own (`not_machine_token`): only the machine sends its history.
- `404` No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one.
- `409` The first event is past the next one Gateway expects (`seq_gap`): read listCloudHistoryThreads and send from its `lastSeq` + 1. Or an event already stored differs from the one sent (`event_conflict`).
- `413` The person's cloud history in this organization holds its cap (`cloud_history_full`), or the body is over 1 MB.
- `429` Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). (application/json, Error)
  - `error` (object)
    - `message` (string, required)
    - `type` (string, required): The class of the error: invalid_request_error (400, 405, 408, 409, 413, 422, 426), authentication_error (401), billing_error (402), permission_error (403), not_found (404), rate_limit_error (429), or a 5xx type such as server_error.
    - `code` (string): Stable: branch on it, not on message. Every 4xx carries one: its site's own code, else the default for its status (400 invalid_request, 401 unauthenticated, 402 payment_required, 403 forbidden, 404 not_found, 405 method_not_allowed, 408 request_timeout, 409 conflict, 422 unprocessable, 429 rate_limited, any other 4xx invalid_request). A 502 carries its site's code, else upstream_error. Any other 5xx carries one only when its site sets it. The agent routes (/v1/anthropic/, /v1/openai/) answer in the provider's shape.
    - `param` (string): `model` when the error is a model refusal (a `code` starting with `model_`); absent otherwise.
    - `nexus` (object): Details of the error, when it has any: the policy rule of a model refusal, the seconds of a 408.
    - `minimum` (string): On a 426 `cli_too_old` only: the oldest `nexus` CLI version Gateway supports.

### Errors

| Status | Code | When |
| --- | --- | --- |
| 400 | `invalid_request_error` | A field is missing or not valid; the message names it |
| 400 |  | No events, more than 64, numbers that are not consecutive or under 1, a bad time, a body that is not JSON, or an event with both or neither of `body` and `omittedBytes` (`invalid_request`). |
| 401 | `authentication_error` | No key, or a key Gateway does not accept |
| 403 | `role_required` | Your role does not have this permission |
| 404 | `not_found` | Nothing matches the path in your organization |
| 404 |  | No such machine of yours: another person's machine, another organization's and a deleted one are as absent as a missing one. |
| 409 |  | The first event is past the next one Gateway expects (`seq_gap`): read listCloudHistoryThreads and send from its `lastSeq` + 1. Or an event already stored differs from the one sent (`event_conflict`). |
| 413 |  | The person's cloud history in this organization holds its cap (`cloud_history_full`), or the body is over 1 MB. |
| 429 |  | Over the caller's rate limit (`rate_limit_error`): retry after `Retry-After` seconds. Also a 429 `concurrency_limit`, with `Retry-After: 1`, when the organization already has its most requests in flight (off unless Gateway sets a cap). |
| 429 | `rate_limit_error` | Too many requests from this key in a minute |

### Example

```sh
curl -X POST "$NEXUS_URL/v1/cloud/machines/<id>/history/<threadId>/events" \
  -H "Authorization: Bearer $NEXUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "events": [
      {
        "seq": 1,
        "at": 0
      }
    ]
  }'
```

Try it: [API Explorer](/app?next=%2Fapi-explorer#post%3A%2Fv1%2Fcloud%2Fmachines%2F%7Bid%7D%2Fhistory%2F%7BthreadId%7D%2Fevents)
