0

Get Regions

Published Oct 17, 2025

List all regions on the platform with their current Machine capacity.

Script fly Verified

The script

Submitted by hugo697 Bun
Verified 390 days ago
1
//native
2
type Fly = {
3
  token: string;
4
};
5
/**
6
 * Get Regions
7
 * List all regions on the platform with their current Machine capacity.
8
 */
9
export async function main(
10
  auth: Fly,
11
  size: string | undefined,
12
  cpu_kind: string | undefined,
13
  memory_mb: string | undefined,
14
  cpus: string | undefined,
15
  gpus: string | undefined,
16
  gpu_kind: string | undefined,
17
) {
18
  const url = new URL(`https://api.machines.dev/v1/platform/regions`);
19
  for (const [k, v] of [
20
    ["size", size],
21
    ["cpu_kind", cpu_kind],
22
    ["memory_mb", memory_mb],
23
    ["cpus", cpus],
24
    ["gpus", gpus],
25
    ["gpu_kind", gpu_kind],
26
  ]) {
27
    if (v !== undefined && v !== "" && k !== undefined) {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      Authorization: "Bearer " + auth.token,
35
    },
36
    body: undefined,
37
  });
38
  if (!response.ok) {
39
    const text = await response.text();
40
    throw new Error(`${response.status} ${text}`);
41
  }
42
  return await response.json();
43
}
44