Tenant machines
Create, list, get, revoke and delete a Tenant's machines under /v1/tenants/{tenantId}/machines.
A Tenant has two kinds of machine:
- An enrolled machine is one of your customer's own computers, running the Sai runtime and enrolled into the Tenant.
- A cloud machine is a computer that Sai hosts for the Tenant. Your backend creates and deletes it. Cloud machines walks through the whole flow.
Your backend manages both with an Organisation Key. A Tenant token sees the same machines in GET /v1/agents/machines.
The console shows them on the Tenant's page in the portal.
The machine object
{
"machineId": "tm_5a1f0c9e2b7d4e6a8c3f1b2d",
"kind": "enrolled",
"name": "Front desk PC",
"platform": "darwin",
"state": "online",
"status": "active",
"online": true,
"lastSeen": 1790003600000,
"runtimeVersion": "1.2.0",
"createdAt": 1790000000000,
"capabilities": {
"canSee": null,
"canUseAccessibility": null,
"canControl": null
}
}{
"machineId": "3b7e9c1a-5f2d-4e8a-9c0b-1d2e3f4a5b6c",
"kind": "cloud",
"name": "Riverside intake",
"platform": "win32",
"machineClass": "win32-4c8g",
"state": "ready",
"lastSeen": 1790003600000,
"runtimeVersion": "1.2.0",
"createdAt": 1790000000000,
"capabilities": null
}A revoked or deleted machine leaves the list.
Capabilities
From Sai runtime 0.1.3, an enrolled machine reports whether Sai can use it. Each field is null when nothing stands in the way, or a sentence saying what does and, where there is one, the fix.
On a computer with no display attached, canSee and canControl are never null.
capabilities is null when the machine has no answer yet: its runtime is older than 0.1.3 or hasn't reported yet, or its check failed. Read null as "no answer", not as a kind of machine: cloud machines report too, once their runner does. A field that is null means nothing was found in the way, not a guarantee: a check that can't tell counts as fine. The runtime reports again whenever an answer changes, and an offline machine keeps its last answers. On macOS, ask the user for what's missing: see macOS permissions.
Cloud machine states
Create a cloud machine
curl -s -X POST "$SAI_API_URL/v1/tenants/$TENANT_ID/machines" \
-H "Authorization: Bearer $SAI_ORG_KEY" \
-H "Content-Type: application/json" \
-d '{
"os": "windows",
"name": "Riverside intake",
"requestId": "8d0c6b7e-2f4a-4c1e-9b3d-5a6f7e8d9c0b"
}'Any other field is refused with 400 invalid_body, so a misspelt requestID fails instead of being ignored.
{
"machineId": "3b7e9c1a-5f2d-4e8a-9c0b-1d2e3f4a5b6c",
"kind": "cloud",
"name": "Riverside intake",
"platform": "win32",
"machineClass": "win32-4c8g",
"state": "provisioning",
"lastSeen": null,
"runtimeVersion": null,
"createdAt": 1790000000000,
"capabilities": null
}The machine is in the list at once, in provisioning. Get it until state is ready.
The Tenant must be active. An Organisation can create 600 cloud machines an hour. A Tenant with a cloudMachineLimit can have at most that many cloud machines. See Limit a Tenant's cloud machines.
{
"error": "machine_limit_reached",
"limit": 2,
"used": 2,
"message": "The Tenant has as many cloud machines as its cloudMachineLimit allows."
}Retry a create
Generate a requestId for each machine you mean to create, such as a UUID, and send the same one again when you retry that create. Without a requestId, every call creates a new machine, so a retry after a timeout can leave you with two.
- The same
requestIdwith the same body returns the samemachineId. Itsstateis alwaysprovisioning. Get the machine for its current state. - The same
requestIdwith a differentos,nameor Tenant returns409 request_id_reused. - The same
requestIdsent again while the first create is still running returns409 create_in_progress. Nothing new is created. Retry in a few seconds with the samerequestId: once the first create has its machine, you get thatmachineId. - A refusal (
402,403,409 machine_limit_reachedor503) creates nothing. You can retry with the samerequestId. - After a
500, Sai may have created the machine. A retry with the samerequestIdfinishes that create instead of starting a second one. - A
requestIdbelongs to your Organisation. It is free again 24 hours after its first create.
List a Tenant's machines
curl -s "$SAI_API_URL/v1/tenants/$TENANT_ID/machines" \
-H "Authorization: Bearer $SAI_ORG_KEY"{
"machines": [
{
"machineId": "tm_5a1f0c9e2b7d4e6a8c3f1b2d",
"kind": "enrolled",
"name": "Front desk PC",
"platform": "darwin",
"state": "online",
"status": "active",
"online": true,
"lastSeen": 1790003600000,
"runtimeVersion": "1.2.0",
"createdAt": 1790000000000,
"capabilities": {
"canSee": null,
"canUseAccessibility": null,
"canControl": null
}
},
{
"machineId": "3b7e9c1a-5f2d-4e8a-9c0b-1d2e3f4a5b6c",
"kind": "cloud",
"name": "Riverside intake",
"platform": "win32",
"machineClass": "win32-4c8g",
"state": "hibernated",
"lastSeen": 1790003600000,
"runtimeVersion": "1.2.0",
"createdAt": 1790000000000,
"capabilities": null
}
]
}The list has both kinds. A disabled Tenant's machines are listed too.
Get a machine
curl -s "$SAI_API_URL/v1/tenants/$TENANT_ID/machines/$MACHINE_ID" \
-H "Authorization: Bearer $SAI_ORG_KEY"200 with the machine.
Watch a machine's screen
With a Tenant token, POST /v1/agents/machines/{machineId}/live returns a liveUrl and a websocketUrl for one of the Tenant's machines. On an enrolled machine, it needs the Sai runtime 0.1.2 or later on macOS, or 0.1.3 or later on Windows. See Live view.
Anyone holding a liveUrl for an enrolled machine can see and control your customer's real computer.
Revoke a machine
curl -s -X DELETE "$SAI_API_URL/v1/tenants/$TENANT_ID/machines/$MACHINE_ID" \
-H "Authorization: Bearer $SAI_ORG_KEY"204 No Content. The machine is signed out at once, leaves the list and cannot reconnect. To bring it back, enroll it again with a new code.
Revoking is for an enrolled machine. The same call on a cloud machine deletes it. See Delete a cloud machine.
To stop every machine of a Tenant at once, disable the Tenant: they stay enrolled and reconnect when it is enabled again. Deleting the Tenant revokes them all.
Delete a cloud machine
curl -s -X DELETE "$SAI_API_URL/v1/tenants/$TENANT_ID/machines/$MACHINE_ID" \
-H "Authorization: Bearer $SAI_ORG_KEY"{ "state": "deleting" }Sai deletes the machine and its disk. A delete cannot be undone. The machine shows deleting until Sai is done, then leaves the list. You can delete a disabled Tenant's machines too.
A machine in provisioning can be deleted once it reaches starting. A failed machine leaves the list by itself.
Disabling or deleting a Tenant with DELETE /v1/tenants/{tenantId} does not delete its cloud machines. They hibernate and stay listed until you delete them here.