Skip to content

Your app keeps one VM for each of its users. The first request for a user creates the VM. Every later request for that user returns the same VM.

  • An approved account and an API key from the API keys page.
  • A user id of lowercase letters, digits and hyphens, at most 27 characters. The VM’s name is user- followed by the id, and a VM name has at most 32 characters.
  • Python 3.12 with requests, or Node 22, for the Python and TypeScript tabs.

A profile holds the settings that each new VM copies. Create it once. Later VMs reuse it by name.

Terminal window
export SI_API_KEY=si_...
export USER_ID=ada
curl -sS -X POST "https://api.slashinfra.com/profiles" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"name":"worker","env":{"TZ":"UTC"}}'
Output
{"id":"prof_6f1c0f0e8a","name":"worker",...}

A later profile change does not reach the VMs that already copied it.

The request names the VM user-<id>, sets the profile and adds a label with the user id. if_absent makes the create return the existing VM with 200 instead of failing with 409. Labels let you find a user’s VM later without the name, with GET /svms?label.user=<id>.

The function below returns the VM id in both cases. Keep it in the same file as the next step.

Terminal window
curl -sS -i -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"name\":\"user-$USER_ID\",\"profile_id\":\"worker\",\"labels\":{\"user\":\"$USER_ID\"},\"if_absent\":true}"
Output
HTTP/2 201
{"id":"6f1c0f0e8a","generation":1,"labels":{"user":"ada"},...}

Use the id as VM in the requests for this user, as in Files and programs over HTTP.

Send the same request again. The reply is 200, with the same id. The VM keeps its files, and it keeps the settings it was created with.

Terminal window
curl -sS -i -X POST "https://api.slashinfra.com/svms" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d "{\"name\":\"user-$USER_ID\",\"profile_id\":\"worker\",\"labels\":{\"user\":\"$USER_ID\"},\"if_absent\":true}"
Output
HTTP/2 200
{"id":"6f1c0f0e8a","generation":1,"labels":{"user":"ada"},...}

You should see the same id in both calls. The second reply is 200, not 201. The Python and TypeScript tabs print whether the two ids match, then the id.

Symptom Cause Fix
400 invalid_name The user id has a character other than a lowercase letter, digit or hyphen, or it is too long. Map the user id to a shorter lowercase id, and keep the mapping in your app.
401 unauthorized The key is missing, wrong or deleted. Set SI_API_KEY to a key from the API keys page.
409 svm_limit Your account has reached its limit of VMs. Delete the VMs of users who left.

Scroll horizontally to see all columns.

When a user leaves, delete their VM. Once the delete finishes, the user’s next request creates a new VM with no files from the old one. To delete VMs on their own, create them with ttl_s, up to 2592000 seconds (30 days).

Terminal window
curl -sS -i -X DELETE "https://api.slashinfra.com/svms/$VM" \
-H "Authorization: Bearer $SI_API_KEY"
Output
HTTP/2 204
  • App builder: one VM per user, and a page that only its user can open.
  • Workload profiles: the profile commands, the copy rules and the domain syntax.
  • Sleep and wake: what a user’s VM keeps while it sleeps between requests.