TypeScript SDK

Reference for fastvm. Auto-generated from the OpenAPI spec + api/helpers.yaml.

Install

shell
npm install fastvm

Import

typescript
import { FastvmClient } from 'fastvm';

const client = new FastvmClient(); // reads FASTVM_API_KEY / FASTVM_BASE_URL

Top-level helpers

client.*

client.health

GET/healthz
client.health(): APIPromise<HealthResponse>

Description

Health check

Returns

client.uploadhelper

client.upload(
  vmId: string,
  localPath: string,
  remotePath: string,
  opts?: { fetchTimeoutSec?: number; execTimeoutSec?: number },
): Promise<void>

Description

Copy a local file or directory into the VM. Uses vms.files.presign and vms.files.fetch under the hood. Directories are tarred on the fly before upload and extracted VM-side after fetch.

Streams end-to-end with no intermediate copy to /tmp on the client, so multi-GB transfers are bounded by VM disk, not RAM. Directory mode needs the tar binary on the client's PATH (standard on macOS and Linux; available on modern Windows via bsdtar).

Parameters

ParamTypeDefaultDescription
vmIdstringrequiredTarget VM id.
localPathstringrequiredLocal file or directory path.
remotePathstringrequiredDestination path inside the VM.
opts.fetchTimeoutSecnumber600Timeout on the VM-side /files/fetch call.
opts.execTimeoutSecnumber600Timeout on VM-side tar extraction.

Returns

Promise<void>

Example

typescript
await client.upload(vm.id, './config.toml', '/etc/app.toml');
await client.upload(vm.id, './src', '/root/src');

client.downloadhelper

client.download(
  vmId: string,
  remotePath: string,
  localPath: string,
  opts?: { fetchTimeoutSec?: number; execTimeoutSec?: number },
): Promise<void>

Description

Copy a file or directory from the VM to the client. Uses vms.files.presign plus a VM-side exec to classify the path and stream its contents out. Directories are tarred VM-side and un-tarred on the client, rooted at ./ so upload and download are symmetric.

Streams end-to-end with no intermediate copy. Missing paths raise FileNotFoundError (Python) or FileTransferError with code: 'ENOENT' (TypeScript).

Parameters

ParamTypeDefaultDescription
vmIdstringrequiredTarget VM id.
remotePathstringrequiredSource path inside the VM.
localPathstringrequiredDestination path on the client.
opts.fetchTimeoutSecnumber600Timeout on VM-side /files/fetch.
opts.execTimeoutSecnumber600Timeout on VM-side exec.

Returns

Promise<void>

Example

typescript
await client.download(vm.id, '/root/out.log', './out.log');
await client.download(vm.id, '/var/log', './log-backup');

client.waitForVmReadyhelper

client.waitForVmReady(
  vmId: string,
  opts?: { pollIntervalMs?: number; timeoutMs?: number },
): Promise<VM>

Description

Poll GET /v1/vms/{id} until the VM reaches status == "running" or a terminal failure status. Same polling logic as vms.launch; use this when you already have a VM id from vms.list() or another flow.

Parameters

ParamTypeDefaultDescription
vmIdstringrequiredTarget VM id.
opts.pollIntervalMsnumber2000Milliseconds between polls.
opts.timeoutMsnumber300000Total wait deadline in ms.

Returns

Promise<>

Example

typescript
let vm = await client.vms.retrieve(someId);
vm = await client.waitForVmReady(vm.id, { timeoutMs:  });

VMs

client.vms.*

client.vms.list

GET/v1/vms
client.vms.list(): APIPromise<VM[]>

Description

List VMs

Returns

[]

client.vms.launchoverride

POST/v1/vms
client.vms.launch(
  params: VmLaunchParams,
  options?: RequestOptions,
  launchOpts?: { wait?: boolean; pollIntervalMs?: number; timeoutMs?: number },
): APIPromise<VM>

Description

Launch a VM and (by default) block until it reaches status == "running". POST /v1/vms returns 201 for immediately-running VMs and 202 for queued VMs; the override handles both paths transparently by polling GET /v1/vms/{id}.

Pass wait=false (TS) / wait=False (Python) to skip polling and return the raw 201/202 body. Pass snapshot_id / snapshotId to restore from a snapshot instead of cold-booting.

Terminal failure statuses (error, stopped, deleting) raise VMLaunchError. Polling-deadline exceeded raises VMNotReadyError.

Parameters

ParamTypeDefaultDescription
paramsVmLaunchParamsrequiredGenerated launch params (machineType, snapshotId, name, metadata, firewall).
optionsRequestOptions | undefinedundefinedGenerated per-request options (headers, signal, timeout, etc.).
launchOpts.waitbooleantrueBlock until RUNNING. Set false for raw 201/202 behavior.
launchOpts.pollIntervalMsnumber2000Milliseconds between polls (±10% jitter applied).
launchOpts.timeoutMsnumber300000Total polling deadline in ms. Throws VMNotReadyError on exceed.

Returns

APIPromise<>

Example

typescript
import { FastvmClient } from 'fastvm';

const client = new FastvmClient();
const vm = await client.vms.launch({ machineType: 'c1m2', name: 'dev' });
console.log(vm.id, vm.status); // "running"

// Restore from snapshot
const fromSnap = await client.vms.launch({ snapshotId: 'snp_...' });

// Skip polling — returns the raw 201/202 body
const queued = await client.vms.launch(
  { machineType: 'c1m2' },
  undefined,
  { wait: false },
);

client.vms.retrieve

GET/v1/vms/{id}
client.vms.retrieve(
  id: string,
): APIPromise<VM>

Description

Get a VM

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).

Returns

client.vms.update

PATCH/v1/vms/{id}
client.vms.update(
  id: string,
  name: string,
  metadata: Metadata,
): APIPromise<VM>

Description

Update a VM

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).
namestring
metadataMetadata

Returns

client.vms.delete

DELETE/v1/vms/{id}
client.vms.delete(
  id: string,
): APIPromise<DeleteResponse>

Description

Delete a VM

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).

Returns

client.vms.setFirewall

PUT/v1/vms/{id}/firewall
client.vms.setFirewall(
  id: string,
  mode: FirewallMode,
  ingress: FirewallRule[],
): APIPromise<VM>

Description

Replace firewall policy

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).
modeFirewallModerequired
ingressFirewallRule[]

Returns

client.vms.patchFirewall

PATCH/v1/vms/{id}/firewall
client.vms.patchFirewall(
  id: string,
  mode: FirewallMode,
  ingress: FirewallRule[],
): APIPromise<VM>

Description

Patch firewall policy

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).
modeFirewallMode
ingressFirewallRule[]

Returns

client.vms.consoleToken

POST/v1/vms/{id}/console-token
client.vms.consoleToken(
  id: string,
): APIPromise<ConsoleTokenResponse>

Description

Mint a console token

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).

Returns

client.vms.runrefresh

POST/v1/vms/{id}/exec
client.vms.run(
  id: string,
  params: VmRunParams,
  options?: RequestOptions,
): APIPromise<ExecVMResponse>

Description

Execute a command inside a VM. Same generated method as upstream. TypeScript doesn't silently iterate strings into characters, so no shell-string auto-wrap helper is needed. Pass an argv array directly.

Parameters

ParamTypeDefaultDescription
idstringrequiredTarget VM id.
paramsVmRunParamsrequiredRequest body (command: string[], timeoutSec?: number).
optionsRequestOptions | undefinedundefinedGenerated per-request options.

Returns

APIPromise<>

Example

typescript
const result = await client.vms.run(vm.id, {
  command: ['python3', 'main.py', '--flag'],
});
console.log(result.exitCode, result.stdout);

VMs.Files

client.vms.files.*

client.vms.files.presign

POST/v1/vms/{id}/files/presign
client.vms.files.presign(
  id: string,
  path: string,
): APIPromise<FilePresignResponse>

Description

Mint signed URLs for uploading a file to a VM

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).
pathstringrequiredAbsolute destination path inside the guest filesystem (where the file will land after fetchFileToVm). Used only to scope the staging object key; any value server-side is accepted here.

Returns

Example

typescript
// High-level helpers — handle presign + PUT/GET + fetch + (for dirs) tar
// for both file and directory transfers automatically.
await client.upload(vm.id, './local/file.txt', '/root/file.txt');
await client.upload(vm.id, './local-dir', '/root/remote-dir');

await client.download(vm.id, '/root/out.log', './out.log');
await client.download(vm.id, '/var/log', './log-backup');

// Raw call if you need manual control over the signed-URL flow:
const presign = await client.vms.files.presign(vm.id, { path: '/root/file.txt' });

client.vms.files.fetch

POST/v1/vms/{id}/files/fetch
client.vms.files.fetch(
  id: string,
  url: string,
  path: string,
  timeoutSec: number,
): APIPromise<ExecVMResponse>

Description

Fetch a file into a VM from a presigned URL

Parameters

ParamTypeDefaultDescription
idstringrequiredVM ID (UUID).
urlstringrequiredMust be the downloadUrl previously returned by POST /v1/vms/{id}/files/presign (URLs from other sources are rejected).
pathstringrequiredAbsolute destination path inside the guest filesystem.
timeoutSecnumberPer-fetch timeout in seconds.

Returns

Example

typescript
// You usually don't call this directly — client.upload() composes
// presign + PUT + fetch in a single call. Use it when piping an
// already-hosted URL (still from /files/presign) into the VM.
await client.vms.files.fetch(vm.id, {
  url: presign.downloadUrl,
  path: '/root/file.txt',
});

Snapshots

client.snapshots.*

client.snapshots.list

GET/v1/snapshots
client.snapshots.list(): APIPromise<Snapshot[]>

Description

List snapshots

Returns

[]

client.snapshots.create

POST/v1/snapshots
client.snapshots.create(
  vmId: string,
  name: string,
): APIPromise<Snapshot>

Description

Create a snapshot

Parameters

ParamTypeDefaultDescription
vmIdstringrequired
namestringSnapshot name (trimmed + whitespace-collapsed, max 64 runes; longer values are truncated server-side). Auto-generated as snapshot-<8-char-vmId-prefix> if empty.

Returns

client.snapshots.update

PATCH/v1/snapshots/{id}
client.snapshots.update(
  id: string,
  name: string,
): APIPromise<Snapshot>

Description

Rename a snapshot

Parameters

ParamTypeDefaultDescription
idstringrequiredSnapshot ID (UUID).
namestring

Returns

client.snapshots.delete

DELETE/v1/snapshots/{id}
client.snapshots.delete(
  id: string,
): APIPromise<DeleteResponse>

Description

Delete a snapshot

Parameters

ParamTypeDefaultDescription
idstringrequiredSnapshot ID (UUID).

Returns

Quotas

client.quotas.*

client.quotas.retrieve

GET/v1/org/quotas
client.quotas.retrieve(): APIPromise<OrgQuotaUsage>

Description

Get org quotas and usage

Returns

Types

Shared schemas referenced in parameters and return values.

DeleteResponse

object
FieldTypeDescription
idstring
deletedboolean

VMStatus

primitive
Lifecycle status. Known values: provisioning, running, stopped, deleting, error. Terminal failure statuses are error and stopped; any other non-running value indicates the VM is still transitioning. Additional values may be introduced in future server versions; clients should treat unknown values as "in transition" rather than as hard errors.

SnapshotStatus

primitive
Snapshot lifecycle status. Known values: creating, ready, error. Additional values may be introduced in future server versions.

VM

object
FieldTypeDescription
idstring
namestring
orgIdstring
machineNamestring
sourceNamestringSource snapshot or image name (empty on fresh boot).
firewallFirewallPolicy
metadataMetadata
publicIpv6string
cpunumber
memoryMiBnumber
diskGiBnumber
statusVMStatus
createdAtstring
deletedAtunknown

Snapshot

object
FieldTypeDescription
idstring
namestring
orgIdstring
vmIdstring
firewallFirewallPolicy
metadataMetadata
statusSnapshotStatus
createdAtstring

FirewallMode

primitive
Firewall mode. Known values: open (allow all inbound traffic), restricted (deny by default; only rules listed in ingress are allowed). Additional values may be introduced in future server versions.

FirewallRule

object
FieldTypeDescription
protocolstringIP protocol. Known values: tcp, udp. Additional values may be introduced in future server versions.
portStartnumberStart of port range (inclusive). Required.
portEndnumberEnd of port range (inclusive). Omit for single-port rules.
sourceCidrsstring[]Allowed source CIDRs in IPv6 notation (e.g. 2001:db8::/32). Omit or empty to allow any source. IPv4 CIDRs are rejected.
descriptionstring

FirewallPolicy

object
FieldTypeDescription
modeFirewallMode
ingressFirewallRule[]

Metadata

object
Free-form string→string map. Server-enforced limits: up to 256 keys, key length 1–256 bytes, value length ≤4096 bytes, total JSON encoding ≤65536 bytes.

ExecVMResponse

object
Buffered response shape for POST /v1/vms/{id}/exec under Accept: application/json. The server collects the streamed events and returns this aggregate once the command exits. Per-stream output is capped at 4 MiB; overflow bytes are dropped and signalled via stdoutTruncated / stderrTruncated. Streaming clients (Accept: application/x-ndjson) receive every byte without a cap.
FieldTypeDescription
exitCodenumber
stdoutstring
stderrstring
timedOutboolean
stdoutTruncatedbooleanTrue if the collector dropped stdout bytes past the 4 MiB cap.
stderrTruncatedbooleanTrue if the collector dropped stderr bytes past the 4 MiB cap.
durationMsnumber

FilePresignResponse

object
Pair of signed URLs scoped to the same per-VM staging object. Usable in either direction: either side (client or VM) PUTs bytes to uploadUrl, and either side GETs them back via downloadUrl. URLs expire after expiresInSec seconds and the staging object is auto-deleted after about a day.
FieldTypeDescription
uploadUrlstringPresigned PUT URL for the staging object. Accepts Content-Type: application/octet-stream. Used by the client on upload, or by the VM (via an exec'd curl -T -) on download.
downloadUrlstringPresigned GET URL for the same staging object. Used by the VM (via POST /v1/vms/{id}/files/fetch) on upload, or by the client (via httpx.stream / curl) on download.
expiresInSecnumberLifetime of both URLs in seconds.
maxUploadBytesnumberUpper bound on upload size (equals the VM's disk size in bytes).

ConsoleTokenResponse

object
FieldTypeDescription
tokenstring
expiresInSecnumber
websocketPathstringRelative WebSocket path; combine with your API host as wss://<host><websocketPath>?session=<token>.

OrgQuotaValues

object
FieldTypeDescription
vcpunumber
memoryMiBnumber
diskGiBnumber
snapshotCountnumber

OrgQuotaUsage

object
FieldTypeDescription
orgIdstring
limitsOrgQuotaValues
usageOrgQuotaValues

HealthResponse

object
Health check
FieldTypeDescription
statusstring