|
2 | 2 |
|
3 | 3 | [](https://npmjs.org/package/@runloop/api-client)  |
4 | 4 |
|
5 | | -This library provides convenient access to the Runloop REST API from server-side TypeScript or JavaScript. |
| 5 | +This library provides convenient access to the Runloop SDK & REST API from server-side TypeScript or JavaScript. |
| 6 | + |
| 7 | +The additional documentation guides can be found at [docs.runloop.ai](https://docs.runloop.ai). The full API of this library can be found in [api.md](api.md). |
| 8 | + |
| 9 | +The **RunloopSDK** is the recommended, modern way to interact with the Runloop API. It provides high-level object-oriented interfaces for common operations while maintaining full access to the underlying REST API through the `.api` property. |
| 10 | + |
| 11 | +## Installation |
| 12 | + |
| 13 | +```sh |
| 14 | +npm install @runloop/api-client |
| 15 | +``` |
| 16 | + |
| 17 | +## Quickstart |
| 18 | + |
| 19 | +Here's a complete example that demonstrates the core SDK functionality: |
| 20 | + |
| 21 | +```typescript |
| 22 | +import { RunloopSDK } from '@runloop/api-client'; |
| 23 | + |
| 24 | +const sdk = new RunloopSDK({ |
| 25 | + bearerToken: process.env.RUNLOOP_API_KEY, // This is the default and can be omitted |
| 26 | +}); |
| 27 | + |
| 28 | +// Create a new devbox and wait for it to be ready |
| 29 | +const devbox = await sdk.devbox.create(); |
| 30 | + |
| 31 | +// Execute a synchronous command |
| 32 | +const result = await devbox.cmd.exec({ command: 'echo "Hello, World!"' }); |
| 33 | +console.log('Output:', await result.stdout()); // "Hello, World!" |
| 34 | +console.log('Exit code:', result.exitCode); // 0 |
| 35 | + |
| 36 | +// Start a long-running HTTP server asynchronously |
| 37 | +const serverExec = await devbox.cmd.execAsync({ |
| 38 | + command: 'npx http-server -p 8080', |
| 39 | +}); |
| 40 | +console.log(`Started server with execution ID: ${serverExec.executionId}`); |
| 41 | + |
| 42 | +// Check server status |
| 43 | +const state = await serverExec.getState(); |
| 44 | +console.log('Server status:', state.status); // "running" |
| 45 | + |
| 46 | +// Later... kill the server when done |
| 47 | +await serverExec.kill(); |
| 48 | + |
| 49 | +await devbox.shutdown(); |
| 50 | +``` |
| 51 | + |
| 52 | +## Core Concepts |
| 53 | + |
| 54 | +### RunloopSDK |
| 55 | + |
| 56 | +The main SDK class that provides access to all Runloop functionality: |
| 57 | + |
| 58 | +```typescript |
| 59 | +import { RunloopSDK } from '@runloop/api-client'; |
| 60 | + |
| 61 | +const sdk = new RunloopSDK({ |
| 62 | + bearerToken: 'your-api-key', |
| 63 | + // ... other options |
| 64 | +}); |
| 65 | +``` |
| 66 | + |
| 67 | +### Available Resources |
| 68 | + |
| 69 | +The SDK provides object-oriented interfaces for all major Runloop resources: |
| 70 | + |
| 71 | +- **`sdk.devbox`** - Devbox management (create, list, execute commands, file operations) |
| 72 | +- **`sdk.blueprint`** - Blueprint management (create, list, build blueprints) |
| 73 | +- **`sdk.snapshot`** - Snapshot management (list disk snapshots) |
| 74 | +- **`sdk.storageObject`** - Storage object management (upload, download, list objects) |
| 75 | +- **`sdk.api`** - Direct access to the legacy REST API client |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | + |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | + |
| 88 | + |
6 | 89 |
|
7 | | -The REST API documentation can be found on [runloop.ai](https://runloop.ai). The full API of this library can be found in [api.md](api.md). |
8 | 90 |
|
9 | | -It is generated with [Stainless](https://www.stainless.com/). |
10 | 91 |
|
11 | 92 | ## Installation |
12 | 93 |
|
|
0 commit comments