runpod-sdk 1.1.1 → 1.2.0-beta.1

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.
Files changed (44) hide show
  1. package/README.md +217 -32
  2. package/dist/package.json +6 -3
  3. package/dist/src/graphql/client.d.ts +22 -0
  4. package/dist/src/graphql/client.js +75 -0
  5. package/dist/src/graphql/client.js.map +1 -0
  6. package/dist/src/graphql/generated/index.d.ts +742 -0
  7. package/dist/src/graphql/generated/index.js +347 -0
  8. package/dist/src/graphql/generated/index.js.map +1 -0
  9. package/dist/src/graphql/generated/operations.d.ts +428 -0
  10. package/dist/src/graphql/generated/operations.js +2 -0
  11. package/dist/src/graphql/generated/operations.js.map +1 -0
  12. package/dist/src/graphql/generated/sdk.d.ts +31 -0
  13. package/dist/src/graphql/generated/sdk.js +232 -0
  14. package/dist/src/graphql/generated/sdk.js.map +1 -0
  15. package/dist/src/graphql/generated/types.d.ts +4281 -0
  16. package/dist/src/graphql/generated/types.js +2 -0
  17. package/dist/src/graphql/generated/types.js.map +1 -0
  18. package/dist/src/index.d.ts +53 -8
  19. package/dist/src/index.js +202 -294
  20. package/dist/src/index.js.map +1 -1
  21. package/dist/src/pods/generated-gpu-types.d.ts +299 -0
  22. package/dist/src/pods/generated-gpu-types.js +148 -0
  23. package/dist/src/pods/generated-gpu-types.js.map +1 -0
  24. package/dist/src/pods/index.d.ts +122 -0
  25. package/dist/src/pods/index.js +242 -0
  26. package/dist/src/pods/index.js.map +1 -0
  27. package/package.json +18 -2
  28. package/schema.gql +161 -0
  29. package/.claude/settings.local.json +0 -15
  30. package/.prettierrc +0 -12
  31. package/CLAUDE.md +0 -48
  32. package/README-dev.md +0 -7
  33. package/examples/basic.js +0 -19
  34. package/examples/cancel.js +0 -27
  35. package/examples/devServerless.js +0 -17
  36. package/examples/errors.js +0 -11
  37. package/examples/health.js +0 -11
  38. package/examples/purge-queue.js +0 -11
  39. package/examples/run.js +0 -27
  40. package/examples/runSync.js +0 -17
  41. package/examples/stream.js +0 -48
  42. package/examples/test.js +0 -74
  43. package/src/index.ts +0 -328
  44. package/tsconfig.json +0 -16
@@ -0,0 +1,242 @@
1
+ import { getSdk } from '../graphql/generated/index.js';
2
+ import { GpuTypes, getGpuDisplayName, GPU_TYPES_LIST } from './generated-gpu-types.js';
3
+ // Re-export for convenience
4
+ export { GpuTypes, getGpuDisplayName, GPU_TYPES_LIST };
5
+ export class PodManager {
6
+ constructor(client) {
7
+ this.client = client;
8
+ this.sdk = getSdk(client.graphqlClient);
9
+ }
10
+ /**
11
+ * Create a pod (on-demand or interruptible)
12
+ * @param config Pod configuration
13
+ * @returns Promise<Pod>
14
+ */
15
+ async create(config) {
16
+ // Client-side validation (fail fast)
17
+ if (!config.name?.trim()) {
18
+ throw new Error('Pod name is required');
19
+ }
20
+ if (!config.imageName) {
21
+ throw new Error('Image name is required');
22
+ }
23
+ if (!config.gpuTypeId) {
24
+ throw new Error('GPU type ID is required');
25
+ }
26
+ if (config.interruptible) {
27
+ if (!config.bidPerGpu || config.bidPerGpu <= 0) {
28
+ throw new Error('bidPerGpu is required for interruptible pods');
29
+ }
30
+ return this._createInterruptible(config);
31
+ }
32
+ else {
33
+ return this._createOnDemand(config);
34
+ }
35
+ }
36
+ async _createOnDemand(config) {
37
+ const input = {
38
+ name: config.name.trim(),
39
+ imageName: config.imageName,
40
+ gpuTypeId: config.gpuTypeId,
41
+ gpuCount: config.gpuCount || 1,
42
+ volumeInGb: config.volumeInGb || 10,
43
+ volumeMountPath: config.volumeMountPath || '/workspace',
44
+ containerDiskInGb: config.containerDiskInGb || 5,
45
+ env: config.env ? Object.entries(config.env).map(([key, value]) => ({ key, value })) : undefined,
46
+ ports: config.ports,
47
+ dockerArgs: config.dockerArgs
48
+ };
49
+ const result = await this.sdk.CreateOnDemandPod({ input });
50
+ if (!result.podFindAndDeployOnDemand) {
51
+ throw new Error('Failed to create pod');
52
+ }
53
+ return result.podFindAndDeployOnDemand;
54
+ }
55
+ async _createInterruptible(config) {
56
+ const input = {
57
+ name: config.name.trim(),
58
+ imageName: config.imageName,
59
+ gpuTypeId: config.gpuTypeId,
60
+ gpuCount: config.gpuCount || 1,
61
+ volumeInGb: config.volumeInGb || 10,
62
+ volumeMountPath: config.volumeMountPath || '/workspace',
63
+ containerDiskInGb: config.containerDiskInGb || 5,
64
+ bidPerGpu: config.bidPerGpu,
65
+ env: config.env ? Object.entries(config.env).map(([key, value]) => ({ key, value })) : undefined,
66
+ ports: config.ports,
67
+ dockerArgs: config.dockerArgs
68
+ };
69
+ const result = await this.sdk.CreateInterruptablePod({ input });
70
+ if (!result.podRentInterruptable) {
71
+ throw new Error('Failed to create interruptible pod');
72
+ }
73
+ return result.podRentInterruptable;
74
+ }
75
+ /**
76
+ * @deprecated Use create() instead
77
+ */
78
+ async createOnDemand(config) {
79
+ return this.create({ ...config, interruptible: false });
80
+ }
81
+ /**
82
+ * @deprecated Use create() instead
83
+ */
84
+ async createInterruptable(config) {
85
+ return this.create({ ...config, interruptible: true });
86
+ }
87
+ /**
88
+ * Get a specific pod by ID
89
+ * @param podId Pod ID
90
+ * @returns Promise<Pod>
91
+ */
92
+ async get(podId) {
93
+ if (!podId?.trim()) {
94
+ throw new Error('Pod ID is required');
95
+ }
96
+ const result = await this.sdk.GetPod({ podId: podId.trim() });
97
+ if (!result.pod) {
98
+ throw new Error(`Pod ${podId} not found`);
99
+ }
100
+ return result.pod;
101
+ }
102
+ /**
103
+ * List all pods for the current user
104
+ * @param filters Optional filters
105
+ * @returns Promise<Pod[]>
106
+ */
107
+ async list(filters) {
108
+ const result = await this.sdk.ListMyPods();
109
+ if (!result.myself?.pods) {
110
+ return [];
111
+ }
112
+ let pods = result.myself.pods.filter((pod) => pod !== null && pod !== undefined);
113
+ // Apply filters
114
+ if (filters?.status) {
115
+ pods = pods.filter((pod) => pod.desiredStatus === filters.status);
116
+ }
117
+ if (filters?.podType) {
118
+ pods = pods.filter((pod) => pod.podType === filters.podType);
119
+ }
120
+ return pods;
121
+ }
122
+ /**
123
+ * Stop a running pod
124
+ * @param podId Pod ID
125
+ * @returns Promise<Pod>
126
+ */
127
+ async stop(podId) {
128
+ if (!podId?.trim()) {
129
+ throw new Error('Pod ID is required');
130
+ }
131
+ const result = await this.sdk.StopPod({ podId: podId.trim() });
132
+ if (!result.podStop) {
133
+ throw new Error(`Failed to stop pod ${podId}`);
134
+ }
135
+ return result.podStop;
136
+ }
137
+ /**
138
+ * Resume a stopped pod
139
+ * @param podId Pod ID
140
+ * @param gpuCount Number of GPUs to resume with
141
+ * @returns Promise<Pod>
142
+ */
143
+ async resume(podId, gpuCount = 1) {
144
+ if (!podId?.trim()) {
145
+ throw new Error('Pod ID is required');
146
+ }
147
+ if (gpuCount < 1) {
148
+ throw new Error('GPU count must be at least 1');
149
+ }
150
+ const result = await this.sdk.ResumePod({ podId: podId.trim(), gpuCount });
151
+ if (!result.podResume) {
152
+ throw new Error(`Failed to resume pod ${podId}`);
153
+ }
154
+ return result.podResume;
155
+ }
156
+ /**
157
+ * Terminate a pod (permanent deletion)
158
+ * @param podId Pod ID
159
+ * @returns Promise<void>
160
+ */
161
+ async terminate(podId) {
162
+ if (!podId?.trim()) {
163
+ throw new Error('Pod ID is required');
164
+ }
165
+ await this.sdk.TerminatePod({ podId: podId.trim() });
166
+ }
167
+ /**
168
+ * Wait for pod to reach a specific status
169
+ * @param podId Pod ID
170
+ * @param targetStatus Target status to wait for
171
+ * @param timeoutMs Timeout in milliseconds (default: 5 minutes)
172
+ * @returns Promise<Pod>
173
+ */
174
+ async waitForStatus(podId, targetStatus, timeoutMs = 300000) {
175
+ const start = Date.now();
176
+ while (Date.now() - start < timeoutMs) {
177
+ const pod = await this.get(podId);
178
+ if (pod.desiredStatus === targetStatus) {
179
+ return pod;
180
+ }
181
+ // Wait 5 seconds between checks
182
+ await new Promise(resolve => setTimeout(resolve, 5000));
183
+ }
184
+ throw new Error(`Timeout waiting for pod ${podId} to reach status ${targetStatus}`);
185
+ }
186
+ /**
187
+ * Convenience method - wait for pod to be running
188
+ * @param podId Pod ID
189
+ * @param timeoutMs Timeout in milliseconds
190
+ * @returns Promise<Pod>
191
+ */
192
+ async waitForReady(podId, timeoutMs) {
193
+ return this.waitForStatus(podId, 'RUNNING', timeoutMs);
194
+ }
195
+ /**
196
+ * Get pod runtime information (ports, GPU utilization, etc.)
197
+ * @param podId Pod ID
198
+ * @returns Promise<Pod['runtime']>
199
+ */
200
+ async getRuntime(podId) {
201
+ const pod = await this.get(podId);
202
+ return pod.runtime;
203
+ }
204
+ /**
205
+ * Check if pod is running
206
+ * @param podId Pod ID
207
+ * @returns Promise<boolean>
208
+ */
209
+ async isRunning(podId) {
210
+ const pod = await this.get(podId);
211
+ return pod.desiredStatus === 'RUNNING';
212
+ }
213
+ /**
214
+ * Get pod cost per hour
215
+ * @param podId Pod ID
216
+ * @returns Promise<number>
217
+ */
218
+ async getCostPerHour(podId) {
219
+ const pod = await this.get(podId);
220
+ return pod.costPerHr;
221
+ }
222
+ /**
223
+ * List available GPU types
224
+ * @returns Promise<GpuType[]>
225
+ */
226
+ async listGpuTypes() {
227
+ const result = await this.sdk.ListGpuTypes();
228
+ if (!result.gpuTypes) {
229
+ return [];
230
+ }
231
+ return result.gpuTypes
232
+ .filter((gpu) => gpu !== null && gpu !== undefined)
233
+ .map((gpu) => ({
234
+ id: gpu.id || '',
235
+ displayName: gpu.displayName || '',
236
+ memoryInGb: gpu.memoryInGb || 0,
237
+ secureCloud: gpu.secureCloud || false,
238
+ communityCloud: gpu.communityCloud || false
239
+ }));
240
+ }
241
+ }
242
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pods/index.ts"],"names":[],"mappings":"AACA,OAAO,EACL,MAAM,EAKP,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,QAAQ,EAAkB,iBAAiB,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAEtG,4BAA4B;AAC5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,EAAE;YAClC,UAAU,EAAE,GAAG,CAAC,UAAU,IAAI,CAAC;YAC/B,WAAW,EAAE,GAAG,CAAC,WAAW,IAAI,KAAK;YACrC,cAAc,EAAE,GAAG,CAAC,cAAc,IAAI,KAAK;SAC5C,CAAC,CAAC,CAAA;IACP,CAAC;CACF"}
package/package.json CHANGED
@@ -1,21 +1,37 @@
1
1
  {
2
2
  "name": "runpod-sdk",
3
- "version": "1.1.1",
3
+ "version": "1.2.0-beta.1",
4
4
  "description": "JavaScript SDK for Runpod",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
7
7
  "type": "module",
8
8
  "author": "Runpod",
9
9
  "dependencies": {
10
+ "graphql-request": "^7.2.0",
10
11
  "ramda": "^0.29.0",
11
12
  "xior": "^0.1.4"
12
13
  },
13
14
  "devDependencies": {
15
+ "@graphql-codegen/add": "^5.0.3",
16
+ "@graphql-codegen/cli": "^5.0.7",
17
+ "@graphql-codegen/schema-ast": "^4.1.0",
18
+ "@graphql-codegen/typescript": "^4.1.6",
19
+ "@graphql-codegen/typescript-graphql-request": "^6.3.0",
20
+ "@graphql-codegen/typescript-operations": "^4.6.1",
21
+ "@graphql-inspector/cli": "^5.0.8",
22
+ "@types/node": "^20.0.0",
14
23
  "@types/ramda": "^0.29.7",
15
24
  "dotenv": "^16.3.1",
25
+ "graphql": "^16.11.0",
16
26
  "typescript": "^5.2.2"
17
27
  },
18
28
  "scripts": {
19
- "build": "tsc"
29
+ "codegen": "graphql-codegen --config codegen.yml",
30
+ "codegen:watch": "graphql-codegen --config codegen.yml --watch",
31
+ "check:codegen": "npm run codegen && git diff --exit-code -- src/graphql/generated/ || (echo 'Generated files out of date. Run: npm run codegen' && exit 1)",
32
+ "build": "npm run codegen && tsc",
33
+ "dev": "npm run codegen:watch & tsc --watch",
34
+ "test": "echo 'No tests yet'",
35
+ "prepublishOnly": "npm run build"
20
36
  }
21
37
  }
package/schema.gql ADDED
@@ -0,0 +1,161 @@
1
+ # Public-facing RunPod GraphQL Schema
2
+ # Contains only operations exposed in the JavaScript SDK
3
+
4
+ scalar DateTime
5
+ scalar JSON
6
+ scalar JSONObject
7
+
8
+ type Query {
9
+ # User profile
10
+ myself: User
11
+
12
+ # Pod operations
13
+ pod(input: PodInput!): Pod
14
+
15
+ # GPU information
16
+ gpuTypes: [GpuType!]!
17
+ }
18
+
19
+ type Mutation {
20
+ # Pod lifecycle
21
+ podFindAndDeployOnDemand(input: PodFindAndDeployOnDemandInput!): Pod
22
+ podRentInterruptable(input: PodRentInterruptableInput!): Pod
23
+ podStop(input: PodInput!): Pod
24
+ podResume(input: PodResumeInput!): Pod
25
+ podTerminate(input: PodInput!): String
26
+ }
27
+
28
+ # Core types for public SDK
29
+ type User {
30
+ id: String
31
+ email: String
32
+ machineQuota: Int
33
+ currentSpendPerHr: Float
34
+ spendLimit: Float
35
+ referralEarned: Float
36
+ pods: [Pod!] # Missing field for ListMyPods query
37
+ }
38
+
39
+ type Pod {
40
+ id: String!
41
+ name: String!
42
+ desiredStatus: String!
43
+ imageName: String
44
+ env: [String] # String array based on dev API
45
+ machineId: String
46
+ memoryInGb: Float
47
+ vcpuCount: Float
48
+ volumeInGb: Float
49
+ volumeMountPath: String
50
+ podType: String
51
+ costPerHr: Float!
52
+ gpuCount: Int
53
+ containerDiskInGb: Int
54
+ ports: String
55
+ volumeKey: String
56
+ containerRegistryAuthId: String
57
+
58
+ # Runtime information
59
+ runtime: PodRuntime
60
+ machine: PodMachine
61
+ }
62
+
63
+ type PodRuntime {
64
+ uptimeInSeconds: Int
65
+ ports: [PodRuntimePort]
66
+ gpus: [PodRuntimeGpu]
67
+ container: PodRuntimeContainer
68
+ }
69
+
70
+ type PodRuntimePort {
71
+ ip: String
72
+ isIpPublic: Boolean
73
+ privatePort: Int
74
+ publicPort: Int
75
+ type: String
76
+ }
77
+
78
+ type PodRuntimeGpu {
79
+ id: String
80
+ gpuUtilPercent: Int
81
+ memoryUtilPercent: Int
82
+ }
83
+
84
+ type PodRuntimeContainer {
85
+ cpuPercent: Int
86
+ memoryPercent: Int
87
+ }
88
+
89
+ type PodMachine {
90
+ podHostId: String
91
+ gpuDisplayName: String
92
+ }
93
+
94
+ type GpuType {
95
+ id: String!
96
+ displayName: String!
97
+ memoryInGb: Int!
98
+ secureCloud: Boolean!
99
+ communityCloud: Boolean!
100
+ lowestPrice(input: GpuLowestPriceInput!): LowestPrice
101
+ }
102
+
103
+ type LowestPrice {
104
+ gpuName: String # Missing field
105
+ stockStatus: String
106
+ uninterruptablePrice: Float
107
+ minimumBidPrice: Float
108
+ rentedCount: Int
109
+ totalCount: Int
110
+ availableGpuCounts: [Int]
111
+ maxUnreservedGpuCount: Int # Missing field
112
+ }
113
+
114
+ # Input types
115
+ input PodInput {
116
+ podId: String!
117
+ }
118
+
119
+ input PodResumeInput {
120
+ podId: String!
121
+ gpuCount: Int!
122
+ }
123
+
124
+ input PodFindAndDeployOnDemandInput {
125
+ name: String!
126
+ imageName: String!
127
+ gpuTypeId: String!
128
+ gpuCount: Int
129
+ volumeInGb: Int
130
+ volumeMountPath: String
131
+ containerDiskInGb: Int
132
+ env: [EnvironmentVariableInput]
133
+ ports: String
134
+ dockerArgs: String
135
+ }
136
+
137
+ input PodRentInterruptableInput {
138
+ name: String!
139
+ imageName: String!
140
+ gpuTypeId: String!
141
+ gpuCount: Int
142
+ volumeInGb: Int
143
+ volumeMountPath: String
144
+ containerDiskInGb: Int
145
+ bidPerGpu: Float!
146
+ env: [EnvironmentVariableInput]
147
+ ports: String
148
+ dockerArgs: String
149
+ }
150
+
151
+ input EnvironmentVariableInput {
152
+ key: String!
153
+ value: String!
154
+ }
155
+
156
+ input GpuLowestPriceInput {
157
+ gpuCount: Int!
158
+ secureCloud: Boolean
159
+ minMemoryInGb: Int
160
+ totalDisk: Int
161
+ }
@@ -1,15 +0,0 @@
1
- {
2
- "permissions": {
3
- "allow": [
4
- "Bash(gh repo view:*)",
5
- "Bash(gh pr list:*)",
6
- "Bash(gh issue list:*)",
7
- "Bash(gh issue view:*)",
8
- "Bash(npm view:*)",
9
- "Bash(gh pr view:*)",
10
- "Bash(git pull:*)",
11
- "Bash(yarn build)"
12
- ],
13
- "deny": []
14
- }
15
- }
package/.prettierrc DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "endOfLine": "lf",
3
- "bracketSpacing": true,
4
- "printWidth": 100,
5
- "singleQuote": false,
6
- "trailingComma": "es5",
7
- "tabWidth": 2,
8
- "useTabs": false,
9
- "quoteProps": "consistent",
10
- "bracketSameLine": false,
11
- "semi": false
12
- }
package/CLAUDE.md DELETED
@@ -1,48 +0,0 @@
1
- # CLAUDE.md
2
-
3
- This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4
-
5
- ## Build Commands
6
-
7
- - `yarn build` or `npm run build` - Compile TypeScript to JavaScript in `/dist`
8
- - `tsc` - Direct TypeScript compilation
9
-
10
- ## Architecture Overview
11
-
12
- This is a JavaScript/TypeScript SDK for RunPod's serverless API. The entire SDK is contained in a single file (`src/index.ts`) with a class-based architecture:
13
-
14
- ### Core Classes
15
- - `RunpodSdk` - Main SDK class, initialized with API key and optional config
16
- - `Endpoint` - Represents a serverless endpoint, provides methods for job management
17
-
18
- ### Key Concepts
19
- - **Serverless Endpoints**: Remote compute resources identified by endpoint IDs
20
- - **Jobs/Requests**: Tasks submitted to endpoints with input payloads
21
- - **Execution Policies**: Configuration for timeouts and priority (`ExecutionPolicy` type)
22
- - **Streaming**: Some endpoints support yielding multiple results via async generators
23
-
24
- ### API Patterns
25
- - All endpoint methods accept optional `timeout` parameter (milliseconds)
26
- - Functions are curried using Ramda for partial application
27
- - Two execution modes: async (`run`) and sync with polling (`runSync`)
28
- - Status checking via polling with `/status` and `/status-sync` endpoints
29
-
30
- ### HTTP Client
31
- Uses `xior` (axios-like) for HTTP requests with custom error handling and user agent.
32
-
33
- ## Environment Configuration
34
-
35
- The SDK supports two base URLs:
36
- - Production: `https://api.runpod.ai/v2` (default)
37
- - Development: `https://dev-api.runpod.ai/v2`
38
-
39
- Configure via `SdkOptions.baseUrl` when initializing the SDK.
40
-
41
- ## Publishing
42
-
43
- From README-dev.md:
44
- ```bash
45
- yarn build # Required before publishing to refresh TypeScript definitions
46
- npm login
47
- npm publish
48
- ```
package/README-dev.md DELETED
@@ -1,7 +0,0 @@
1
- README-dev.md
2
-
3
- ```bash
4
- yarn build # if you forget this typescript type defs will not be refreshed
5
- npm login
6
- npm publish
7
- ```
package/examples/basic.js DELETED
@@ -1,19 +0,0 @@
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)
@@ -1,27 +0,0 @@
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)
@@ -1,17 +0,0 @@
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)
@@ -1,11 +0,0 @@
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)
@@ -1,11 +0,0 @@
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)
@@ -1,11 +0,0 @@
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)
package/examples/run.js DELETED
@@ -1,27 +0,0 @@
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
- }