@nodetool-ai/compute 0.8.11 → 0.8.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,74 +1,127 @@
1
1
  /**
2
- * RunPod Pod management over the REST API (https://rest.runpod.io/v1).
2
+ * RunPod Pod management over the REST API v2 (https://api.runpod.io/v2).
3
3
  *
4
- * The serverless helpers in `runpod-api.ts` create templates/endpoints (the
5
- * job/queue model) and read the API key from `process.env`. This module manages
6
- * **persistent Pods** — the right shape for a long-lived NodeTool WebSocket
7
- * worker the server/CLI attaches to — and takes the API key **explicitly** so it
8
- * can be sourced from the per-user secret store (`getSecret`), never the
9
- * environment.
4
+ * This module manages **persistent Pods** — the right shape for a long-lived
5
+ * NodeTool WebSocket worker the server/CLI attaches to — and takes the API key
6
+ * **explicitly** so it can be sourced from the per-user secret store
7
+ * (`getSecret`), never the environment.
10
8
  *
11
- * REST surface used: POST /v1/pods, GET /v1/pods/{id}, POST /v1/pods/{id}/stop,
12
- * DELETE /v1/pods/{id}, GET /v1/pods.
9
+ * REST surface used: POST /v2/pods, GET /v2/pods/{id}, GET /v2/pods,
10
+ * POST /v2/pods/{id}/action (start / stop), DELETE /v2/pods/{id}.
13
11
  */
14
- /** Request body for POST /v1/pods (subset we use; see the REST reference). */
12
+ export declare const DEFAULT_RUNPOD_REST_BASE_URL = "https://api.runpod.io/v2";
13
+ /**
14
+ * Resolve the RunPod REST API base URL. Honors `RUNPOD_REST_BASE_URL` when set
15
+ * so future API base changes can be overridden without a release.
16
+ */
17
+ export declare function getRunpodRestBaseUrl(): string;
18
+ /** GPU configuration for POST /v2/pods (`CreateGpuConfig`). */
19
+ export interface RunpodCreateGpuConfig {
20
+ id: string;
21
+ count?: number;
22
+ /** CUDA versions the host driver must support, as `major.minor`. */
23
+ allowedCudaVersions?: string[];
24
+ minCudaVersion?: string;
25
+ minRamPerGpu?: number;
26
+ minVcpuCountPerGpu?: number;
27
+ }
28
+ /** CPU configuration for POST /v2/pods (`CreateCpuConfig`). */
29
+ export interface RunpodCreateCpuConfig {
30
+ /** CPU flavor identifier, e.g. `"cpu5c"`. */
31
+ id: string;
32
+ /** Number of vCPUs (minimum 2, power of two). */
33
+ vcpuCount: number;
34
+ }
35
+ /** Host-local persistent volume mount (GPU pods only). */
36
+ export interface RunpodPersistentMount {
37
+ /** Storage size in GB (minimum 10). */
38
+ size: number;
39
+ /** Mount path inside the container, e.g. `"/workspace"`. */
40
+ path: string;
41
+ }
42
+ /** Network volume mount attached to a pod. */
43
+ export interface RunpodNetworkMount {
44
+ volumeId: string;
45
+ path: string;
46
+ }
47
+ /** Storage mounts for POST /v2/pods (`Mounts`). */
48
+ export interface RunpodPodMounts {
49
+ persistent?: RunpodPersistentMount;
50
+ network?: RunpodNetworkMount[];
51
+ global?: {
52
+ volumeId: string;
53
+ path?: string;
54
+ }[];
55
+ }
56
+ /** Request body for POST /v2/pods (subset we use; see the v2 OpenAPI spec). */
15
57
  export interface RunpodPodSpec {
16
58
  name: string;
17
- imageName: string;
18
- computeType?: "CPU" | "GPU";
19
- vcpuCount?: number;
20
- cpuFlavorIds?: string[];
21
- cpuFlavorPriority?: "availability" | "custom";
22
- gpuTypeIds?: string[];
23
- gpuCount?: number;
24
- /** CUDA versions the host driver must support (GPU pods only). */
25
- allowedCudaVersions?: string[];
59
+ image?: string;
60
+ templateId?: string;
61
+ cloud?: "SECURE" | "COMMUNITY";
62
+ gpu?: RunpodCreateGpuConfig;
63
+ cpu?: RunpodCreateCpuConfig;
26
64
  ports?: string[];
27
65
  env?: Record<string, string>;
28
- containerDiskInGb?: number;
29
- volumeInGb?: number;
30
- volumeMountPath?: string;
31
- networkVolumeId?: string;
32
- dockerEntrypoint?: string[];
33
- dockerStartCmd?: string[];
34
- supportPublicIp?: boolean;
66
+ /** Ephemeral container disk in GB (minimum 1). */
67
+ disk?: number;
68
+ mounts?: RunpodPodMounts;
69
+ entrypoint?: string[];
70
+ cmd?: string[];
71
+ args?: string;
35
72
  globalNetworking?: boolean;
36
73
  dataCenterIds?: string[];
74
+ startSsh?: boolean;
75
+ startJupyter?: boolean;
37
76
  }
38
- /** Pod as returned by GET /v1/pods/{id} (fields we read). */
77
+ /** Lifecycle status of a pod in RunPod REST API v2. */
78
+ export type RunpodPodStatus = "PROVISIONING" | "STARTING" | "RUNNING" | "EXITED" | "ERROR" | "TERMINATED";
79
+ /** Live port mapping entry in `pod.runtime.ports`. */
80
+ export interface RunpodRuntimePort {
81
+ private: number;
82
+ public?: number | null;
83
+ type: string;
84
+ ip?: string | null;
85
+ }
86
+ /** Live runtime block returned by GET /v2/pods/{id} while RUNNING. */
87
+ export interface RunpodPodRuntime {
88
+ uptime?: number;
89
+ ports?: RunpodRuntimePort[];
90
+ [k: string]: unknown;
91
+ }
92
+ /** Pod as returned by GET /v2/pods/{id} (fields we read). */
39
93
  export interface RunpodPod {
40
94
  id: string;
41
95
  name?: string;
42
- desiredStatus?: "RUNNING" | "READYT" | "EXITED" | "TERMINATED" | string;
96
+ status?: RunpodPodStatus | string;
43
97
  image?: string;
44
- /** Public IPv4; empty/null while the Pod is initializing. */
45
- publicIp?: string | null;
46
- /** Internal→external port map, e.g. {"7777": 41021}. */
47
- portMappings?: Record<string, number> | null;
98
+ /** Live metrics and port mappings; null when not RUNNING or in list responses. */
99
+ runtime?: RunpodPodRuntime | null;
48
100
  ports?: string[];
49
- /** Hourly cost (USD) RunPod bills for this pod's compute. */
50
- costPerHr?: number;
101
+ /** Hourly compute rate (USD) RunPod bills for this pod. */
102
+ cost?: number;
51
103
  [k: string]: unknown;
52
104
  }
53
- /** Create (and deploy) a Pod. POST /v1/pods. */
105
+ /** Create (and deploy) a Pod. POST /v2/pods. */
54
106
  export declare function createPod(apiKey: string, spec: RunpodPodSpec): Promise<RunpodPod>;
55
- /** Get a Pod by id. GET /v1/pods/{id}. */
107
+ /** Get a Pod by id. GET /v2/pods/{id}. */
56
108
  export declare function getPod(apiKey: string, id: string): Promise<RunpodPod>;
57
- /** List Pods. GET /v1/pods. */
109
+ /** List Pods. GET /v2/pods (follows cursor pagination when present). */
58
110
  export declare function listPods(apiKey: string): Promise<RunpodPod[]>;
59
- /** Stop a Pod (releases compute, keeps the volume). POST /v1/pods/{id}/stop. */
111
+ /** Stop a Pod (releases compute, keeps the volume). POST /v2/pods/{id}/action. */
60
112
  export declare function stopPod(apiKey: string, id: string): Promise<void>;
61
113
  /**
62
114
  * Resume a stopped Pod (re-allocates compute, keeps the volume).
63
- * POST /v1/pods/{id}/start. May fail or return zero GPUs if RunPod capacity has
64
- * changed since the Pod was stopped.
115
+ * POST /v2/pods/{id}/action. May fail if RunPod capacity has changed since the
116
+ * Pod was stopped.
65
117
  */
66
118
  export declare function startPod(apiKey: string, id: string): Promise<void>;
67
- /** Terminate a Pod (deletes it). DELETE /v1/pods/{id}. */
119
+ /** Terminate a Pod (deletes it). DELETE /v2/pods/{id}. */
68
120
  export declare function deletePod(apiKey: string, id: string): Promise<void>;
69
121
  /**
70
122
  * Direct TCP WebSocket URL for an exposed `/tcp` port, or null while the Pod
71
- * lacks a public IP / port mapping. Preferred for large frames (no HTTP proxy).
123
+ * lacks a public IP / port mapping in `pod.runtime.ports`. Preferred for large
124
+ * frames (no HTTP proxy).
72
125
  */
73
126
  export declare function podDirectWsUrl(pod: RunpodPod, internalPort: number): string | null;
74
127
  /**
@@ -76,51 +129,64 @@ export declare function podDirectWsUrl(pod: RunpodPod, internalPort: number): st
76
129
  * by RunPod; subject to the proxy's size/timeout limits (fine for small frames).
77
130
  */
78
131
  export declare function podProxyWsUrl(podId: string, internalPort: number): string;
79
- /**
80
- * Default GPUs requested for a GPU pod. RunPod's REST API does not document a
81
- * default for `gpuCount`, so we set it explicitly to avoid a "running" pod that
82
- * was allocated zero GPUs. One GPU is the right default for a single worker.
83
- */
132
+ /** Default GPUs requested for a GPU pod. */
84
133
  export declare const DEFAULT_GPU_COUNT = 1;
85
- /**
86
- * Default vCPUs for a GPU pod. RunPod pairs vCPUs with the GPU on GPU pods, but
87
- * leaving `vcpuCount` undefined relies on undocumented defaults; pin a sane
88
- * value so the worker has CPU headroom for I/O and the bridge process.
89
- */
90
- export declare const DEFAULT_GPU_VCPU_COUNT = 8;
91
- /** Default vCPUs for a CPU pod. */
134
+ /** Default CPU flavor identifier for a CPU pod (`GET /v2/catalog/cpus`). */
135
+ export declare const DEFAULT_CPU_FLAVOR_ID = "cpu5c";
136
+ /** Default vCPUs for a CPU pod (power of two, minimum 2). */
92
137
  export declare const DEFAULT_CPU_VCPU_COUNT = 4;
93
138
  /**
94
- * CUDA versions a GPU worker host must support. The worker image installs
95
- * PyPI's Linux torch, which is a CUDA 13.0 build and needs an NVIDIA driver
96
- * of 580 or newer. Without the filter RunPod may place the pod on an older
97
- * driver, where torch cannot use the GPU. RunPod's API lists 13.0 as its
98
- * newest value; add newer ones here as RunPod adds them.
139
+ * Minimum CUDA version a GPU worker host must support. The worker image
140
+ * installs PyPI's Linux torch, which is a CUDA 13.0 build and needs an NVIDIA
141
+ * driver of 580 or newer. Using `minCudaVersion` (rather than exact-match
142
+ * `allowedCudaVersions`) accepts 13.0 and any newer host CUDA version.
99
143
  */
144
+ export declare const WORKER_MIN_CUDA_VERSION = "13.0";
145
+ /** @deprecated Use {@link WORKER_MIN_CUDA_VERSION} with `minCudaVersion`. */
100
146
  export declare const WORKER_CUDA_VERSIONS: readonly string[];
147
+ /** Matches RunPod's capacity-exhausted error responses across API versions. */
148
+ export declare function isRunpodCapacityError(err: unknown): boolean;
101
149
  export interface DeployWorkerPodOptions {
102
150
  /** Pod name. */
103
151
  name: string;
104
152
  /** Registry image RunPod pulls (must be reachable by RunPod). */
105
153
  image: string;
154
+ /** RunPod template. Replaces the image, ports and default disks. */
155
+ templateId?: string;
106
156
  /** Shared-secret passed as NODETOOL_WORKER_TOKEN (gates the ws handshake). */
107
157
  workerToken?: string;
108
158
  /** Internal port the worker serves on. Default 7777. */
109
159
  internalPort?: number;
110
160
  /** Expose via RunPod HTTP proxy ("http" → wss proxy) or direct TCP. */
111
161
  exposure?: "http" | "tcp";
162
+ /**
163
+ * RunPod cloud tier. When omitted, tries `"SECURE"` first and falls back to
164
+ * `"COMMUNITY"` if Secure Cloud reports no available capacity.
165
+ */
166
+ cloud?: "SECURE" | "COMMUNITY";
112
167
  computeType?: "CPU" | "GPU";
168
+ /** CPU flavor identifier (CPU pods only). Defaults to {@link DEFAULT_CPU_FLAVOR_ID}. */
169
+ cpuFlavorId?: string;
170
+ /** vCPU count (exact on CPU pods; converted to minVcpuCountPerGpu on GPU pods). */
113
171
  vcpuCount?: number;
172
+ /** Single GPU type identifier (GPU pods only). */
173
+ gpuTypeId?: string;
174
+ /** @deprecated Prefer `gpuTypeId`; the first entry is used in API v2. */
114
175
  gpuTypeIds?: string[];
115
176
  /** GPUs per pod (GPU pods only). Defaults to {@link DEFAULT_GPU_COUNT}. */
116
177
  gpuCount?: number;
117
178
  /**
118
- * CUDA versions the host must support (GPU pods only). Defaults to
119
- * {@link WORKER_CUDA_VERSIONS}.
179
+ * Minimum CUDA version the host must support (GPU pods only). Defaults to
180
+ * {@link WORKER_MIN_CUDA_VERSION} unless `allowedCudaVersions` is supplied.
181
+ */
182
+ minCudaVersion?: string;
183
+ /**
184
+ * Exact CUDA versions the host must support (GPU pods only). Pass `[]` to
185
+ * disable the default {@link WORKER_MIN_CUDA_VERSION} floor.
120
186
  */
121
187
  allowedCudaVersions?: readonly string[];
122
188
  containerDiskInGb?: number;
123
- /** Persistent volume size in GB (mounted at `volumeMountPath`). */
189
+ /** Persistent volume size in GB (GPU pods only; mounted at `volumeMountPath`). */
124
190
  volumeInGb?: number;
125
191
  /** Mount path for the persistent volume. Defaults to "/workspace". */
126
192
  volumeMountPath?: string;
@@ -146,14 +212,15 @@ export interface DeployedWorkerPod {
146
212
  }
147
213
  /**
148
214
  * Deploy a NodeTool worker image as a persistent RunPod Pod and wait until it is
149
- * RUNNING with a resolvable WebSocket endpoint. Does NOT read process.env — pass
150
- * `apiKey` (from the secret store) and `workerToken` explicitly.
215
+ * RUNNING with a resolvable WebSocket endpoint. Does NOT read process.env for
216
+ * credentials — pass `apiKey` (from the secret store) and `workerToken`
217
+ * explicitly.
151
218
  *
152
219
  * Reaching RUNNING + having an endpoint does not guarantee the worker process
153
220
  * has finished loading nodes; the caller should connect with retry.
154
221
  */
155
222
  export declare function deployWorkerPod(apiKey: string, opts: DeployWorkerPodOptions): Promise<DeployedWorkerPod>;
156
- /** Poll GET /v1/pods/{id} until RUNNING with a resolvable endpoint. */
223
+ /** Poll GET /v2/pods/{id} until RUNNING with a resolvable endpoint. */
157
224
  export declare function waitForPodEndpoint(apiKey: string, id: string, opts: {
158
225
  internalPort: number;
159
226
  exposure: "http" | "tcp";
@@ -1 +1 @@
1
- {"version":3,"file":"runpod-rest.d.ts","sourceRoot":"","sources":["../../src/providers/runpod-rest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAQH,8EAA8E;AAC9E,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;IAE5B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,iBAAiB,CAAC,EAAE,cAAc,GAAG,QAAQ,CAAC;IAE9C,UAAU,CAAC,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kEAAkE;IAClE,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE/B,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,eAAe,CAAC,EAAE,MAA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ChD,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,SAAS,CAAC;CAChB;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,iBAAiB,CAAC,CAiG5B;AAED,uEAAuE;AACvE,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,IAAI,EAAE;IACJ,YAAY,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,OAAO,CAAC;IAAE,GAAG,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CA0B5C"}
@@ -1,22 +1,28 @@
1
1
  /**
2
- * RunPod Pod management over the REST API (https://rest.runpod.io/v1).
2
+ * RunPod Pod management over the REST API v2 (https://api.runpod.io/v2).
3
3
  *
4
- * The serverless helpers in `runpod-api.ts` create templates/endpoints (the
5
- * job/queue model) and read the API key from `process.env`. This module manages
6
- * **persistent Pods** — the right shape for a long-lived NodeTool WebSocket
7
- * worker the server/CLI attaches to — and takes the API key **explicitly** so it
8
- * can be sourced from the per-user secret store (`getSecret`), never the
9
- * environment.
4
+ * This module manages **persistent Pods** — the right shape for a long-lived
5
+ * NodeTool WebSocket worker the server/CLI attaches to — and takes the API key
6
+ * **explicitly** so it can be sourced from the per-user secret store
7
+ * (`getSecret`), never the environment.
10
8
  *
11
- * REST surface used: POST /v1/pods, GET /v1/pods/{id}, POST /v1/pods/{id}/stop,
12
- * DELETE /v1/pods/{id}, GET /v1/pods.
9
+ * REST surface used: POST /v2/pods, GET /v2/pods/{id}, GET /v2/pods,
10
+ * POST /v2/pods/{id}/action (start / stop), DELETE /v2/pods/{id}.
13
11
  */
14
- const RUNPOD_REST_BASE_URL = "https://rest.runpod.io/v1";
12
+ export const DEFAULT_RUNPOD_REST_BASE_URL = "https://api.runpod.io/v2";
15
13
  /**
16
- * Call the RunPod REST API with an explicitly-supplied key.
14
+ * Resolve the RunPod REST API base URL. Honors `RUNPOD_REST_BASE_URL` when set
15
+ * so future API base changes can be overridden without a release.
16
+ */
17
+ export function getRunpodRestBaseUrl() {
18
+ const configured = process.env.RUNPOD_REST_BASE_URL?.trim();
19
+ return (configured || DEFAULT_RUNPOD_REST_BASE_URL).replace(/\/+$/, "");
20
+ }
21
+ /**
22
+ * Call the RunPod REST API v2 with an explicitly-supplied key.
17
23
  *
18
24
  * @param apiKey RunPod API key (from the per-user secret store).
19
- * @param endpoint Path under /v1, e.g. "pods" or "pods/<id>".
25
+ * @param endpoint Path under /v2, e.g. "pods" or "pods/<id>".
20
26
  */
21
27
  async function runpodRest(apiKey, endpoint, method = "GET", data) {
22
28
  if (!apiKey)
@@ -30,9 +36,9 @@ async function runpodRest(apiKey, endpoint, method = "GET", data) {
30
36
  },
31
37
  signal: AbortSignal.timeout(60_000)
32
38
  };
33
- if (data && method === "POST")
39
+ if (data !== undefined && method === "POST")
34
40
  init.body = JSON.stringify(data);
35
- const response = await fetch(`${RUNPOD_REST_BASE_URL}/${endpoint}`, init);
41
+ const response = await fetch(`${getRunpodRestBaseUrl()}/${endpoint}`, init);
36
42
  if (!response.ok) {
37
43
  const body = await response.text().catch(() => "");
38
44
  throw new Error(`RunPod REST ${method} /${endpoint} failed (${response.status}): ${body}`);
@@ -45,38 +51,59 @@ async function runpodRest(apiKey, endpoint, method = "GET", data) {
45
51
  // ---------------------------------------------------------------------------
46
52
  // Pod operations
47
53
  // ---------------------------------------------------------------------------
48
- /** Create (and deploy) a Pod. POST /v1/pods. */
54
+ /** Create (and deploy) a Pod. POST /v2/pods. */
49
55
  export async function createPod(apiKey, spec) {
50
56
  const pod = (await runpodRest(apiKey, "pods", "POST", spec));
51
57
  if (!pod?.id)
52
58
  throw new Error("RunPod createPod returned no pod id");
53
59
  return pod;
54
60
  }
55
- /** Get a Pod by id. GET /v1/pods/{id}. */
61
+ /** Get a Pod by id. GET /v2/pods/{id}. */
56
62
  export async function getPod(apiKey, id) {
57
63
  return (await runpodRest(apiKey, `pods/${id}`));
58
64
  }
59
- /** List Pods. GET /v1/pods. */
65
+ /** List Pods. GET /v2/pods (follows cursor pagination when present). */
60
66
  export async function listPods(apiKey) {
61
- const res = await runpodRest(apiKey, "pods");
62
- if (Array.isArray(res))
63
- return res;
64
- const arr = res.pods;
65
- return Array.isArray(arr) ? arr : [];
67
+ const pods = [];
68
+ let cursor = null;
69
+ const seenCursors = new Set();
70
+ for (let page = 0; page < 100; page++) {
71
+ const endpoint = cursor
72
+ ? `pods?cursor=${encodeURIComponent(cursor)}`
73
+ : "pods";
74
+ const res = await runpodRest(apiKey, endpoint);
75
+ if (Array.isArray(res)) {
76
+ pods.push(...res);
77
+ break;
78
+ }
79
+ if (Array.isArray(res.pods)) {
80
+ pods.push(...res.pods);
81
+ }
82
+ const pagination = res.pagination;
83
+ if (!pagination?.hasNextPage ||
84
+ typeof pagination.nextCursor !== "string" ||
85
+ !pagination.nextCursor ||
86
+ seenCursors.has(pagination.nextCursor)) {
87
+ break;
88
+ }
89
+ seenCursors.add(pagination.nextCursor);
90
+ cursor = pagination.nextCursor;
91
+ }
92
+ return pods;
66
93
  }
67
- /** Stop a Pod (releases compute, keeps the volume). POST /v1/pods/{id}/stop. */
94
+ /** Stop a Pod (releases compute, keeps the volume). POST /v2/pods/{id}/action. */
68
95
  export async function stopPod(apiKey, id) {
69
- await runpodRest(apiKey, `pods/${id}/stop`, "POST");
96
+ await runpodRest(apiKey, `pods/${id}/action`, "POST", { action: "stop" });
70
97
  }
71
98
  /**
72
99
  * Resume a stopped Pod (re-allocates compute, keeps the volume).
73
- * POST /v1/pods/{id}/start. May fail or return zero GPUs if RunPod capacity has
74
- * changed since the Pod was stopped.
100
+ * POST /v2/pods/{id}/action. May fail if RunPod capacity has changed since the
101
+ * Pod was stopped.
75
102
  */
76
103
  export async function startPod(apiKey, id) {
77
- await runpodRest(apiKey, `pods/${id}/start`, "POST");
104
+ await runpodRest(apiKey, `pods/${id}/action`, "POST", { action: "start" });
78
105
  }
79
- /** Terminate a Pod (deletes it). DELETE /v1/pods/{id}. */
106
+ /** Terminate a Pod (deletes it). DELETE /v2/pods/{id}. */
80
107
  export async function deletePod(apiKey, id) {
81
108
  await runpodRest(apiKey, `pods/${id}`, "DELETE");
82
109
  }
@@ -85,13 +112,14 @@ export async function deletePod(apiKey, id) {
85
112
  // ---------------------------------------------------------------------------
86
113
  /**
87
114
  * Direct TCP WebSocket URL for an exposed `/tcp` port, or null while the Pod
88
- * lacks a public IP / port mapping. Preferred for large frames (no HTTP proxy).
115
+ * lacks a public IP / port mapping in `pod.runtime.ports`. Preferred for large
116
+ * frames (no HTTP proxy).
89
117
  */
90
118
  export function podDirectWsUrl(pod, internalPort) {
91
- const ext = pod.portMappings?.[String(internalPort)];
92
- if (!pod.publicIp || !ext)
119
+ const port = pod.runtime?.ports?.find((p) => p.private === internalPort);
120
+ if (!port?.ip || !port.public)
93
121
  return null;
94
- return `ws://${pod.publicIp}:${ext}`;
122
+ return `ws://${port.ip}:${port.public}`;
95
123
  }
96
124
  /**
97
125
  * RunPod HTTP-proxy WebSocket URL for an exposed `/http` port. TLS-terminated
@@ -103,32 +131,30 @@ export function podProxyWsUrl(podId, internalPort) {
103
131
  // ---------------------------------------------------------------------------
104
132
  // High-level worker deploy
105
133
  // ---------------------------------------------------------------------------
106
- /**
107
- * Default GPUs requested for a GPU pod. RunPod's REST API does not document a
108
- * default for `gpuCount`, so we set it explicitly to avoid a "running" pod that
109
- * was allocated zero GPUs. One GPU is the right default for a single worker.
110
- */
134
+ /** Default GPUs requested for a GPU pod. */
111
135
  export const DEFAULT_GPU_COUNT = 1;
112
- /**
113
- * Default vCPUs for a GPU pod. RunPod pairs vCPUs with the GPU on GPU pods, but
114
- * leaving `vcpuCount` undefined relies on undocumented defaults; pin a sane
115
- * value so the worker has CPU headroom for I/O and the bridge process.
116
- */
117
- export const DEFAULT_GPU_VCPU_COUNT = 8;
118
- /** Default vCPUs for a CPU pod. */
136
+ /** Default CPU flavor identifier for a CPU pod (`GET /v2/catalog/cpus`). */
137
+ export const DEFAULT_CPU_FLAVOR_ID = "cpu5c";
138
+ /** Default vCPUs for a CPU pod (power of two, minimum 2). */
119
139
  export const DEFAULT_CPU_VCPU_COUNT = 4;
120
140
  /**
121
- * CUDA versions a GPU worker host must support. The worker image installs
122
- * PyPI's Linux torch, which is a CUDA 13.0 build and needs an NVIDIA driver
123
- * of 580 or newer. Without the filter RunPod may place the pod on an older
124
- * driver, where torch cannot use the GPU. RunPod's API lists 13.0 as its
125
- * newest value; add newer ones here as RunPod adds them.
141
+ * Minimum CUDA version a GPU worker host must support. The worker image
142
+ * installs PyPI's Linux torch, which is a CUDA 13.0 build and needs an NVIDIA
143
+ * driver of 580 or newer. Using `minCudaVersion` (rather than exact-match
144
+ * `allowedCudaVersions`) accepts 13.0 and any newer host CUDA version.
126
145
  */
127
- export const WORKER_CUDA_VERSIONS = ["13.0"];
146
+ export const WORKER_MIN_CUDA_VERSION = "13.0";
147
+ /** @deprecated Use {@link WORKER_MIN_CUDA_VERSION} with `minCudaVersion`. */
148
+ export const WORKER_CUDA_VERSIONS = [WORKER_MIN_CUDA_VERSION];
149
+ /** Matches RunPod's capacity-exhausted error responses across API versions. */
150
+ export function isRunpodCapacityError(err) {
151
+ return err instanceof Error && /no (?:longer any )?instances/i.test(err.message);
152
+ }
128
153
  /**
129
154
  * Deploy a NodeTool worker image as a persistent RunPod Pod and wait until it is
130
- * RUNNING with a resolvable WebSocket endpoint. Does NOT read process.env — pass
131
- * `apiKey` (from the secret store) and `workerToken` explicitly.
155
+ * RUNNING with a resolvable WebSocket endpoint. Does NOT read process.env for
156
+ * credentials — pass `apiKey` (from the secret store) and `workerToken`
157
+ * explicitly.
132
158
  *
133
159
  * Reaching RUNNING + having an endpoint does not guarantee the worker process
134
160
  * has finished loading nodes; the caller should connect with retry.
@@ -145,30 +171,79 @@ export async function deployWorkerPod(apiKey, opts) {
145
171
  const isGpu = opts.computeType === "GPU";
146
172
  const spec = {
147
173
  name: opts.name,
148
- imageName: opts.image,
149
- computeType: opts.computeType ?? "CPU",
150
- // Always pin vcpuCount explicitly rather than relying on RunPod defaults.
151
- vcpuCount: opts.vcpuCount ??
152
- (isGpu ? DEFAULT_GPU_VCPU_COUNT : DEFAULT_CPU_VCPU_COUNT),
153
- gpuTypeIds: opts.gpuTypeIds,
154
- ports: sshKey
155
- ? [`${internalPort}/${exposure}`, "22/tcp"]
156
- : [`${internalPort}/${exposure}`],
157
- env,
158
- containerDiskInGb: opts.containerDiskInGb ?? 20
174
+ ...(opts.templateId ? { templateId: opts.templateId } : { image: opts.image }),
175
+ env
159
176
  };
160
- // GPU pods must request an explicit gpuCount; without it RunPod may allocate
161
- // zero GPUs while still reporting the pod as running.
177
+ if (opts.cloud) {
178
+ spec.cloud = opts.cloud;
179
+ }
162
180
  if (isGpu) {
163
- spec.gpuCount = opts.gpuCount ?? DEFAULT_GPU_COUNT;
164
- spec.allowedCudaVersions = [...(opts.allowedCudaVersions ?? WORKER_CUDA_VERSIONS)];
181
+ const gpuId = opts.gpuTypeId ?? opts.gpuTypeIds?.[0];
182
+ if (!gpuId) {
183
+ throw new Error("RunPod GPU pod requires a GPU type id");
184
+ }
185
+ const gpuCount = opts.gpuCount ?? DEFAULT_GPU_COUNT;
186
+ const gpu = {
187
+ id: gpuId,
188
+ count: gpuCount
189
+ };
190
+ if (opts.vcpuCount !== undefined) {
191
+ gpu.minVcpuCountPerGpu = Math.max(1, Math.floor(opts.vcpuCount / gpuCount));
192
+ }
193
+ if (opts.minCudaVersion) {
194
+ gpu.minCudaVersion = opts.minCudaVersion;
195
+ }
196
+ else if (opts.allowedCudaVersions !== undefined) {
197
+ if (opts.allowedCudaVersions.length > 0) {
198
+ gpu.allowedCudaVersions = [...opts.allowedCudaVersions];
199
+ }
200
+ }
201
+ else {
202
+ gpu.minCudaVersion = WORKER_MIN_CUDA_VERSION;
203
+ }
204
+ spec.gpu = gpu;
205
+ }
206
+ else {
207
+ spec.cpu = {
208
+ id: opts.cpuFlavorId ?? DEFAULT_CPU_FLAVOR_ID,
209
+ vcpuCount: opts.vcpuCount ?? DEFAULT_CPU_VCPU_COUNT
210
+ };
211
+ }
212
+ // A template owns its ports and container disk, unless the caller overrides.
213
+ if (!opts.templateId) {
214
+ spec.ports = sshKey
215
+ ? [`${internalPort}/${exposure}`, "22/tcp"]
216
+ : [`${internalPort}/${exposure}`];
217
+ }
218
+ if (!opts.templateId || opts.containerDiskInGb) {
219
+ spec.disk = opts.containerDiskInGb ?? 20;
165
220
  }
166
221
  // Persistent volume — survives stop/resume, holds the HF model cache.
167
- if (opts.volumeInGb) {
168
- spec.volumeInGb = opts.volumeInGb;
169
- spec.volumeMountPath = opts.volumeMountPath ?? "/workspace";
222
+ // RunPod API v2 disallows `mounts.persistent` on CPU pods and requires both
223
+ // `size` and `path` whenever `persistent` is set.
224
+ if (isGpu && opts.volumeInGb) {
225
+ spec.mounts = {
226
+ persistent: {
227
+ size: opts.volumeInGb,
228
+ path: opts.volumeMountPath ?? "/workspace"
229
+ }
230
+ };
231
+ }
232
+ let created;
233
+ try {
234
+ created = await createPod(apiKey, spec);
235
+ }
236
+ catch (err) {
237
+ // API v2 removed `cloudType: "ALL"` and defaults to `"SECURE"` only.
238
+ // When the caller did not pin a cloud tier and Secure Cloud has no
239
+ // capacity, retry once on Community Cloud.
240
+ if (!opts.cloud && isRunpodCapacityError(err)) {
241
+ created = await createPod(apiKey, { ...spec, cloud: "COMMUNITY" });
242
+ }
243
+ else {
244
+ throw err;
245
+ }
170
246
  }
171
- const created = await createPod(apiKey, spec);
172
247
  try {
173
248
  const { pod, wsUrl } = await waitForPodEndpoint(apiKey, created.id, {
174
249
  internalPort,
@@ -185,7 +260,7 @@ export async function deployWorkerPod(apiKey, opts) {
185
260
  throw err;
186
261
  }
187
262
  }
188
- /** Poll GET /v1/pods/{id} until RUNNING with a resolvable endpoint. */
263
+ /** Poll GET /v2/pods/{id} until RUNNING with a resolvable endpoint. */
189
264
  export async function waitForPodEndpoint(apiKey, id, opts) {
190
265
  const deadline = Date.now() + (opts.timeoutMs ?? 240_000);
191
266
  const intervalMs = opts.intervalMs ?? 5_000;
@@ -193,10 +268,12 @@ export async function waitForPodEndpoint(apiKey, id, opts) {
193
268
  while (Date.now() < deadline) {
194
269
  const pod = await getPod(apiKey, id);
195
270
  last = pod;
196
- if (pod.desiredStatus === "TERMINATED" || pod.desiredStatus === "EXITED") {
197
- throw new Error(`Pod ${id} reached terminal status ${pod.desiredStatus}`);
271
+ if (pod.status === "TERMINATED" ||
272
+ pod.status === "EXITED" ||
273
+ pod.status === "ERROR") {
274
+ throw new Error(`Pod ${id} reached terminal status ${pod.status}`);
198
275
  }
199
- if (pod.desiredStatus === "RUNNING" || pod.desiredStatus === "READYT") {
276
+ if (pod.status === "RUNNING") {
200
277
  if (opts.exposure === "http") {
201
278
  return { pod, wsUrl: podProxyWsUrl(id, opts.internalPort) };
202
279
  }
@@ -206,6 +283,6 @@ export async function waitForPodEndpoint(apiKey, id, opts) {
206
283
  }
207
284
  await new Promise((r) => setTimeout(r, intervalMs));
208
285
  }
209
- throw new Error(`Pod ${id} did not become reachable within the timeout (last status: ${last?.desiredStatus ?? "unknown"})`);
286
+ throw new Error(`Pod ${id} did not become reachable within the timeout (last status: ${last?.status ?? "unknown"})`);
210
287
  }
211
288
  //# sourceMappingURL=runpod-rest.js.map