runpod-sdk 1.1.2 → 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 (41) hide show
  1. package/README.md +217 -32
  2. package/dist/src/graphql/client.d.ts +22 -0
  3. package/dist/src/graphql/client.js +75 -0
  4. package/dist/src/graphql/client.js.map +1 -0
  5. package/dist/src/graphql/generated/index.d.ts +742 -0
  6. package/dist/src/graphql/generated/index.js +347 -0
  7. package/dist/src/graphql/generated/index.js.map +1 -0
  8. package/dist/src/graphql/generated/operations.d.ts +428 -0
  9. package/dist/src/graphql/generated/operations.js +2 -0
  10. package/dist/src/graphql/generated/operations.js.map +1 -0
  11. package/dist/src/graphql/generated/sdk.d.ts +31 -0
  12. package/dist/src/graphql/generated/sdk.js +232 -0
  13. package/dist/src/graphql/generated/sdk.js.map +1 -0
  14. package/dist/src/graphql/generated/types.d.ts +4281 -0
  15. package/dist/src/graphql/generated/types.js +2 -0
  16. package/dist/src/graphql/generated/types.js.map +1 -0
  17. package/dist/src/index.d.ts +53 -8
  18. package/dist/src/index.js +73 -9
  19. package/dist/src/index.js.map +1 -1
  20. package/dist/src/pods/generated-gpu-types.d.ts +299 -0
  21. package/dist/src/pods/generated-gpu-types.js +148 -0
  22. package/dist/src/pods/generated-gpu-types.js.map +1 -0
  23. package/dist/src/pods/index.d.ts +122 -0
  24. package/dist/src/pods/index.js +242 -0
  25. package/dist/src/pods/index.js.map +1 -0
  26. package/package.json +16 -2
  27. package/schema.gql +161 -0
  28. package/.prettierrc +0 -12
  29. package/README-dev.md +0 -7
  30. package/examples/basic.js +0 -19
  31. package/examples/cancel.js +0 -27
  32. package/examples/devServerless.js +0 -17
  33. package/examples/errors.js +0 -11
  34. package/examples/health.js +0 -11
  35. package/examples/purge-queue.js +0 -11
  36. package/examples/run.js +0 -27
  37. package/examples/runSync.js +0 -17
  38. package/examples/stream.js +0 -48
  39. package/examples/test.js +0 -74
  40. package/src/index.ts +0 -330
  41. package/tsconfig.json +0 -17
package/README.md CHANGED
@@ -1,23 +1,154 @@
1
- # js-sdk
1
+ # RunPod JavaScript SDK
2
2
 
3
- JavaScript client sdk for runpod
3
+ [![npm version](https://img.shields.io/npm/v/runpod-sdk.svg)](https://www.npmjs.com/package/runpod-sdk)
4
4
 
5
- # Example Usage
5
+ Official JavaScript SDK for [RunPod](https://runpod.io) - GPU cloud computing platform
6
6
 
7
- ```js
8
- const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env;
9
- import runpodSdk from "runpod-sdk";
7
+ ## 🚀 Features
8
+
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
14
+
15
+ ## 📦 Installation
16
+
17
+ ```bash
18
+ npm install runpod-sdk
19
+ ```
10
20
 
11
- const runpod = runpodSdk(RUNPOD_API_KEY);
12
- const endpoint = runpod.endpoint(ENDPOINT_ID);
21
+ ## 🎯 Quick Start
22
+
23
+ ```typescript
24
+ import RunPod from 'runpod-sdk'
25
+
26
+ const runpod = new RunPod('your-api-key')
27
+
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')
13
38
  const result = await endpoint.runSync({
14
- input: {
15
- prompt: "a photo of a horse the size of a Boeing 787",
16
- },
17
- });
39
+ input: { prompt: "Hello AI!" }
40
+ })
18
41
  ```
19
42
 
20
- # Using Endpoints
43
+ ## 🖥️ Pod Management
44
+
45
+ Create and manage GPU pods programmatically:
46
+
47
+ ### Creating Pods
48
+
49
+ ```typescript
50
+ import runpod, { GpuTypes } from 'runpod-sdk'
51
+
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
+ })
74
+ ```
75
+
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' })
82
+
83
+ // Get specific pod
84
+ const pod = await runpod.pods.get('pod-id')
85
+
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}`)
94
+ ```
95
+
96
+ ### Pod Information
97
+
98
+ ```typescript
99
+ // Check pod status
100
+ const isRunning = await runpod.pods.isRunning('pod-id')
101
+ const costPerHour = await runpod.pods.getCostPerHour('pod-id')
102
+
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
+ ```
144
+
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)
150
+
151
+ ## ⚡ Serverless Endpoints
21
152
 
22
153
  Once an endpoint has been created, you can send requests to the queue:
23
154
 
@@ -89,29 +220,83 @@ const result = await endpoint.runSync({
89
220
  },
90
221
  }, 5000);
91
222
  ```
223
+
92
224
  will timeout after 5 seconds.
93
225
 
94
- Note that this is the timeout on the *local* function call, not the underlying request in the queue. So this:
226
+ ## 🔧 Account & Resources
95
227
 
96
- ```js
97
- const result = await endpoint.run({
98
- input: {
99
- prompt: "a photo of a horse the size of a Boeing 787",
100
- },
101
- }, 3000);
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))
102
237
  ```
103
238
 
104
- 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.
239
+ ## 🌍 Configuration
105
240
 
106
- To affect the maximum time a request can take on the backend, you can provide a policy in the request input:
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
+ })
107
249
 
108
- ```js
109
- const result = await endpoint.run({
110
- input: {
111
- prompt: "a photo of a horse the size of a Boeing 787",
112
- },
113
- policy: {
114
- executionTimeout: 3000,
115
- }
116
- });
117
- ```
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)
270
+ ```
271
+
272
+ ---
273
+
274
+ ## 🤝 Contributing
275
+
276
+ We welcome contributions! This SDK uses GraphQL Code Generator for type-safe operations.
277
+
278
+ ### Development Setup
279
+
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
293
+ ```
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.
@@ -0,0 +1,22 @@
1
+ import { GraphQLClient } from 'graphql-request';
2
+ import { Variables } from 'graphql-request';
3
+ export interface GraphQLConfig {
4
+ apiKey: string;
5
+ baseUrl?: string;
6
+ timeout?: number;
7
+ retries?: number;
8
+ }
9
+ export declare class RunPodGraphQLClient {
10
+ private client;
11
+ private config;
12
+ get graphqlClient(): GraphQLClient;
13
+ constructor(config: GraphQLConfig);
14
+ request<T = any, V extends Variables = Variables>(query: string, variables?: V, options?: {
15
+ retries?: number;
16
+ }): Promise<T>;
17
+ private isClientError;
18
+ private wrapError;
19
+ private sleep;
20
+ updateApiKey(apiKey: string): void;
21
+ setEndpoint(url: string): void;
22
+ }
@@ -0,0 +1,75 @@
1
+ import { GraphQLClient } from 'graphql-request';
2
+ export class RunPodGraphQLClient {
3
+ // Expose client for SDK usage
4
+ get graphqlClient() {
5
+ return this.client;
6
+ }
7
+ constructor(config) {
8
+ this.config = {
9
+ baseUrl: 'https://api.runpod.io/graphql',
10
+ timeout: 30000,
11
+ retries: 3,
12
+ ...config
13
+ };
14
+ this.client = new GraphQLClient(this.config.baseUrl, {
15
+ headers: {
16
+ 'Authorization': `Bearer ${this.config.apiKey}`,
17
+ 'Content-Type': 'application/json',
18
+ },
19
+ });
20
+ }
21
+ async request(query, variables, options) {
22
+ const maxRetries = options?.retries ?? this.config.retries;
23
+ let lastError;
24
+ for (let attempt = 0; attempt < maxRetries; attempt++) {
25
+ try {
26
+ return await this.client.request(query, variables);
27
+ }
28
+ catch (error) {
29
+ lastError = error;
30
+ // Don't retry on client errors (4xx)
31
+ if (this.isClientError(error)) {
32
+ throw this.wrapError(error);
33
+ }
34
+ // Exponential backoff for retries
35
+ if (attempt < maxRetries - 1) {
36
+ await this.sleep(Math.pow(2, attempt) * 1000);
37
+ }
38
+ }
39
+ }
40
+ throw this.wrapError(lastError);
41
+ }
42
+ isClientError(error) {
43
+ return error?.response?.status >= 400 && error?.response?.status < 500;
44
+ }
45
+ wrapError(error) {
46
+ if (error?.response?.errors?.[0]) {
47
+ const gqlError = error.response.errors[0];
48
+ const wrappedError = new Error(gqlError.message);
49
+ wrappedError.name = 'GraphQLError';
50
+ Object.assign(wrappedError, {
51
+ code: gqlError.extensions?.code,
52
+ originalError: error
53
+ });
54
+ return wrappedError;
55
+ }
56
+ return error;
57
+ }
58
+ sleep(ms) {
59
+ return new Promise(resolve => setTimeout(resolve, ms));
60
+ }
61
+ updateApiKey(apiKey) {
62
+ this.config.apiKey = apiKey;
63
+ this.client.setHeader('Authorization', `Bearer ${apiKey}`);
64
+ }
65
+ setEndpoint(url) {
66
+ this.config.baseUrl = url;
67
+ this.client = new GraphQLClient(url, {
68
+ headers: {
69
+ 'Authorization': `Bearer ${this.config.apiKey}`,
70
+ 'Content-Type': 'application/json',
71
+ },
72
+ });
73
+ }
74
+ }
75
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/graphql/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAU/C,MAAM,OAAO,mBAAmB;IAI9B,8BAA8B;IAC9B,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAA;IACpB,CAAC;IAED,YAAY,MAAqB;QAC/B,IAAI,CAAC,MAAM,GAAG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