runpod-sdk 1.2.0-beta.1 → 2.0.0

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RunPod, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,154 +1,61 @@
1
- # RunPod JavaScript SDK
1
+ # runpod-sdk
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/runpod-sdk.svg)](https://www.npmjs.com/package/runpod-sdk)
4
4
 
5
- Official JavaScript SDK for [RunPod](https://runpod.io) - GPU cloud computing platform
5
+ JavaScript and TypeScript SDK for Runpod. It has two parts:
6
6
 
7
- ## 🚀 Features
7
+ - The Serverless job client: `run`, `runSync`, `status`, `stream`, `cancel`, `health`, and `purgeQueue` on an endpoint.
8
+ - The typed REST v2 client from [`@runpod/typescript-api-sdk`](https://www.npmjs.com/package/@runpod/typescript-api-sdk), for pods, Serverless endpoints, templates, network volumes, and more.
8
9
 
9
- - **🖥️ Pod Management** - Create, control, and monitor GPU pods
10
- - **⚡ Serverless Endpoints** - Run inference on serverless GPU endpoints
11
- - **📝 Full TypeScript Support** - Auto-generated types for better DX
12
- - **🔄 Automatic Retries** - Built-in error handling and retry logic
13
- - **🌍 Environment Switching** - Easy prod/dev environment management
10
+ Supports **Node.js 20+**, ESM, and CommonJS. In CommonJS, the default export is on `.default`: `const runpodSdk = require("runpod-sdk").default`.
14
11
 
15
- ## 📦 Installation
12
+ <!-- runpod-agent-setup:start -->
13
+ **For AI agents:** setup instructions for the Runpod skills and MCP server are at https://agents.runpod.io/
14
+ <!-- runpod-agent-setup:end -->
16
15
 
17
- ```bash
18
- npm install runpod-sdk
19
- ```
20
-
21
- ## 🎯 Quick Start
22
-
23
- ```typescript
24
- import RunPod from 'runpod-sdk'
25
-
26
- const runpod = new RunPod('your-api-key')
16
+ # Installation
27
17
 
28
- // 🆕 Create and manage GPU pods
29
- const pod = await runpod.pods.createOnDemand({
30
- name: 'my-gpu-pod',
31
- imageName: 'runpod/pytorch:latest',
32
- gpuTypeId: 'NVIDIA_A100',
33
- gpuCount: 1
34
- })
35
-
36
- // ⚡ Use serverless endpoints
37
- const endpoint = runpod.endpoint('your-endpoint-id')
38
- const result = await endpoint.runSync({
39
- input: { prompt: "Hello AI!" }
40
- })
41
- ```
18
+ `npm install runpod-sdk`
42
19
 
43
- ## 🖥️ Pod Management
20
+ Or for Yarn:
44
21
 
45
- Create and manage GPU pods programmatically:
22
+ `yarn add runpod-sdk`
46
23
 
47
- ### Creating Pods
24
+ # Example Usage
48
25
 
49
- ```typescript
50
- import runpod, { GpuTypes } from 'runpod-sdk'
26
+ ```js
27
+ const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env;
28
+ import runpodSdk from "runpod-sdk";
51
29
 
52
- // On-demand pod (guaranteed resources)
53
- const pod = await runpod.pods.create({
54
- name: 'training-pod',
55
- imageName: 'pytorch/pytorch:latest',
56
- gpuTypeId: GpuTypes.A100_80GB, // Type-safe GPU selection
57
- gpuCount: 2,
58
- volumeInGb: 50,
59
- env: {
60
- WANDB_API_KEY: 'your-key',
61
- MODEL_NAME: 'llama-7b'
62
- }
63
- })
64
-
65
- // Spot pod (cheaper, interruptible)
66
- const spotPod = await runpod.pods.create({
67
- name: 'spot-training',
68
- imageName: 'pytorch/pytorch:latest',
69
- gpuTypeId: GpuTypes.RTX_3090, // Type-safe
70
- interruptible: true, // Makes it a spot pod
71
- bidPerGpu: 0.15, // Your max bid per GPU per hour
72
- gpuCount: 4
73
- })
30
+ const runpod = runpodSdk(RUNPOD_API_KEY);
31
+ const endpoint = runpod.endpoint(ENDPOINT_ID);
32
+ const result = await endpoint.runSync({
33
+ input: {
34
+ prompt: "a photo of a horse the size of a Boeing 787",
35
+ },
36
+ });
74
37
  ```
75
38
 
76
- ### Managing Pods
77
-
78
- ```typescript
79
- // List your pods
80
- const pods = await runpod.pods.list()
81
- const runningPods = await runpod.pods.list({ status: 'RUNNING' })
39
+ # Using the REST v2 API
82
40
 
83
- // Get specific pod
84
- const pod = await runpod.pods.get('pod-id')
41
+ `runpod.api` is a typed client for the [Runpod REST v2 API](https://api.runpod.io/v2/docs). Paths, parameters, and responses are typed from the OpenAPI spec.
85
42
 
86
- // Control pods
87
- await runpod.pods.stop('pod-id')
88
- await runpod.pods.resume('pod-id', 2) // Resume with 2 GPUs
89
- await runpod.pods.terminate('pod-id') // Permanent deletion
90
-
91
- // Wait for pod to be ready
92
- const readyPod = await runpod.pods.waitForReady('pod-id')
93
- console.log(`Pod ready! SSH: ${readyPod.machine?.podHostId}`)
43
+ ```js
44
+ const { data: pods, error } = await runpod.api.GET("/v2/pods");
94
45
  ```
95
46
 
96
- ### Pod Information
47
+ See the [`@runpod/typescript-api-sdk` README](../typescript-api-sdk/README.md) for retries, timeouts, rate limits, and log streams. Everything that package exports is also exported from `runpod-sdk`.
97
48
 
98
- ```typescript
99
- // Check pod status
100
- const isRunning = await runpod.pods.isRunning('pod-id')
101
- const costPerHour = await runpod.pods.getCostPerHour('pod-id')
49
+ # Upgrading from 1.x
102
50
 
103
- // Get runtime info (ports, GPU utilization)
104
- const runtime = await runpod.pods.getRuntime('pod-id')
105
- console.log(`GPU utilization: ${runtime?.gpus?.[0]?.gpuUtilPercent}%`)
106
- ```
107
-
108
- ### GPU Types
109
-
110
- Flexible GPU selection with type safety and runtime discovery:
111
-
112
- ```typescript
113
- import { GpuTypes } from 'runpod-sdk'
114
-
115
- // Method 1: Type-safe with autocomplete (RECOMMENDED)
116
- const pod = await runpod.pods.create({
117
- name: 'prod-pod',
118
- imageName: 'pytorch/pytorch:latest',
119
- gpuTypeId: GpuTypes.H200_SXM, // 141GB memory, full IDE support
120
- })
121
-
122
- // Method 2: Custom string for dev/experimental GPUs
123
- const devPod = await runpod.pods.create({
124
- name: 'dev-pod',
125
- imageName: 'custom-image:latest',
126
- gpuTypeId: 'CUSTOM_DEV_GPU_TYPE', // Any string works
127
- })
128
-
129
- // Method 3: Runtime discovery for flexibility
130
- const gpuTypes = await runpod.pods.listGpuTypes()
131
- const highMemGpu = gpuTypes.find(g => g.memoryInGb >= 80)
132
-
133
- const flexPod = await runpod.pods.create({
134
- name: 'flex-pod',
135
- imageName: 'pytorch/pytorch:latest',
136
- gpuTypeId: highMemGpu?.id || GpuTypes.RTX_4090
137
- })
138
-
139
- // Check available GPUs at runtime
140
- const availableGpus = await runpod.pods.listGpuTypes()
141
- const customGpu = availableGpus.find(gpu => gpu.displayName.includes('RTX'))
142
- console.log(`Found GPU: ${customGpu?.displayName}`)
143
- ```
51
+ The `endpoint(id)` methods keep their 1.x names and arguments. Other changes in 2.0.0:
144
52
 
145
- **Available Production GPU Types:**
146
- - **Latest**: RTX_5090 (32GB), RTX_5080 (16GB)
147
- - **High-End**: H200_SXM (141GB), H100_PCIE (80GB), B200 (180GB)
148
- - **Popular**: RTX_4090 (24GB), A100_PCIE (80GB), L40S (48GB)
149
- - **Cost-Effective**: RTX_3090 (24GB), RTX_4080 (16GB)
53
+ - Node.js 20 or later is required.
54
+ - An HTTP error throws `RunpodServerlessError`, with `status`, `statusText`, and `body`.
55
+ - The exported `run`, `runSync`, `status`, `stream`, `health`, and `purgeQueue` functions are no longer curried. Call them with all arguments.
56
+ - `runSync` no longer logs each poll to the console.
150
57
 
151
- ## ⚡ Serverless Endpoints
58
+ # Using Endpoints
152
59
 
153
60
  Once an endpoint has been created, you can send requests to the queue:
154
61
 
@@ -220,83 +127,29 @@ const result = await endpoint.runSync({
220
127
  },
221
128
  }, 5000);
222
129
  ```
223
-
224
130
  will timeout after 5 seconds.
225
131
 
226
- ## 🔧 Account & Resources
227
-
228
- ```typescript
229
- // Get your profile and usage
230
- const profile = await runpod.getProfile()
231
- console.log(`Credits: ${profile?.spendLimit}`)
232
- console.log(`Current spend: $${profile?.currentSpendPerHr}/hour`)
233
-
234
- // List available GPU types
235
- const gpuTypes = await runpod.listGpuTypes()
236
- console.log('Available GPUs:', gpuTypes.map(g => g.displayName))
237
- ```
238
-
239
- ## 🌍 Configuration
240
-
241
- ```typescript
242
- // Initialize with custom options
243
- const runpod = new RunPod('your-api-key', {
244
- baseUrl: 'https://api.runpod.ai/v2', // REST endpoints
245
- graphqlUrl: 'https://api.runpod.io/graphql', // GraphQL API
246
- timeout: 30000,
247
- retries: 3
248
- })
132
+ Note that this is the timeout on the *local* function call, not the underlying request in the queue. So this:
249
133
 
250
- // Switch environments
251
- runpod.setEnvironment('development') // Uses dev API
252
- runpod.setEnvironment('production') // Uses prod API (default)
253
- ```
254
-
255
- ## 📝 TypeScript Support
256
-
257
- Full TypeScript support with auto-generated types:
258
-
259
- ```typescript
260
- import RunPod, { Pod, PodConfig, PodStatus } from 'runpod-sdk'
261
-
262
- const config: PodConfig = {
263
- name: 'my-pod',
264
- imageName: 'ubuntu:20.04',
265
- gpuTypeId: 'NVIDIA_A100',
266
- // Full autocomplete and type checking
267
- }
268
-
269
- const pod: Pod = await runpod.pods.createOnDemand(config)
134
+ ```js
135
+ const result = await endpoint.run({
136
+ input: {
137
+ prompt: "a photo of a horse the size of a Boeing 787",
138
+ },
139
+ }, 3000);
270
140
  ```
271
141
 
272
- ---
273
-
274
- ## 🤝 Contributing
275
-
276
- We welcome contributions! This SDK uses GraphQL Code Generator for type-safe operations.
142
+ will not enqueue a request which can only take 3 seconds on the server, it will only timeout if the enqueue itself is slower than 3 seconds.
277
143
 
278
- ### Development Setup
144
+ To affect the maximum time a request can take on the backend, you can provide a policy in the request input:
279
145
 
280
- ```bash
281
- git clone https://github.com/runpod/js-sdk.git
282
- cd js-sdk
283
- npm install
284
-
285
- # Copy environment file and add your API key
286
- cp .env.example .env
287
-
288
- # Generate GraphQL types
289
- npm run codegen
290
-
291
- # Build the project
292
- npm run build
146
+ ```js
147
+ const result = await endpoint.run({
148
+ input: {
149
+ prompt: "a photo of a horse the size of a Boeing 787",
150
+ },
151
+ policy: {
152
+ executionTimeout: 3000,
153
+ }
154
+ });
293
155
  ```
294
-
295
- ### Architecture
296
-
297
- - `src/index.ts` - Main SDK entry point
298
- - `src/pods/` - Pod management functionality
299
- - `src/graphql/` - GraphQL client and operations
300
- - `src/graphql/generated/` - Auto-generated types (do not edit)
301
-
302
- The generated types in `src/graphql/generated/` are created from the RunPod GraphQL API and should not be manually edited.
package/dist/index.cjs ADDED
@@ -0,0 +1,247 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Endpoint: () => Endpoint,
25
+ RunpodSdk: () => RunpodSdk,
26
+ RunpodServerlessError: () => RunpodServerlessError,
27
+ cancel: () => cancel,
28
+ default: () => runpodSdk,
29
+ health: () => health,
30
+ purgeQueue: () => purgeQueue,
31
+ run: () => run,
32
+ runSync: () => runSync,
33
+ runpodServerlessBaseUrlDev: () => runpodServerlessBaseUrlDev,
34
+ runpodServerlessBaseUrlProd: () => runpodServerlessBaseUrlProd,
35
+ status: () => status,
36
+ statusSync: () => statusSync,
37
+ stream: () => stream
38
+ });
39
+ module.exports = __toCommonJS(index_exports);
40
+ var import_typescript_api_sdk = require("@runpod/typescript-api-sdk");
41
+
42
+ // src/serverless.ts
43
+ var runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
44
+ var runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
45
+ var RunpodServerlessError = class extends Error {
46
+ status;
47
+ statusText;
48
+ body;
49
+ constructor(status2, statusText, body, url) {
50
+ super(`runpod: ${status2} ${statusText} from ${url}${body ? `: ${body}` : ""}`);
51
+ this.name = "RunpodServerlessError";
52
+ this.status = status2;
53
+ this.statusText = statusText;
54
+ this.body = body;
55
+ }
56
+ };
57
+ var TERMINAL_STATUSES = ["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"];
58
+ var isCompleted = (status2) => TERMINAL_STATUSES.includes(status2);
59
+ var clamp = (min, max, value) => Math.min(max, Math.max(min, value));
60
+ var endpointUrl = (baseUrl, endpointId) => `${baseUrl}/${endpointId}`;
61
+ function getUserAgent() {
62
+ const version = true ? "2.0.0" : "dev";
63
+ const environment = typeof window !== "undefined" && window.navigator ? `Browser/${window.navigator.userAgent}` : "Unknown Environment";
64
+ return `RunPod-JS-SDK/${version} (${environment})`;
65
+ }
66
+ async function request(method, url, apiKey, body, timeout) {
67
+ const response = await fetch(url, {
68
+ method,
69
+ headers: {
70
+ "Authorization": `Bearer ${apiKey}`,
71
+ "Content-Type": "application/json",
72
+ "User-Agent": getUserAgent()
73
+ },
74
+ body: method === "POST" ? JSON.stringify(body ?? {}) : void 0,
75
+ signal: timeout > 0 ? AbortSignal.timeout(timeout) : void 0
76
+ });
77
+ if (!response.ok) {
78
+ const text = await response.text().catch(() => "");
79
+ throw new RunpodServerlessError(response.status, response.statusText, text, url);
80
+ }
81
+ return response;
82
+ }
83
+ async function readJson(response) {
84
+ if (response.status !== 200) {
85
+ return { status: response.status, statusText: response.statusText };
86
+ }
87
+ return response.json();
88
+ }
89
+ async function readStatus(response) {
90
+ if (response.status !== 200) {
91
+ return { status: response.status, statusText: response.statusText, started: false };
92
+ }
93
+ const data = await response.json();
94
+ return {
95
+ ...data,
96
+ started: true,
97
+ completed: isCompleted(data.status),
98
+ succeeded: data.status === "COMPLETED"
99
+ };
100
+ }
101
+ async function run(baseUrl, apiKey, endpointId, payload, timeout = 3e3) {
102
+ const url = `${endpointUrl(baseUrl, endpointId)}/run`;
103
+ return readJson(await request("POST", url, apiKey, payload, timeout));
104
+ }
105
+ async function status(baseUrl, apiKey, endpointId, requestId, timeout = 3e3) {
106
+ const url = `${endpointUrl(baseUrl, endpointId)}/status/${requestId}`;
107
+ return readStatus(await request("GET", url, apiKey, void 0, timeout));
108
+ }
109
+ async function statusSync(baseUrl, apiKey, endpointId, requestId, timeout = 9e4) {
110
+ const wait = clamp(1e3, 9e4, timeout);
111
+ const url = `${endpointUrl(baseUrl, endpointId)}/status-sync/${requestId}?wait=${wait}`;
112
+ return readStatus(await request("GET", url, apiKey, void 0, 0));
113
+ }
114
+ async function runsyncOnce(baseUrl, apiKey, endpointId, payload, timeout) {
115
+ const wait = clamp(1e3, 9e4, timeout);
116
+ const url = `${endpointUrl(baseUrl, endpointId)}/runsync?wait=${wait}`;
117
+ return readStatus(await request("POST", url, apiKey, payload, 0));
118
+ }
119
+ async function runSync(baseUrl, apiKey, endpointId, payload, timeout = 9e4) {
120
+ const startTime = Date.now();
121
+ const remaining = () => clamp(1e3, 9e4, timeout - (Date.now() - startTime));
122
+ let data = await runsyncOnce(baseUrl, apiKey, endpointId, payload, timeout);
123
+ const { id } = data;
124
+ const pollStart = Date.now();
125
+ while (!isCompleted(data.status)) {
126
+ if (Date.now() - pollStart > timeout) {
127
+ return { ...data, started: true, completed: false };
128
+ }
129
+ data = await statusSync(baseUrl, apiKey, endpointId, id, remaining());
130
+ }
131
+ return { ...data, started: true, completed: true, succeeded: data.status === "COMPLETED" };
132
+ }
133
+ async function* stream(baseUrl, apiKey, endpointId, requestId, timeout = 0) {
134
+ const start = Date.now();
135
+ const url = `${endpointUrl(baseUrl, endpointId)}/stream/${requestId}`;
136
+ let completed = false;
137
+ while (!completed) {
138
+ const data = await readJson(await request("GET", url, apiKey, void 0, 0));
139
+ if (timeout !== 0 && Date.now() - start > timeout) {
140
+ completed = true;
141
+ }
142
+ if (isCompleted(data.status)) {
143
+ completed = true;
144
+ }
145
+ for (const output of data?.stream ?? []) {
146
+ yield output;
147
+ }
148
+ }
149
+ }
150
+ async function cancel(baseUrl, apiKey, endpointId, requestId, timeout = 3e3) {
151
+ const url = `${endpointUrl(baseUrl, endpointId)}/cancel/${requestId}`;
152
+ return readJson(await request("POST", url, apiKey, {}, timeout));
153
+ }
154
+ async function health(baseUrl, apiKey, endpointId, timeout = 3e3) {
155
+ const url = `${endpointUrl(baseUrl, endpointId)}/health`;
156
+ return readJson(await request("GET", url, apiKey, void 0, timeout));
157
+ }
158
+ async function purgeQueue(baseUrl, apiKey, endpointId, timeout = 3e3) {
159
+ const url = `${endpointUrl(baseUrl, endpointId)}/purge-queue`;
160
+ return readJson(await request("POST", url, apiKey, {}, timeout));
161
+ }
162
+ var Endpoint = class {
163
+ endpointId;
164
+ baseUrl;
165
+ apiKey;
166
+ constructor(baseUrl, apiKey, endpointId) {
167
+ this.baseUrl = baseUrl;
168
+ this.apiKey = apiKey;
169
+ this.endpointId = endpointId;
170
+ }
171
+ runSync(payload, timeout = 9e4) {
172
+ return runSync(this.baseUrl, this.apiKey, this.endpointId, payload, timeout);
173
+ }
174
+ run(payload, timeout = 3e3) {
175
+ return run(this.baseUrl, this.apiKey, this.endpointId, payload, timeout);
176
+ }
177
+ status(requestId, timeout = 3e3) {
178
+ return status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
179
+ }
180
+ statusSync(requestId, timeout = 9e4) {
181
+ return statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
182
+ }
183
+ /** No timeout by default. */
184
+ stream(requestId, timeout = 0) {
185
+ return stream(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
186
+ }
187
+ cancel(requestId, timeout = 3e3) {
188
+ return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout);
189
+ }
190
+ health(timeout = 3e3) {
191
+ return health(this.baseUrl, this.apiKey, this.endpointId, timeout);
192
+ }
193
+ purgeQueue(timeout = 3e3) {
194
+ return purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout);
195
+ }
196
+ };
197
+
198
+ // src/index.ts
199
+ __reExport(index_exports, require("@runpod/typescript-api-sdk"), module.exports);
200
+ var RunpodSdk = class {
201
+ baseUrl = runpodServerlessBaseUrlProd;
202
+ apiKey = "";
203
+ apiBaseUrl;
204
+ restClient;
205
+ constructor(apiKey, options = {}) {
206
+ this.baseUrl = options.baseUrl ?? this.baseUrl;
207
+ this.apiBaseUrl = options.apiBaseUrl;
208
+ if (apiKey == null) {
209
+ console.log("Api key not supplied");
210
+ return;
211
+ }
212
+ this.apiKey = apiKey;
213
+ }
214
+ /** A Serverless endpoint client for job requests. */
215
+ endpoint(endpointId) {
216
+ if (endpointId == null) {
217
+ console.log("Endpoint id not supplied");
218
+ return null;
219
+ }
220
+ return new Endpoint(this.baseUrl, this.apiKey, endpointId);
221
+ }
222
+ /** The typed REST v2 client, for pods, endpoints, templates, volumes, and more. */
223
+ get api() {
224
+ this.restClient ??= (0, import_typescript_api_sdk.createRunpodClient)({ apiKey: this.apiKey || void 0, baseUrl: this.apiBaseUrl });
225
+ return this.restClient;
226
+ }
227
+ };
228
+ function runpodSdk(apiKey, options = {}) {
229
+ return new RunpodSdk(apiKey, options);
230
+ }
231
+ // Annotate the CommonJS export names for ESM import in node:
232
+ 0 && (module.exports = {
233
+ Endpoint,
234
+ RunpodSdk,
235
+ RunpodServerlessError,
236
+ cancel,
237
+ health,
238
+ purgeQueue,
239
+ run,
240
+ runSync,
241
+ runpodServerlessBaseUrlDev,
242
+ runpodServerlessBaseUrlProd,
243
+ status,
244
+ statusSync,
245
+ stream,
246
+ ...require("@runpod/typescript-api-sdk")
247
+ });
@@ -0,0 +1,127 @@
1
+ import { RunpodClient } from '@runpod/typescript-api-sdk';
2
+ export * from '@runpod/typescript-api-sdk';
3
+
4
+ declare const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
5
+ declare const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
6
+ type ExecutionPolicy = {
7
+ executionTimeout?: number;
8
+ lowPriority?: boolean;
9
+ ttl?: number;
10
+ };
11
+ type S3Config = {
12
+ accessId: string;
13
+ accessSecret: string;
14
+ bucketName: string;
15
+ endpointUrl: string;
16
+ objectPath?: string;
17
+ };
18
+ type EndpointInputPayload = {
19
+ input: any;
20
+ webhook?: string;
21
+ webhookV2?: string;
22
+ s3Config?: S3Config;
23
+ policy?: ExecutionPolicy;
24
+ };
25
+ type EndpointIncompleteOutput = {
26
+ delayTime?: number;
27
+ status: string;
28
+ id: string;
29
+ };
30
+ type EndpointCompletedOutput = {
31
+ status: string;
32
+ id: string;
33
+ output: any;
34
+ executionTime: number;
35
+ delayTime: number;
36
+ };
37
+ type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput;
38
+ type EndpointStreamOutput = {
39
+ status: string;
40
+ stream: any[];
41
+ };
42
+ type CancelOutput = {
43
+ status: string;
44
+ id: string;
45
+ executionTime: number;
46
+ delayTime: number;
47
+ };
48
+ type HealthCheck = {
49
+ jobs: {
50
+ completed: number;
51
+ failed: number;
52
+ inProgress: number;
53
+ inQueue: number;
54
+ retried: number;
55
+ };
56
+ workers: {
57
+ idle: number;
58
+ initializing: number;
59
+ ready: number;
60
+ running: number;
61
+ throttled: number;
62
+ };
63
+ };
64
+ type PurgeQueueOutput = {
65
+ removed: number;
66
+ status: string;
67
+ };
68
+ /** Thrown when the Serverless job API answers with a non-2xx status. */
69
+ declare class RunpodServerlessError extends Error {
70
+ readonly status: number;
71
+ readonly statusText: string;
72
+ readonly body: string;
73
+ constructor(status: number, statusText: string, body: string, url: string);
74
+ }
75
+ /** POST /run: queue a job and return its id. */
76
+ declare function run(baseUrl: string, apiKey: string, endpointId: string, payload: EndpointInputPayload, timeout?: number): Promise<EndpointIncompleteOutput>;
77
+ /** GET /status/{requestId}. */
78
+ declare function status(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<EndpointOutput>;
79
+ /** GET /status-sync/{requestId}: wait on the server for up to `timeout` ms (1 to 90 s). */
80
+ declare function statusSync(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<EndpointOutput>;
81
+ /** POST /runsync, then poll /status-sync until the job ends or `timeout` ms pass. */
82
+ declare function runSync(baseUrl: string, apiKey: string, endpointId: string, payload: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
83
+ /** Poll GET /stream/{requestId} and yield each streamed output until the job ends. */
84
+ declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): AsyncGenerator<any>;
85
+ /** POST /cancel/{requestId}. */
86
+ declare function cancel(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number): Promise<CancelOutput>;
87
+ /** GET /health: job and worker counts for the endpoint. */
88
+ declare function health(baseUrl: string, apiKey: string, endpointId: string, timeout?: number): Promise<HealthCheck>;
89
+ /** POST /purge-queue: remove every queued job. */
90
+ declare function purgeQueue(baseUrl: string, apiKey: string, endpointId: string, timeout?: number): Promise<PurgeQueueOutput>;
91
+ /** One Serverless endpoint, bound to an API key. */
92
+ declare class Endpoint {
93
+ endpointId: string;
94
+ baseUrl: string;
95
+ private apiKey;
96
+ constructor(baseUrl: string, apiKey: string, endpointId: string);
97
+ runSync(payload: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
98
+ run(payload: EndpointInputPayload, timeout?: number): Promise<EndpointIncompleteOutput>;
99
+ status(requestId: string, timeout?: number): Promise<EndpointOutput>;
100
+ statusSync(requestId: string, timeout?: number): Promise<EndpointOutput>;
101
+ /** No timeout by default. */
102
+ stream(requestId: string, timeout?: number): AsyncGenerator<any, any, any>;
103
+ cancel(requestId: string, timeout?: number): Promise<CancelOutput>;
104
+ health(timeout?: number): Promise<HealthCheck>;
105
+ purgeQueue(timeout?: number): Promise<PurgeQueueOutput>;
106
+ }
107
+
108
+ type SdkOptions = {
109
+ /** Serverless job API base URL. Defaults to https://api.runpod.ai/v2. */
110
+ baseUrl?: string;
111
+ /** REST v2 API base URL. Defaults to https://api.runpod.io. */
112
+ apiBaseUrl?: string;
113
+ };
114
+ declare class RunpodSdk {
115
+ baseUrl: string;
116
+ private apiKey;
117
+ private apiBaseUrl?;
118
+ private restClient?;
119
+ constructor(apiKey: string, options?: SdkOptions);
120
+ /** A Serverless endpoint client for job requests. */
121
+ endpoint(endpointId: string): Endpoint | null;
122
+ /** The typed REST v2 client, for pods, endpoints, templates, volumes, and more. */
123
+ get api(): RunpodClient;
124
+ }
125
+ declare function runpodSdk(apiKey: string, options?: SdkOptions): RunpodSdk;
126
+
127
+ export { type CancelOutput, Endpoint, type EndpointCompletedOutput, type EndpointIncompleteOutput, type EndpointInputPayload, type EndpointOutput, type EndpointStreamOutput, type ExecutionPolicy, type HealthCheck, type PurgeQueueOutput, RunpodSdk, RunpodServerlessError, type S3Config, type SdkOptions, cancel, runpodSdk as default, health, purgeQueue, run, runSync, runpodServerlessBaseUrlDev, runpodServerlessBaseUrlProd, status, statusSync, stream };