0

Get Placements

by
Published Oct 17, 2025

Simulates placing the specified number of machines into regions, depending on available capacity and limits.

Script fly Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Fly = {
3
  token: string;
4
};
5
/**
6
 * Get Placements
7
 * Simulates placing the specified number of machines into regions, depending on available capacity and limits.
8
 */
9
export async function main(
10
  auth: Fly,
11
  body: {
12
    compute?: {
13
      cpu_kind?: string;
14
      cpus?: number;
15
      gpu_kind?: string;
16
      gpus?: number;
17
      host_dedication_id?: string;
18
      kernel_args?: string[];
19
      memory_mb?: number;
20
    };
21
    count?: number;
22
    org_slug: string;
23
    region?: string;
24
    volume_name?: string;
25
    volume_size_bytes?: number;
26
    weights?: {};
27
  },
28
) {
29
  const url = new URL(`https://api.machines.dev/v1/platform/placements`);
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45