runpod-sdk 1.0.3 → 1.0.4

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/README.md CHANGED
@@ -22,7 +22,7 @@ const result = await endpoint.runSync({
22
22
  Once an endpoint has been created, you can send requests to the queue:
23
23
 
24
24
  ```js
25
- const requestId = await endpoint.run({
25
+ const { id } = await endpoint.run({
26
26
  input: {
27
27
  prompt: "a photo of a horse the size of a Boeing 787",
28
28
  },
@@ -32,7 +32,7 @@ const requestId = await endpoint.run({
32
32
  You can check on the status of this request once you have the id:
33
33
 
34
34
  ```js
35
- const status = await endpoint.getStatus(requestId);
35
+ const status = await endpoint.getStatus(id);
36
36
  ```
37
37
 
38
38
  If the request has been completed, the status object returned will contain the `output` of the request.
@@ -58,3 +58,20 @@ For long running applications or troubleshooting, you may want to check the heal
58
58
  ```js
59
59
  const health = await endpoint.getHealth();
60
60
  ```
61
+
62
+ Some Runpod endpoints are configured to yield multiple results for a single input, which can be streamed locally:
63
+
64
+ ```js
65
+ const { id } = await endpoint.run({
66
+ input: {
67
+ prompt: "7 photos of a horse the size of a Boeing 787",
68
+ },
69
+ });
70
+
71
+ for await (const result of endpoint.stream(id)) {
72
+ console.log("Stream yielded another photo:");
73
+ console.log(result.output);
74
+ }
75
+ ```
76
+
77
+ (this horse photo endpoint is fictitious, but it shows why you might want a stream of results)
package/dist/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export type EndpointInputPayload = {
15
15
  policy?: ExecutionPolicy;
16
16
  };
17
17
  export type EndpointIncompleteOutput = {
18
+ delayTime?: number;
18
19
  status: string;
19
20
  id: string;
20
21
  };
@@ -26,6 +27,10 @@ export type EndpointCompletedOutput = {
26
27
  delayTime: number;
27
28
  };
28
29
  export type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput;
30
+ export type EndpointStreamOutput = {
31
+ status: string;
32
+ stream: [any];
33
+ };
29
34
  export type CancelOutput = {
30
35
  status: string;
31
36
  id: string;
@@ -57,9 +62,10 @@ export type SdkOptions = {
57
62
  };
58
63
  export declare const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
59
64
  export declare const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
60
- export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<{
65
+ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload, timeout?: number) => Promise<{
61
66
  started: boolean;
62
67
  completed: boolean;
68
+ delayTime?: number | undefined;
63
69
  status: string;
64
70
  id: string;
65
71
  } | {
@@ -74,6 +80,7 @@ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(ba
74
80
  started: boolean;
75
81
  completed: boolean;
76
82
  succeeded: boolean;
83
+ delayTime?: number | undefined;
77
84
  status: string;
78
85
  id: string;
79
86
  } | {
@@ -86,23 +93,24 @@ export declare const runSync: import("ts-toolbelt/out/Function/Curry").Curry<(ba
86
93
  executionTime: number;
87
94
  delayTime: number;
88
95
  }>>;
89
- export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => Promise<any>>;
90
- export declare const getStatus: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, requestId: string) => Promise<any>>;
91
- export declare const stream: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, requestId: string) => Promise<any>>;
92
- export declare const getHealth: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string) => Promise<any>>;
93
- export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string) => Promise<any>>;
96
+ export declare const run: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload, timeout?: number) => Promise<any>>;
97
+ export declare const status: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, requestId: string, timeout?: number) => Promise<any>>;
98
+ export declare function stream(baseUrl: string, apiKey: string, endpointId: string, requestId: string): AsyncGenerator<any, void, unknown>;
99
+ export declare const health: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
100
+ export declare const purgeQueue: import("ts-toolbelt/out/Function/Curry").Curry<(baseUrl: string, apiKey: string, endpointId: string, timeout?: number) => Promise<any>>;
94
101
  declare class Endpoint {
95
102
  endpointId: string;
96
103
  baseUrl: string;
97
104
  private apiKey;
98
105
  constructor(baseUrl: string, apiKey: string, endpointId: string);
99
- runSync(request: EndpointInputPayload): Promise<EndpointCompletedOutput>;
100
- run(request: EndpointInputPayload): Promise<string>;
101
- getStatus(requestId: string): Promise<EndpointOutput>;
102
- stream(requestId: string): Promise<EndpointOutput>;
103
- cancel(requestId: string): Promise<CancelOutput>;
104
- getHealth(): Promise<HealthCheck>;
105
- purgeQueue(): Promise<PurgeQueueOutput>;
106
+ runSync(request: EndpointInputPayload, timeout?: number): Promise<EndpointCompletedOutput>;
107
+ run(request: EndpointInputPayload, timeout?: number): Promise<string>;
108
+ status(requestId: string, timeout?: number): Promise<EndpointOutput>;
109
+ statusSync(requestId: string, timeout?: number): Promise<EndpointOutput>;
110
+ stream(requestId: string): AsyncGenerator<any>;
111
+ cancel(requestId: string, timeout?: number): Promise<CancelOutput>;
112
+ health(timeout?: number): Promise<HealthCheck>;
113
+ purgeQueue(timeout?: number): Promise<PurgeQueueOutput>;
106
114
  }
107
115
  declare class RunpodSdk {
108
116
  private apiKey;
package/dist/index.js CHANGED
@@ -45,6 +45,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
+ var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
49
+ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
50
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
51
+ var g = generator.apply(thisArg, _arguments || []), i, q = [];
52
+ return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
53
+ function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
54
+ function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
55
+ function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
56
+ function fulfill(value) { resume("next", value); }
57
+ function reject(value) { resume("throw", value); }
58
+ function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
59
+ };
48
60
  import axios from "axios";
49
61
  import { curry, clamp, isNil } from "ramda";
50
62
  var getAuthHeader = function (apiKey) { return ({
@@ -54,7 +66,6 @@ var getAuthHeader = function (apiKey) { return ({
54
66
  },
55
67
  }); };
56
68
  var print = console.log;
57
- var sleep = function (ms) { return new Promise(function (resolve) { return setTimeout(resolve, ms); }); };
58
69
  var handleErrors = function (axiosRequest) { return __awaiter(void 0, void 0, void 0, function () {
59
70
  var resp, status, statusText;
60
71
  return __generator(this, function (_a) {
@@ -81,92 +92,139 @@ var handleErrorsStatus = function (axiosRequest) { return __awaiter(void 0, void
81
92
  if (status !== 200) {
82
93
  return [2 /*return*/, { status: status, statusText: statusText, started: false }];
83
94
  }
84
- return [2 /*return*/, __assign(__assign({}, resp.data), { started: true, completed: ["COMPLETED", "FAILED"].includes(resp.data.status), succeeded: resp.data.status === "COMPLETED" })];
95
+ return [2 /*return*/, __assign(__assign({}, resp.data), { started: true, completed: isCompleted(resp.data.status), succeeded: resp.data.status === "COMPLETED" })];
85
96
  }
86
97
  });
87
98
  }); };
88
99
  export var runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2";
89
100
  export var runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2";
90
101
  var getEndpointUrl = curry(function (baseUrl, endpointId) { return "".concat(baseUrl, "/").concat(endpointId); });
102
+ var isCompleted = function (status) {
103
+ return ["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"].includes(status);
104
+ };
91
105
  //run and then poll status
92
- export var runSync = curry(function (baseUrl, apiKey, endpointId, request) { return __awaiter(void 0, void 0, void 0, function () {
93
- var maxWaitTimeMs, startTime, getRemainingTime, runResp, data, id, start;
94
- var _a, _b;
95
- return __generator(this, function (_c) {
96
- switch (_c.label) {
97
- case 0:
98
- maxWaitTimeMs = (_b = (_a = request === null || request === void 0 ? void 0 : request.policy) === null || _a === void 0 ? void 0 : _a.executionTimeout) !== null && _b !== void 0 ? _b : 300 * 1000;
99
- startTime = Date.now();
100
- getRemainingTime = function () { return clamp(1000, 90000, maxWaitTimeMs - (Date.now() - startTime)); };
101
- return [4 /*yield*/, runsync(baseUrl, apiKey, endpointId, request)];
102
- case 1:
103
- runResp = _c.sent();
104
- data = __assign({}, runResp);
105
- id = data.id;
106
- start = Date.now();
107
- _c.label = 2;
108
- case 2:
109
- if (!!["COMPLETED", "FAILED"].includes(data.status)) return [3 /*break*/, 4];
110
- if (Date.now() - start > maxWaitTimeMs) {
111
- print("".concat(id, " timed out after ").concat(maxWaitTimeMs / 1000, " seconds"));
112
- return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: false })];
113
- }
114
- return [4 /*yield*/, statusSync(baseUrl, apiKey, endpointId, id, getRemainingTime())];
115
- case 3:
116
- data = _c.sent();
117
- print("".concat(id, ": ").concat(data.status));
118
- return [3 /*break*/, 2];
119
- case 4: return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: true, succeeded: data.status === "COMPLETED" })];
120
- }
106
+ export var runSync = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
107
+ if (timeout === void 0) { timeout = 90000; }
108
+ return __awaiter(void 0, void 0, void 0, function () {
109
+ var startTime, getRemainingTime, runResp, data, id, start;
110
+ return __generator(this, function (_a) {
111
+ switch (_a.label) {
112
+ case 0:
113
+ startTime = Date.now();
114
+ getRemainingTime = function () { return clamp(1000, 90000, timeout - (Date.now() - startTime)); };
115
+ return [4 /*yield*/, runsync(baseUrl, apiKey, endpointId, request, timeout)];
116
+ case 1:
117
+ runResp = _a.sent();
118
+ data = __assign({}, runResp);
119
+ id = data.id;
120
+ start = Date.now();
121
+ _a.label = 2;
122
+ case 2:
123
+ if (!!isCompleted(data.status)) return [3 /*break*/, 4];
124
+ if (Date.now() - start > timeout) {
125
+ print("".concat(id, " timed out after ").concat(timeout / 1000, " seconds"));
126
+ return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: false })];
127
+ }
128
+ return [4 /*yield*/, statusSync(baseUrl, apiKey, endpointId, id, getRemainingTime())];
129
+ case 3:
130
+ data = _a.sent();
131
+ print("".concat(id, ": ").concat(data.status));
132
+ return [3 /*break*/, 2];
133
+ case 4: return [2 /*return*/, __assign(__assign({}, data), { started: true, completed: true, succeeded: data.status === "COMPLETED" })];
134
+ }
135
+ });
121
136
  });
122
- }); });
137
+ });
123
138
  //wrapper over /status-sync
124
- var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId, wait) {
139
+ var statusSync = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
140
+ if (timeout === void 0) { timeout = 90000; }
141
+ var wait = clamp(1000, 90000, timeout);
142
+ console.log("statusSync wait", wait);
125
143
  var url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + "?wait=".concat(wait);
126
144
  var authHeader = getAuthHeader(apiKey);
127
- return handleErrorsStatus(axios.get(url, authHeader));
145
+ return handleErrorsStatus(axios.get(url, __assign({}, authHeader)));
128
146
  });
129
147
  //wrapper over /runsync
130
- var runsync = curry(function (baseUrl, apiKey, endpointId, request) {
131
- var url = getEndpointUrl(baseUrl, endpointId) + "/runsync";
148
+ var runsync = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
149
+ if (timeout === void 0) { timeout = 90000; }
150
+ var wait = clamp(1000, 90000, timeout);
151
+ console.log("runsync wait:", wait);
152
+ var url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + "?wait=".concat(wait);
132
153
  var authHeader = getAuthHeader(apiKey);
133
- return handleErrorsStatus(axios.post(url, request, authHeader));
154
+ return handleErrorsStatus(axios.post(url, request, __assign({}, authHeader)));
134
155
  });
135
156
  //wrapper over /run
136
- export var run = curry(function (baseUrl, apiKey, endpointId, request) {
157
+ export var run = curry(function (baseUrl, apiKey, endpointId, request, timeout) {
158
+ if (timeout === void 0) { timeout = 3000; }
137
159
  var url = getEndpointUrl(baseUrl, endpointId) + "/run";
138
160
  var authHeader = getAuthHeader(apiKey);
139
- return handleErrors(axios.post(url, request, authHeader));
161
+ return handleErrors(axios.post(url, request, __assign(__assign({}, authHeader), { timeout: timeout })));
140
162
  });
141
163
  //wrapper over /status
142
- export var getStatus = curry(function (baseUrl, apiKey, endpointId, requestId) {
164
+ export var status = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
165
+ if (timeout === void 0) { timeout = 3000; }
143
166
  var url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId;
144
167
  var authHeader = getAuthHeader(apiKey);
145
168
  return handleErrorsStatus(axios.get(url, authHeader));
146
169
  });
147
- //wrapper over /stream
148
- export var stream = curry(function (baseUrl, apiKey, endpointId, requestId) {
149
- var url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId;
150
- var authHeader = getAuthHeader(apiKey);
151
- return handleErrors(axios.get(url, authHeader));
152
- });
170
+ //generator yielding results of stream
171
+ export function stream(baseUrl, apiKey, endpointId, requestId) {
172
+ return __asyncGenerator(this, arguments, function stream_1() {
173
+ var completed, url, authHeader, resp, _i, _a, output;
174
+ return __generator(this, function (_b) {
175
+ switch (_b.label) {
176
+ case 0:
177
+ completed = false;
178
+ _b.label = 1;
179
+ case 1:
180
+ if (!!completed) return [3 /*break*/, 8];
181
+ url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId;
182
+ authHeader = getAuthHeader(apiKey);
183
+ return [4 /*yield*/, __await(handleErrors(axios.get(url, authHeader)))];
184
+ case 2:
185
+ resp = _b.sent();
186
+ if (isCompleted(resp.status)) {
187
+ completed = true;
188
+ }
189
+ _i = 0, _a = resp === null || resp === void 0 ? void 0 : resp.stream;
190
+ _b.label = 3;
191
+ case 3:
192
+ if (!(_i < _a.length)) return [3 /*break*/, 7];
193
+ output = _a[_i];
194
+ return [4 /*yield*/, __await(output)];
195
+ case 4: return [4 /*yield*/, _b.sent()];
196
+ case 5:
197
+ _b.sent();
198
+ _b.label = 6;
199
+ case 6:
200
+ _i++;
201
+ return [3 /*break*/, 3];
202
+ case 7: return [3 /*break*/, 1];
203
+ case 8: return [2 /*return*/];
204
+ }
205
+ });
206
+ });
207
+ }
153
208
  //wrapper over /cancel
154
- var cancel = curry(function (baseUrl, apiKey, endpointId, requestId) {
209
+ var cancel = curry(function (baseUrl, apiKey, endpointId, requestId, timeout) {
210
+ if (timeout === void 0) { timeout = 3000; }
155
211
  var url = getEndpointUrl(baseUrl, endpointId) + "/cancel/" + requestId;
156
212
  var authHeader = getAuthHeader(apiKey);
157
- return handleErrors(axios.post(url, {}, authHeader));
213
+ return handleErrors(axios.post(url, {}, __assign(__assign({}, authHeader), { timeout: timeout })));
158
214
  });
159
215
  //wrapper over /health
160
- export var getHealth = curry(function (baseUrl, apiKey, endpointId) {
216
+ export var health = curry(function (baseUrl, apiKey, endpointId, timeout) {
217
+ if (timeout === void 0) { timeout = 3000; }
161
218
  var url = getEndpointUrl(baseUrl, endpointId) + "/health";
162
219
  var authHeader = getAuthHeader(apiKey);
163
- return handleErrors(axios.get(url, authHeader));
220
+ return handleErrors(axios.get(url, __assign(__assign({}, authHeader), { timeout: timeout })));
164
221
  });
165
222
  //wrapper over /purge-queue
166
- export var purgeQueue = curry(function (baseUrl, apiKey, endpointId) {
223
+ export var purgeQueue = curry(function (baseUrl, apiKey, endpointId, timeout) {
224
+ if (timeout === void 0) { timeout = 3000; }
167
225
  var url = getEndpointUrl(baseUrl, endpointId) + "/purge-queue";
168
226
  var authHeader = getAuthHeader(apiKey);
169
- return handleErrors(axios.post(url, {}, authHeader));
227
+ return handleErrors(axios.post(url, {}, __assign(__assign({}, authHeader), { timeout: timeout })));
170
228
  });
171
229
  var Endpoint = /** @class */ (function () {
172
230
  function Endpoint(baseUrl, apiKey, endpointId) {
@@ -177,52 +235,62 @@ var Endpoint = /** @class */ (function () {
177
235
  this.apiKey = apiKey;
178
236
  this.endpointId = endpointId;
179
237
  }
180
- Endpoint.prototype.runSync = function (request) {
238
+ Endpoint.prototype.runSync = function (request, timeout) {
239
+ if (timeout === void 0) { timeout = 90000; }
181
240
  return __awaiter(this, void 0, void 0, function () {
182
241
  return __generator(this, function (_a) {
183
- return [2 /*return*/, runSync(this.baseUrl, this.apiKey, this.endpointId, request)];
242
+ return [2 /*return*/, runSync(this.baseUrl, this.apiKey, this.endpointId, request, timeout)];
184
243
  });
185
244
  });
186
245
  };
187
- Endpoint.prototype.run = function (request) {
246
+ Endpoint.prototype.run = function (request, timeout) {
247
+ if (timeout === void 0) { timeout = 3000; }
188
248
  return __awaiter(this, void 0, void 0, function () {
189
249
  return __generator(this, function (_a) {
190
- return [2 /*return*/, run(this.baseUrl, this.apiKey, this.endpointId, request)];
250
+ return [2 /*return*/, run(this.baseUrl, this.apiKey, this.endpointId, request, timeout)];
191
251
  });
192
252
  });
193
253
  };
194
- Endpoint.prototype.getStatus = function (requestId) {
254
+ Endpoint.prototype.status = function (requestId, timeout) {
255
+ if (timeout === void 0) { timeout = 3000; }
195
256
  return __awaiter(this, void 0, void 0, function () {
196
257
  return __generator(this, function (_a) {
197
- return [2 /*return*/, getStatus(this.baseUrl, this.apiKey, this.endpointId, requestId)];
258
+ return [2 /*return*/, status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
198
259
  });
199
260
  });
200
261
  };
201
- Endpoint.prototype.stream = function (requestId) {
262
+ Endpoint.prototype.statusSync = function (requestId, timeout) {
263
+ if (timeout === void 0) { timeout = 90000; }
202
264
  return __awaiter(this, void 0, void 0, function () {
203
265
  return __generator(this, function (_a) {
204
- return [2 /*return*/, stream(this.baseUrl, this.apiKey, this.endpointId, requestId)];
266
+ return [2 /*return*/, statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
205
267
  });
206
268
  });
207
269
  };
208
- Endpoint.prototype.cancel = function (requestId) {
270
+ Endpoint.prototype.stream = function (requestId) {
271
+ return stream(this.baseUrl, this.apiKey, this.endpointId, requestId);
272
+ };
273
+ Endpoint.prototype.cancel = function (requestId, timeout) {
274
+ if (timeout === void 0) { timeout = 3000; }
209
275
  return __awaiter(this, void 0, void 0, function () {
210
276
  return __generator(this, function (_a) {
211
- return [2 /*return*/, cancel(this.baseUrl, this.apiKey, this.endpointId, requestId)];
277
+ return [2 /*return*/, cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)];
212
278
  });
213
279
  });
214
280
  };
215
- Endpoint.prototype.getHealth = function () {
281
+ Endpoint.prototype.health = function (timeout) {
282
+ if (timeout === void 0) { timeout = 3000; }
216
283
  return __awaiter(this, void 0, void 0, function () {
217
284
  return __generator(this, function (_a) {
218
- return [2 /*return*/, getHealth(this.baseUrl, this.apiKey, this.endpointId)];
285
+ return [2 /*return*/, health(this.baseUrl, this.apiKey, this.endpointId, timeout)];
219
286
  });
220
287
  });
221
288
  };
222
- Endpoint.prototype.purgeQueue = function () {
289
+ Endpoint.prototype.purgeQueue = function (timeout) {
290
+ if (timeout === void 0) { timeout = 3000; }
223
291
  return __awaiter(this, void 0, void 0, function () {
224
292
  return __generator(this, function (_a) {
225
- return [2 /*return*/, purgeQueue(this.baseUrl, this.apiKey, this.endpointId)];
293
+ return [2 /*return*/, purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout)];
226
294
  });
227
295
  });
228
296
  };
@@ -256,3 +324,4 @@ export default (function (apiKey, options) {
256
324
  if (options === void 0) { options = defaultSdkOptions; }
257
325
  return new RunpodSdk(apiKey, options);
258
326
  });
327
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,KAAwB,MAAM,OAAO,CAAA;AAC5C,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,OAAO,CAAA;AA0D3C,IAAM,aAAa,GAAG,UAAC,MAAc,IAAK,OAAA,CAAC;IACzC,OAAO,EAAE;QACP,eAAe,EAAE,iBAAU,MAAM,CAAE;QACnC,cAAc,EAAE,kBAAkB;KACnC;CACF,CAAC,EALwC,CAKxC,CAAA;AACF,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAA;AAEzB,IAAM,YAAY,GAAG,UAAO,YAAoC;;;;oBACjD,qBAAM,YAAY,EAAA;;gBAAzB,IAAI,GAAG,SAAkB;gBACvB,MAAM,GAAiB,IAAI,OAArB,EAAE,UAAU,GAAK,IAAI,WAAT,CAAS;gBACnC,IAAI,MAAM,KAAK,GAAG,EAAE;oBAClB,sBAAO,EAAE,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,EAAA;iBAC9B;gBACD,sBAAO,IAAI,CAAC,IAAI,EAAA;;;KACjB,CAAA;AACD,IAAM,kBAAkB,GAAG,UAAO,YAAoC;;;;oBACvD,qBAAM,YAAY,EAAA;;gBAAzB,IAAI,GAAG,SAAkB;gBACvB,MAAM,GAAiB,IAAI,OAArB,EAAE,UAAU,GAAK,IAAI,WAAT,CAAS;gBACnC,IAAI,MAAM,KAAK,GAAG,EAAE;oBAClB,sBAAO,EAAE,MAAM,QAAA,EAAE,UAAU,YAAA,EAAE,OAAO,EAAE,KAAK,EAAE,EAAA;iBAC9C;gBACD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A;;;KACnE;IACK,6BAAU,GAAhB,UAAiB,OAAsB;QAAtB,wBAAA,EAAA,cAAsB;;;gBACrC,sBAAO,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,EAAA;;;KACvE;IACH,eAAC;AAAD,CAAC,AApCD,IAoCC;AAED,IAAM,iBAAiB,GAAG;IACxB,OAAO,EAAE,2BAA2B;CACrC,CAAA;AACD;IAGE,mBAAY,MAAc,EAAE,OAAmB;;QAFvC,WAAM,GAAW,EAAE,CAAA;QAC3B,YAAO,GAAW,2BAA2B,CAAA;QAE3C,IAAI,KAAK,CAAC,MAAM,CAAC,EAAE;YACjB,KAAK,CAAC,sBAAsB,CAAC,CAAA;YAC7B,OAAM;SACP;QACD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,OAAO,GAAG,MAAA,OAAO,CAAC,OAAO,mCAAI,IAAI,CAAC,OAAO,CAAA;IAChD,CAAC;IACD,4BAAQ,GAAR,UAAS,UAAkB;QACzB,IAAI,KAAK,CAAC,UAAU,CAAC,EAAE;YACrB,KAAK,CAAC,0BAA0B,CAAC,CAAA;YACjC,OAAO,IAAI,CAAA;SACZ;QACD,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IAC5D,CAAC;IAGH,gBAAC;AAAD,CAAC,AApBD,IAoBC;AACD,gBAAe,UAAC,MAAc,EAAE,OAAuC;IAAvC,wBAAA,EAAA,2BAAuC;IACrE,OAAA,IAAI,SAAS,CAAC,MAAM,EAAE,OAAO,CAAC;AAA9B,CAA8B,EAAA"}
@@ -0,0 +1,19 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+
11
+ const input = {
12
+ input: {
13
+ audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
14
+ model: "base",
15
+ },
16
+ }
17
+ const result = await endpoint.runSync(input)
18
+
19
+ console.log(result)
@@ -0,0 +1,27 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+ const input = {
11
+ input: {
12
+ audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
13
+ model: "base",
14
+ },
15
+ }
16
+ const result = await endpoint.run(input)
17
+ console.log("run resp")
18
+ console.log(result)
19
+
20
+ const { id } = result
21
+ const cancelResp = await endpoint.cancel(id)
22
+ console.log("cancel resp")
23
+ console.log(cancelResp)
24
+
25
+ const statusResp = await endpoint.status(id)
26
+ console.log("status after cancellation")
27
+ console.log(statusResp)
@@ -0,0 +1,17 @@
1
+ import runpodSdk, { runpodServerlessBaseUrlDev } from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY, { baseUrl: runpodServerlessBaseUrlDev })
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+ const input = {
11
+ input: {
12
+ audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
13
+ model: "base",
14
+ },
15
+ }
16
+ const result = await endpoint.runSync(input)
17
+ console.log(result)
@@ -0,0 +1,11 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
3
+ if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint(ENDPOINT_ID)
10
+ const result = await endpoint.health()
11
+ console.log(result)
@@ -0,0 +1,11 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+ const result = await endpoint.health()
11
+ console.log(result)
@@ -0,0 +1,11 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
3
+ if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint(ENDPOINT_ID)
10
+ const result = await endpoint.purgeQueue()
11
+ console.log(result)
@@ -0,0 +1,27 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+ const input = {
11
+ input: {
12
+ audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
13
+ model: "base",
14
+ },
15
+ }
16
+ const result = await endpoint.run(input)
17
+ console.log("run response")
18
+ console.log(result)
19
+
20
+ const { id } = result
21
+ const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
22
+ for (let i = 0; i < 5; i++) {
23
+ const status = await endpoint.status(id)
24
+ console.log("status response")
25
+ console.log(status)
26
+ await sleep(1000)
27
+ }
@@ -0,0 +1,17 @@
1
+ import runpodSdk from "../dist/index.js"
2
+ const { RUNPOD_API_KEY } = process.env
3
+ if (!RUNPOD_API_KEY) {
4
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
5
+ process.exit()
6
+ }
7
+
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint("faster-whisper")
10
+ const input = {
11
+ input: {
12
+ audio: "https://github.com/runpod-workers/sample-inputs/raw/main/audio/gettysburg.wav",
13
+ model: "base",
14
+ },
15
+ }
16
+ const result = await endpoint.runSync(input, 3000)
17
+ console.log(result)
@@ -0,0 +1,48 @@
1
+ import runpodSdk from "runpod-sdk"
2
+
3
+ const { RUNPOD_API_KEY } = process.env
4
+ if (!RUNPOD_API_KEY) {
5
+ console.log("please supply RUNPOD_API_KEY as an environment variable")
6
+ process.exit()
7
+ }
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ //mock endpoint which returns whatever you specify as a stream
10
+ //with a specified delay between inputs
11
+ const endpoint = runpod.endpoint("gwp4kx5yd3nur1")
12
+
13
+ const request = {
14
+ input: {
15
+ mock_return: ["a", "b", "c", "d", "e", "f", "g"],
16
+ mock_delay: 2,
17
+ },
18
+ }
19
+ const runResp = await endpoint.run(request)
20
+ const { id } = runResp
21
+ for await (const result of endpoint.stream(id)) {
22
+ console.log(`stream yielded ${JSON.stringify(result, null, 2)}`)
23
+ }
24
+
25
+ // Expected output
26
+ /*
27
+ stream yielded {
28
+ "output": "a",
29
+ }
30
+ stream yielded {
31
+ "output": "b"
32
+ }
33
+ stream yielded {
34
+ "output": "c"
35
+ }
36
+ stream yielded {
37
+ "output": "d"
38
+ }
39
+ stream yielded {
40
+ "output": "e"
41
+ }
42
+ stream yielded {
43
+ "output": "f"
44
+ }
45
+ stream yielded {
46
+ "output": "g"
47
+ }
48
+ */
package/examples/test.js CHANGED
@@ -1,20 +1,17 @@
1
- import runpodSdk, { runpodServerlessBaseUrlDev } from "../dist/index.js"
1
+ import runpodSdk from "../dist/index.js"
2
2
 
3
- const { RUNPOD_API_KEY } = process.env
4
- if (!RUNPOD_API_KEY) {
5
- console.log("please supply RUNPOD_API_KEY as an environment variable")
3
+ const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
4
+ if (!RUNPOD_API_KEY || !ENDPOINT_ID) {
5
+ console.log("please supply RUNPOD_API_KEY and ENDPOINT_ID as an environment variable")
6
6
  process.exit()
7
7
  }
8
- //OOP
9
- const runpod = runpodSdk(RUNPOD_API_KEY, { baseUrl: runpodServerlessBaseUrlDev })
10
- const endpoint = runpod.endpoint("mock")
8
+ const runpod = runpodSdk(RUNPOD_API_KEY)
9
+ const endpoint = runpod.endpoint(ENDPOINT_ID)
10
+
11
11
  const request = {
12
12
  input: {
13
13
  prompt: "photo of a horse",
14
14
  },
15
- policy: {
16
- executionTimeout: 120 * 1000,
17
- },
18
15
  }
19
16
 
20
17
  console.log("\nrun")
@@ -22,20 +19,40 @@ const runResp = await endpoint.run(request)
22
19
  console.log(runResp)
23
20
  const { id: requestId } = runResp
24
21
  console.log("\nstatus")
25
- const statusResp = await endpoint.getStatus(requestId)
22
+ const statusResp = await endpoint.status(requestId)
26
23
  console.log(statusResp)
27
24
  console.log("\ncancel")
28
25
  const cancelResp = await endpoint.cancel(requestId)
29
26
  console.log(cancelResp)
30
27
  console.log("\nhealth")
31
- const healthResp = await endpoint.getHealth()
28
+ const healthResp = await endpoint.health()
32
29
  console.log(healthResp)
33
30
  console.log("\npurge queue")
34
31
  const purgeResp = await endpoint.purgeQueue()
35
32
  console.log(purgeResp)
36
33
  console.log("\nafter purge")
37
- console.log(await endpoint.getHealth())
34
+ console.log(await endpoint.health())
38
35
 
39
36
  console.log("runSync")
40
37
  const result = await endpoint.runSync(request)
41
38
  console.log(result)
39
+
40
+ const failingRequest = {
41
+ input: {
42
+ bogus_key: "photo of a horse",
43
+ },
44
+ }
45
+ console.log("runSync failing")
46
+ const failingResult = await endpoint.runSync(failingRequest)
47
+ console.log(failingResult)
48
+
49
+ const slowRequest = {
50
+ input: {
51
+ prompt: "photo of a horse",
52
+ num_inference_steps: 200,
53
+ },
54
+ }
55
+
56
+ console.log("runSync timed out")
57
+ const timedOutResult = await endpoint.runSync(slowRequest, 3000)
58
+ console.log(timedOutResult)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runpod-sdk",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "JavaScript SDK for Runpod",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -17,6 +17,7 @@ export type EndpointInputPayload = {
17
17
  policy?: ExecutionPolicy
18
18
  }
19
19
  export type EndpointIncompleteOutput = {
20
+ delayTime?: number
20
21
  status: string
21
22
  id: string
22
23
  }
@@ -30,6 +31,11 @@ export type EndpointCompletedOutput = {
30
31
 
31
32
  export type EndpointOutput = EndpointCompletedOutput | EndpointIncompleteOutput
32
33
 
34
+ export type EndpointStreamOutput = {
35
+ status: string
36
+ stream: [any]
37
+ }
38
+
33
39
  export type CancelOutput = {
34
40
  status: string
35
41
  id: string
@@ -58,7 +64,6 @@ const getAuthHeader = (apiKey: string) => ({
58
64
  },
59
65
  })
60
66
  const print = console.log
61
- const sleep = (ms: any) => new Promise((resolve: any) => setTimeout(resolve, ms))
62
67
 
63
68
  const handleErrors = async (axiosRequest: Promise<AxiosResponse>) => {
64
69
  const resp = await axiosRequest
@@ -77,27 +82,34 @@ const handleErrorsStatus = async (axiosRequest: Promise<AxiosResponse>) => {
77
82
  return {
78
83
  ...resp.data,
79
84
  started: true,
80
- completed: ["COMPLETED", "FAILED"].includes(resp.data.status),
85
+ completed: isCompleted(resp.data.status),
81
86
  succeeded: resp.data.status === "COMPLETED",
82
87
  }
83
88
  }
84
89
  export const runpodServerlessBaseUrlProd = "https://api.runpod.ai/v2"
85
90
  export const runpodServerlessBaseUrlDev = "https://dev-api.runpod.ai/v2"
86
91
  const getEndpointUrl = curry((baseUrl, endpointId: string) => `${baseUrl}/${endpointId}`)
92
+ const isCompleted = (status: string) =>
93
+ ["COMPLETED", "FAILED", "CANCELLED", "TIMED_OUT"].includes(status)
87
94
 
88
95
  //run and then poll status
89
96
  export const runSync = curry(
90
- async (baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => {
91
- const maxWaitTimeMs = request?.policy?.executionTimeout ?? 300 * 1000
97
+ async (
98
+ baseUrl: string,
99
+ apiKey: string,
100
+ endpointId: string,
101
+ request: EndpointInputPayload,
102
+ timeout: number = 90000
103
+ ) => {
92
104
  const startTime = Date.now()
93
- const getRemainingTime = () => clamp(1000, 90000, maxWaitTimeMs - (Date.now() - startTime))
94
- const runResp: any = await runsync(baseUrl, apiKey, endpointId, request)
105
+ const getRemainingTime = () => clamp(1000, 90000, timeout - (Date.now() - startTime))
106
+ const runResp: any = await runsync(baseUrl, apiKey, endpointId, request, timeout)
95
107
  let data: EndpointOutput = { ...runResp }
96
108
  const { id } = data
97
109
  const start = Date.now()
98
- while (!["COMPLETED", "FAILED"].includes(data.status)) {
99
- if (Date.now() - start > maxWaitTimeMs) {
100
- print(`${id} timed out after ${maxWaitTimeMs / 1000} seconds`)
110
+ while (!isCompleted(data.status)) {
111
+ if (Date.now() - start > timeout) {
112
+ print(`${id} timed out after ${timeout / 1000} seconds`)
101
113
  return { ...data, started: true, completed: false }
102
114
  }
103
115
  data = await statusSync(baseUrl, apiKey, endpointId, id, getRemainingTime())
@@ -109,64 +121,118 @@ export const runSync = curry(
109
121
 
110
122
  //wrapper over /status-sync
111
123
  const statusSync = curry(
112
- (baseUrl: string, apiKey: string, endpointId: string, requestId: String, wait: number) => {
124
+ (
125
+ baseUrl: string,
126
+ apiKey: string,
127
+ endpointId: string,
128
+ requestId: String,
129
+ timeout: number = 90000
130
+ ) => {
131
+ const wait = clamp(1000, 90000, timeout)
132
+ console.log("statusSync wait", wait)
113
133
  const url = getEndpointUrl(baseUrl, endpointId) + "/status-sync/" + requestId + `?wait=${wait}`
114
134
  const authHeader = getAuthHeader(apiKey)
115
- return handleErrorsStatus(axios.get(url, authHeader))
135
+ return handleErrorsStatus(axios.get(url, { ...authHeader }))
116
136
  }
117
137
  )
118
138
 
119
139
  //wrapper over /runsync
120
140
  const runsync = curry(
121
- (baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => {
122
- const url = getEndpointUrl(baseUrl, endpointId) + "/runsync"
141
+ (
142
+ baseUrl: string,
143
+ apiKey: string,
144
+ endpointId: string,
145
+ request: EndpointInputPayload,
146
+ timeout: number = 90000
147
+ ) => {
148
+ const wait = clamp(1000, 90000, timeout)
149
+ console.log("runsync wait:", wait)
150
+ const url = getEndpointUrl(baseUrl, endpointId) + "/runsync" + `?wait=${wait}`
123
151
  const authHeader = getAuthHeader(apiKey)
124
- return handleErrorsStatus(axios.post(url, request, authHeader))
152
+ return handleErrorsStatus(axios.post(url, request, { ...authHeader }))
125
153
  }
126
154
  )
127
155
 
128
156
  //wrapper over /run
129
157
  export const run = curry(
130
- (baseUrl: string, apiKey: string, endpointId: string, request: EndpointInputPayload) => {
158
+ (
159
+ baseUrl: string,
160
+ apiKey: string,
161
+ endpointId: string,
162
+ request: EndpointInputPayload,
163
+ timeout: number = 3000
164
+ ) => {
131
165
  const url = getEndpointUrl(baseUrl, endpointId) + "/run"
132
166
  const authHeader = getAuthHeader(apiKey)
133
- return handleErrors(axios.post(url, request, authHeader))
167
+ return handleErrors(axios.post(url, request, { ...authHeader, timeout }))
134
168
  }
135
169
  )
136
170
  //wrapper over /status
137
- export const getStatus = curry(
138
- (baseUrl: string, apiKey: string, endpointId: string, requestId: string) => {
171
+ export const status = curry(
172
+ (
173
+ baseUrl: string,
174
+ apiKey: string,
175
+ endpointId: string,
176
+ requestId: string,
177
+ timeout: number = 3000
178
+ ) => {
139
179
  const url = getEndpointUrl(baseUrl, endpointId) + "/status/" + requestId
140
180
  const authHeader = getAuthHeader(apiKey)
141
181
  return handleErrorsStatus(axios.get(url, authHeader))
142
182
  }
143
183
  )
144
- //wrapper over /stream
145
- export const stream = curry(
146
- (baseUrl: string, apiKey: string, endpointId: string, requestId: string) => {
184
+
185
+ //generator yielding results of stream
186
+ export async function* stream(
187
+ baseUrl: string,
188
+ apiKey: string,
189
+ endpointId: string,
190
+ requestId: string
191
+ ) {
192
+ let completed = false
193
+ while (!completed) {
147
194
  const url = getEndpointUrl(baseUrl, endpointId) + "/stream/" + requestId
148
195
  const authHeader = getAuthHeader(apiKey)
149
- return handleErrors(axios.get(url, authHeader))
196
+ const resp = await handleErrors(axios.get(url, authHeader))
197
+ if (isCompleted(resp.status)) {
198
+ completed = true
199
+ }
200
+ for (const output of resp?.stream) {
201
+ yield output
202
+ }
150
203
  }
151
- )
204
+ }
205
+
152
206
  //wrapper over /cancel
153
- const cancel = curry((baseUrl: string, apiKey: string, endpointId: string, requestId: string) => {
154
- const url = getEndpointUrl(baseUrl, endpointId) + "/cancel/" + requestId
155
- const authHeader = getAuthHeader(apiKey)
156
- return handleErrors(axios.post(url, {}, authHeader))
157
- })
207
+ const cancel = curry(
208
+ (
209
+ baseUrl: string,
210
+ apiKey: string,
211
+ endpointId: string,
212
+ requestId: string,
213
+ timeout: number = 3000
214
+ ) => {
215
+ const url = getEndpointUrl(baseUrl, endpointId) + "/cancel/" + requestId
216
+ const authHeader = getAuthHeader(apiKey)
217
+ return handleErrors(axios.post(url, {}, { ...authHeader, timeout }))
218
+ }
219
+ )
158
220
  //wrapper over /health
159
- export const getHealth = curry((baseUrl: string, apiKey: string, endpointId: string) => {
160
- const url = getEndpointUrl(baseUrl, endpointId) + "/health"
161
- const authHeader = getAuthHeader(apiKey)
162
- return handleErrors(axios.get(url, authHeader))
163
- })
221
+ export const health = curry(
222
+ (baseUrl: string, apiKey: string, endpointId: string, timeout: number = 3000) => {
223
+ const url = getEndpointUrl(baseUrl, endpointId) + "/health"
224
+ const authHeader = getAuthHeader(apiKey)
225
+ return handleErrors(axios.get(url, { ...authHeader, timeout }))
226
+ }
227
+ )
164
228
  //wrapper over /purge-queue
165
- export const purgeQueue = curry((baseUrl: string, apiKey: string, endpointId: string) => {
166
- const url = getEndpointUrl(baseUrl, endpointId) + "/purge-queue"
167
- const authHeader = getAuthHeader(apiKey)
168
- return handleErrors(axios.post(url, {}, authHeader))
169
- })
229
+ export const purgeQueue = curry(
230
+ (baseUrl: string, apiKey: string, endpointId: string, timeout: number = 3000) => {
231
+ const url = getEndpointUrl(baseUrl, endpointId) + "/purge-queue"
232
+ const authHeader = getAuthHeader(apiKey)
233
+ return handleErrors(axios.post(url, {}, { ...authHeader, timeout }))
234
+ }
235
+ )
170
236
 
171
237
  class Endpoint {
172
238
  endpointId: string = ""
@@ -177,26 +243,32 @@ class Endpoint {
177
243
  this.apiKey = apiKey
178
244
  this.endpointId = endpointId
179
245
  }
180
- async runSync(request: EndpointInputPayload): Promise<EndpointCompletedOutput> {
181
- return runSync(this.baseUrl, this.apiKey, this.endpointId, request)
246
+ async runSync(
247
+ request: EndpointInputPayload,
248
+ timeout: number = 90000
249
+ ): Promise<EndpointCompletedOutput> {
250
+ return runSync(this.baseUrl, this.apiKey, this.endpointId, request, timeout)
251
+ }
252
+ async run(request: EndpointInputPayload, timeout: number = 3000): Promise<string> {
253
+ return run(this.baseUrl, this.apiKey, this.endpointId, request, timeout)
182
254
  }
183
- async run(request: EndpointInputPayload): Promise<string> {
184
- return run(this.baseUrl, this.apiKey, this.endpointId, request)
255
+ async status(requestId: string, timeout: number = 3000): Promise<EndpointOutput> {
256
+ return status(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
185
257
  }
186
- async getStatus(requestId: string): Promise<EndpointOutput> {
187
- return getStatus(this.baseUrl, this.apiKey, this.endpointId, requestId)
258
+ async statusSync(requestId: string, timeout: number = 90000): Promise<EndpointOutput> {
259
+ return statusSync(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
188
260
  }
189
- async stream(requestId: string): Promise<EndpointOutput> {
261
+ stream(requestId: string): AsyncGenerator<any> {
190
262
  return stream(this.baseUrl, this.apiKey, this.endpointId, requestId)
191
263
  }
192
- async cancel(requestId: string): Promise<CancelOutput> {
193
- return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId)
264
+ async cancel(requestId: string, timeout: number = 3000): Promise<CancelOutput> {
265
+ return cancel(this.baseUrl, this.apiKey, this.endpointId, requestId, timeout)
194
266
  }
195
- async getHealth(): Promise<HealthCheck> {
196
- return getHealth(this.baseUrl, this.apiKey, this.endpointId)
267
+ async health(timeout: number = 3000): Promise<HealthCheck> {
268
+ return health(this.baseUrl, this.apiKey, this.endpointId, timeout)
197
269
  }
198
- async purgeQueue(): Promise<PurgeQueueOutput> {
199
- return purgeQueue(this.baseUrl, this.apiKey, this.endpointId)
270
+ async purgeQueue(timeout: number = 3000): Promise<PurgeQueueOutput> {
271
+ return purgeQueue(this.baseUrl, this.apiKey, this.endpointId, timeout)
200
272
  }
201
273
  }
202
274
 
package/tsconfig.json CHANGED
@@ -8,7 +8,8 @@
8
8
  "lib": ["ES2022", "DOM"],
9
9
  "strict": true,
10
10
  "esModuleInterop": true,
11
- "declaration": true
11
+ "declaration": true,
12
+ "sourceMap": true
12
13
  },
13
14
  "include": ["src/**/*.ts"]
14
15
  }
@@ -1,17 +0,0 @@
1
- import runpodSdk from "runpod-sdk"
2
-
3
- const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env
4
- if (!(RUNPOD_API_KEY && ENDPOINT_ID)) {
5
- console.log("please supply RUNPOD_API_KEY and ENDPOINT_ID as environment variables")
6
- process.exit()
7
- }
8
- const runpod = runpodSdk(RUNPOD_API_KEY)
9
- const endpoint = runpod.endpoint(ENDPOINT_ID)
10
-
11
- const result = await endpoint.runSync({
12
- input: {
13
- prompt: "photo of a horse",
14
- },
15
- })
16
-
17
- console.log(result)