Skip to content
betterstack-alchemyUnofficial

Cloud.Reference

Kind Reference data (lookup functions)Source src/Cloud/Reference.ts

Better Stack Cloud reference data: what you can order in a zone (server types and their availability, images, managed-database plans and engine versions, Kubernetes versions, load balancer and object cache types), your organization’s quota, and the addresses it holds.

Every function is a plain Effect over the SDK, so it works in a stack program at plan time (the providers bring the credentials) and in any Effect program given BetterStack.fromApiToken(...) and an HttpClient. Lists are read in full (every page). The zone defaults to the credentials’ (BETTERSTACK_AVAILABILITY_ZONE, or the profile’s); pass availabilityZone to ask about another one. Finders fail with the typed ReferenceNotFound when nothing matches.

Errors stay typed (ReferenceNotFound and the SDK’s tags) so plain Effect code can branch on them. A stack program may only fail with ConfigError, so inside Alchemy.Stack(...) end a plan-time read with Effect.orDie: a miss then stops the plan, as a lookup that finds nothing does.

const type = yield* BetterStack.Cloud.findServerType({ minVcpu: 2 });
const image = yield* BetterStack.Cloud.findImage({ distribution: "ubuntu", lts: true });
const postgres = yield* BetterStack.Cloud.latestPostgresVersion();
const findImage = (criteria: ImageCriteria)

The newest image of a distribution: the slug <distribution>-<version> with the highest version, optionally LTS releases only. Fails with ReferenceNotFound when the zone has none.

The newest Ubuntu LTS

const ubuntu = yield* BetterStack.Cloud.findImage({ distribution: "ubuntu", lts: true });
// ubuntu.slug === "ubuntu-26-04"

See also

const findServerType = (criteria: ServerTypeCriteria =

The smallest server type that meets the criteria: fewest vCPUs, then least memory, then smallest disk. Deprecated types are never picked, and by default neither is a type the zone or your quota can’t start now. Fails with ReferenceNotFound when no type qualifies.

The smallest shared type with 2 vCPUs and 4 GiB

const type = yield* BetterStack.Cloud.findServerType({ minVcpu: 2, minRamGb: 4, family: "AM" });
const server = yield* BetterStack.Cloud.Server("web", {
serverType: type.name!,
image: "ubuntu-26-04",
sshKeys: ["deploy"],
});

See also

const image = (slug: string, options?: ZoneOptions)

One image by slug. Fails with ReferenceNotFound when the zone has no such image.

Example

const image = yield* BetterStack.Cloud.image("ubuntu-26-04");

See also

const images = ( options?: ZoneOptions, ): Effect.Effect<Array<Cloud.Image>, Cloud.ListImageError, BetterStackOpContext>

Every image you can create a server from in the zone. Its slug (ubuntu-26-04, …) is what Cloud.Server’s image takes.

Example

const slugs = (yield* BetterStack.Cloud.images()).map((image) => image.slug);

See also

const ips = ( options?: IpOptions, ): Effect.Effect<Array<Cloud.Ip>, Cloud.ListIpError, BetterStackOpContext>

Every address your organization holds in the zone: the public and private addresses of its servers and the reserved IPs, with the server, network or reservation each belongs to.

Example

const publicV4 = (yield* BetterStack.Cloud.ips())
.filter((ip) => ip.visibility === "public" && ip.type === "ipv4")
.map((ip) => ip.ip);

See also

const quota = ( options?: ZoneOptions, ): Effect.Effect<Cloud.Quota, Cloud.GetQuotaError, BetterStackOpContext>

Your organization’s limits in the zone and how much of each it uses: servers and vCPUs per tier, memory, volumes, networks, IPs, snapshots, request rates, … Each entry is { default, limit, used } (used is null for a rate or a per-object limit). Check headroom before a deploy that creates billable resources.

Example

const { networks } = yield* BetterStack.Cloud.quota();
const left = (networks?.limit ?? 0) - (networks?.used ?? 0);

See also

const serverType = (name: string, options?: ZoneOptions)

One server type by name (AM1, AM4, …). Fails with ReferenceNotFound when the zone has no such type.

Example

const am1 = yield* BetterStack.Cloud.serverType("AM1");
// am1.vcpu, am1.ramGb, am1.storageGb, am1.availability

See also

const serverTypeAvailability = ( options?: ServerTypeAvailabilityOptions, ): Effect.Effect< Array<Cloud.ServerTypeAvailability>, Cloud.ListServerTypeAvailabilityError, BetterStackOpContext >

For every server type, whether your organization can start count more servers of it in the zone right now: available, over_quota (a limit of your organization stands in the way) or no_capacity (the zone can’t start them now). Check it before a deploy that creates servers.

Example

const availability = yield* BetterStack.Cloud.serverTypeAvailability({ count: 2 });
const canStart = availability.find((entry) => entry.name === "AM1")?.status === "available";

See also

const serverTypes = ( options?: ZoneOptions, ): Effect.Effect<Array<Cloud.ServerType>, Cloud.ListServerTypeError, BetterStackOpContext>

Every server type in the zone (deprecated ones included, with availability: "unavailable" and their replacement). Use it to show or filter what Cloud.Server’s serverType accepts; for “the smallest type that fits”, use findServerType.

Example

const types = yield* BetterStack.Cloud.serverTypes();
const dedicated = types.filter((type) => type.family === "AMD");

See also