0

Create Volume

by
Published Oct 17, 2025

Create a volume for a specific app using the details provided in the request body.

Script fly Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Fly = {
3
  token: string;
4
};
5
/**
6
 * Create Volume
7
 * Create a volume for a specific app using the details provided in the request body.
8

9
 */
10
export async function main(
11
  auth: Fly,
12
  app_name: string,
13
  body: {
14
    compute?: {
15
      cpu_kind?: string;
16
      cpus?: number;
17
      gpu_kind?: string;
18
      gpus?: number;
19
      host_dedication_id?: string;
20
      kernel_args?: string[];
21
      memory_mb?: number;
22
    };
23
    compute_image?: string;
24
    encrypted?: false | true;
25
    fstype?: string;
26
    name?: string;
27
    region?: string;
28
    require_unique_zone?: false | true;
29
    size_gb?: number;
30
    snapshot_id?: string;
31
    snapshot_retention?: number;
32
    source_volume_id?: string;
33
    unique_zone_app_wide?: false | true;
34
  },
35
) {
36
  const url = new URL(`https://api.machines.dev/v1/apps/${app_name}/volumes`);
37

38
  const response = await fetch(url, {
39
    method: "POST",
40
    headers: {
41
      "Content-Type": "application/json",
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: JSON.stringify(body),
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52