Skip to content
betterstack-alchemyUnofficial

Servers

A Server is a Better Stack Cloud virtual machine: Ubuntu on NVMe storage, with public IPv4 and IPv6 addresses, private networks and a firewall, billed hourly up to a monthly cap. It is both a compute primitive and the host that Services and Websites deploy onto.

us-west-2aavailability zone
publicfirewall
privatenetwork · 10.0.0.0/24
boxserver
type
AM1
image
ubuntu-26-04
key
deploy key
  • publicfilters →box
  • privateattaches →box
A server lives in one availability zone. Its type and image are properties of the box; a firewall and private networks are separate objects attached to it.

The smallest server is a type and an image:

alchemy.run.ts
const server = yield* BetterStack.Cloud.Server("box", {
serverType: "AM1",
image: "ubuntu-26-04",
});

serverType is a type name such as AM1, the smallest available in us-west-2a when checked on 2026-12-01. image is an image slug such as ubuntu-26-04. Changing serverType rescales the server in place: it reboots, and the deploy waits until it runs again with the new type. Changing image replaces it. The resolved server exposes id, ipv4, ipv6, sshHost, status and the rest of the observed state; see the Server reference.

To pick a size or an image by what you need rather than by name, use the Cloud lookups. They read Better Stack’s catalog at plan time and fail when nothing matches:

alchemy.run.ts
const type = yield* BetterStack.Cloud.findServerType({ minVcpu: 2, family: "AM" }).pipe(
Effect.orDie,
);
const ubuntu = yield* BetterStack.Cloud.findImage({ distribution: "ubuntu", lts: true }).pipe(
Effect.orDie,
);
const sized = yield* BetterStack.Cloud.Server("sized", {
serverType: type.name!,
image: ubuntu.slug!,
});

findServerType returns the smallest type that meets the criteria and that your zone and quota can start now. See the Cloud lookups.

Register your public key as an SshKey and pass its slug:

alchemy.run.ts
const key = yield* BetterStack.Cloud.SshKey("laptop", {
publicKey:
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEF0uIiLF54lpavoiG7O95cChLJ80vbi0Nh08Kf3+G/a me@example.com",
});
const withKey = yield* BetterStack.Cloud.Server("api", {
serverType: "AM1",
image: "ubuntu-26-04",
sshKeys: [key.slug],
});

SSH keys belong to the team, so a key created in one zone exists in every zone. sshKeys changes in place through attach and detach actions, and only keys this prop listed before are ever detached.

Separately from your keys, Alchemy generates an ed25519 deploy key for every server it creates, registers it with the team, and installs it at first boot. The private half is the server’s privateKey: Redacted in plan output and attributes, but kept in the stack’s state, in clear text with Alchemy.localState(). Anyone who can read .alchemy/state can log in to the server as root; see State storage. A deploy returns only once the server is running and an SSH login as root with that key has succeeded, so the next resource can SSH in at once. That key is how Cloud.Ssh and Cloud.Service reach the box. Deleting the server detaches every key and then deletes the deploy key.

Better Stack refuses to delete a key that any server still has, including a server created with the key in sshKeys. So deleting an SshKey first detaches it from every server, then deletes it, retrying for up to 2 minutes.

One case can’t be fixed from the stack: a server destroyed outside it (in the console or through the API) keeps listing its keys until Better Stack purges its record, and it can’t be detached from. The delete then fails with the typed SshKeyHeld error, which names that server, and the key stays in the state. Run alchemy destroy again later: it succeeds once the record is gone. Both behaviours were observed against the real API on 2026-12-01.

The Ssh binding gives you exec and scp against a server, from Effects that run on your machine at deploy time, such as Actions:

src/inspect.ts
const ssh = yield* BetterStack.Cloud.Ssh(server);
const { stdout } = yield* ssh.exec("uname -a");
yield* ssh.scp("./assets.tar.gz", "/opt/app/assets.tar.gz");

exec returns { stdout, stderr, code } and fails with a typed SshError on a non-zero exit. Both use the system ssh and scp binaries, the deploy key and the root user unless you pass { user, privateKey }. A server you look up has no deploy key in your state.

userData runs on the server’s first boot: a #cloud-config document or a script starting with #!, at most 32 KiB.

alchemy.run.ts
const web = yield* BetterStack.Cloud.Server("web", {
serverType: "AM1",
image: "ubuntu-26-04",
userData: `#cloud-config
packages:
- nginx`,
});

Without userData, Alchemy sends its own bootstrap script, which preinstalls Node.js for Services. With it, your document is sent unchanged instead, because the Cloud API takes one document. Cloud.Service then installs Node.js over SSH when it is missing.

If you provision servers with your own tooling, bootstrap: false skips the deploy key, the bootstrap script and the SSH check:

alchemy.run.ts
const plain = yield* BetterStack.Cloud.Server("plain", {
serverType: "AM1",
image: "ubuntu-26-04",
sshKeys: [key.slug],
bootstrap: false,
});

Without the deploy key, Alchemy can’t reach the server: Cloud.Service can’t deploy to it, and Cloud.Ssh needs a privateKey from you. Changing bootstrap replaces the server.

Private networks and a firewall are props that take ids, and attach and detach in place:

alchemy.run.ts
const network = yield* BetterStack.Cloud.Network("private", {
ipPrefix: "10.0.0.0",
ipPrefixLength: 24,
});
const firewall = yield* BetterStack.Cloud.Firewall("public", {});
const attached = yield* BetterStack.Cloud.Server("attached", {
serverType: "AM1",
image: "ubuntu-26-04",
networkIds: [network.id],
firewallIds: [firewall.id],
});

A server has at most one firewall. A list prop you leave out is not managed: only items it listed before are ever detached. See Networking.

A PlacementGroup of type spread puts each server on a different physical host, so one hardware failure can’t take more than one of them down. compact packs them close together for the lowest latency. Both are best effort.

alchemy.run.ts
const spread = yield* BetterStack.Cloud.PlacementGroup("replicas", {
placementType: "spread",
});
const a = yield* BetterStack.Cloud.Server("a", {
serverType: "AM1",
image: "ubuntu-26-04",
placementGroupId: spread.id,
});
const b = yield* BetterStack.Cloud.Server("b", {
serverType: "AM1",
image: "ubuntu-26-04",
placementGroupId: spread.id,
});

A server joins a group when it is created; changing placementGroupId replaces the server. A group can only be deleted once it has no servers.

A ScheduledSnapshot snapshots a server’s disk hourly, daily, weekly or monthly:

alchemy.run.ts
yield* BetterStack.Cloud.ScheduledSnapshot("nightly", {
serverId: server.id,
frequency: "daily",
});

Snapshots are billed and stay after the schedule is deleted. Attached volumes are not included; see Volumes.

A Snapshot is one snapshot taken when it is created, such as before an upgrade, and kept until the stack deletes it:

alchemy.run.ts
yield* BetterStack.Cloud.Snapshot("before-upgrade", { serverId: server.id });

The server keeps running while its disk is copied, so the snapshot is crash-consistent: stop the server or flush its databases first when that matters. It bills by the size of the root disk, outlives its server, and is deleted with the stack. Restoring is an action, not a prop: call the SDK’s restoreSnapshot (a new server) or restoreServer (roll the server back). Server snapshots are tested against the offline mock only.

A ServerPool keeps booted servers of one type waiting, so a claim gets a running server in under a second. Warm servers are billed while they wait.

alchemy.run.ts
yield* BetterStack.Cloud.ServerPool("workers", {
image: "ubuntu-26-04",
serverType: "AM1",
minSize: 1,
maxSize: 2,
defaults: { sshKeys: [key.slug] },
});

The pool is tested against the offline mock only, because it bills; see Compatibility.

term is monthly by default. annual commits you to a full year of the server, and its public IPs and add-ons follow the same term. Leave it out unless you mean that. See Better Stack’s Cloud pricing.

An account’s first billable Cloud create is refused: the deploy fails with the typed PaymentRequired error, and its message carries Better Stack’s payment link. Paying through that link creates the server from the refused request, with the name, type, term, SSH keys and Alchemy’s ownership marker the deploy sent, but outside the stack’s state: the deploy that was refused recorded no server.

Whether the next deploy then finds that server by its ownership marker (see below) and takes it over, rather than buying a second one, is not verified yet. After paying, check the account’s server list before you deploy again, and delete any extra server by hand. See Live verification.

Every server this stack creates carries an alchemy entry in its metadata, which takes one of its 10 metadata slots; your own keys are left alone. A deploy that lost track of a server it created finds it by that marker instead of buying another, and alchemy nuke lists only Alchemy-created servers. See the Server reference.

Server.lookup references a server this stack doesn’t manage, by id or name. It is read at plan time and never created, changed or deleted:

alchemy.run.ts
const existing = BetterStack.Cloud.Server.lookup({ name: "web-1" });

An Otlp export sends the metrics of the team’s servers in a zone to your own OpenTelemetry receiver (OTLP over HTTP), at endpoint + /v1/metrics, every minute:

alchemy.run.ts
const token = yield* Config.Redacted("OTLP_TOKEN").pipe(Effect.orDie);
const metrics = yield* BetterStack.Cloud.Otlp("metrics", {
endpoint: "https://otlp.example.com", // metrics go to <endpoint>/v1/metrics
resourceTypes: ["server"],
headers: { Authorization: Redacted.make(`Bearer ${Redacted.value(token)}`) },
});

Everything but teamId and availabilityZone changes in place, including status (active or paused) and temporality (cumulative by default; Prometheus-based backends refuse delta). headers is write-only: the API answers only headerNames, so a changed header value is compared with what was last deployed. A failing receiver shows in lastError, and after 24 hours without a delivery the export pauses itself (pausedReason: "delivery_failed"). This is for server metrics leaving Better Stack; to send your own application’s telemetry into Better Stack, see Watching your services.

A Webhook receives a signed JSON event whenever a resource of the listed webhookTypes is created, updated or destroyed in its availability zone:

alchemy.run.ts
const hook = yield* BetterStack.Cloud.Webhook("events", {
url: "https://example.com/hooks/betterstack",
webhookTypes: ["server", "volume", "firewall"],
});
// Give the receiver hook.secret (Redacted) to verify each delivery's signature.

Verify deliveries with the secret attribute. The API cannot rotate it, so replace the webhook to get a new one. Respond with a 2xx within 10 seconds; after a delivery fails 10 attempts (about a day) Better Stack pauses the webhook, and with status: "active" in the config the next deploy that changes it resumes it.