Also as Markdown for agents: /docs/api.md

Yurt API

Make, sleep, wake and delete VMs, and run commands in them, over HTTPS. Get told about changes with webhooks.

Base URL: https://getyurt.dev/api/v1

Authentication

Make a key in the dashboard under API keys. It starts with yurt_ and is shown once. Send it as a bearer token:

curl https://getyurt.dev/api/v1/vms -H "Authorization: Bearer $YURT_API_KEY"

A key is either:

Delete a key in the dashboard to revoke it right away.

Errors

Errors return a status code and a JSON body with one field: {"error": "what went wrong"}.

The VM object

{
  "name": "agent-1",
  "state": "running",
  "sleeps_in": "12m",
  "created": 1796220273,
  "awake_seconds_this_month": 51000,
  "cost_cents_this_month": 25.5,
  "ssh": "ssh agent-1@ssh.getyurt.dev"
}

Endpoints

GET /me

Your credits and limits.

curl https://getyurt.dev/api/v1/me -H "Authorization: Bearer $YURT_API_KEY"
{"account": "u3", "credits_cents": 1873.4, "spent_cents_this_month": 126.6,
 "price_per_hour": 0.018, "vm_size": "2 vCPU · 2 GB RAM · 10 GB disk", "max_vms": 3}

GET /vms

All your VMs: {"vms": [VM, ...]}.

POST /vms

Make a VM. Takes about 10 seconds. Every ssh key on your account can log in to it.

curl -X POST https://getyurt.dev/api/v1/vms -H "Authorization: Bearer $YURT_API_KEY" \
  -H "Content-Type: application/json" -d '{"name": "agent-1", "idle_minutes": 30}'

Returns the VM.

GET /vms/{name}

One VM.

PATCH /vms/{name}

Change idle sleep: {"idle_minutes": 60} or {"idle_minutes": "off"}. Returns the VM.

POST /vms/{name}/sleep

Put it to sleep now. Memory and running programs are kept. Returns the VM.

POST /vms/{name}/wake

Wake it, or boot it if it was stopped. Takes about a second. Returns the VM.

POST /vms/{name}/exec

Run a shell command as root and wait for it. Wakes the VM if it sleeps.

curl -X POST https://getyurt.dev/api/v1/vms/agent-1/exec -H "Authorization: Bearer $YURT_API_KEY" \
  -H "Content-Type: application/json" -d '{"command": "cd /root/app && npm test", "timeout": 300}'
{"exit_code": 0, "stdout": "...", "stderr": ""}

DELETE /vms/{name}

Delete the VM and everything on it. This can't be undone. Returns {"deleted": "agent-1"}.

Webhooks

Add an endpoint in the dashboard under Webhooks. Yurt then POSTs JSON to it when something happens to your VMs.

Events:

vm.awake and vm.asleep arrive up to a minute after the change.

{"id": "evt_3f9a1c2b7d4e5f60", "type": "vm.asleep", "created": 1796220400,
 "data": {"account": "u3", "vm": "agent-1", "state": "sleeping"}}

Rules:

Verify the signature

Each request has webhook-id, webhook-timestamp and webhook-signature headers (the Standard Webhooks format). The signature is v1, plus the base64 HMAC-SHA256 of id.timestamp.body, keyed with your secret (after whsec_, base64-decoded).

import base64, hashlib, hmac, time

def verify(secret, headers, body):
    key = base64.b64decode(secret.removeprefix("whsec_"))
    msg = f"{headers['webhook-id']}.{headers['webhook-timestamp']}.".encode() + body
    good = base64.b64encode(hmac.new(key, msg, hashlib.sha256).digest()).decode()
    fresh = abs(time.time() - int(headers["webhook-timestamp"])) < 300
    return fresh and any(hmac.compare_digest(s.partition(",")[2], good)
                         for s in headers["webhook-signature"].split())

Libraries from standardwebhooks.com work too.

Limits