chutes-js 1.0.1 → 1.0.2
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 +47 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,6 @@ A lightweight, functional JavaScript SDK for consuming [Chutes.ai](https://chute
|
|
|
5
5
|
- **Zero dependencies** – Built on native `fetch` and `AsyncGenerator`
|
|
6
6
|
- **Streaming support** – First-class SSE parsing for chat/LLM responses
|
|
7
7
|
- **Universal** – Works in Node.js 18+, Cloudflare Workers, and browsers
|
|
8
|
-
- **TypeScript-ready** – Full JSDoc types for IntelliSense
|
|
9
8
|
|
|
10
9
|
## Installation
|
|
11
10
|
|
|
@@ -27,28 +26,27 @@ const response = await client.chat({
|
|
|
27
26
|
});
|
|
28
27
|
console.log(response.choices[0].message.content);
|
|
29
28
|
|
|
30
|
-
// 2.
|
|
31
|
-
const
|
|
32
|
-
model: '
|
|
33
|
-
|
|
29
|
+
// 2. Image Generation (uses image.chutes.ai)
|
|
30
|
+
const blob = await client.image({
|
|
31
|
+
model: 'qwen-image',
|
|
32
|
+
prompt: 'A beautiful sunset'
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const result = await client.invoke(
|
|
43
|
-
{ name: 'Wan-2.2-I2V-14B-Fast', username: 'chutes' },
|
|
44
|
-
'/run',
|
|
45
|
-
{ prompt: 'A cat playing piano', image_b64: '...' }
|
|
46
|
-
);
|
|
47
|
-
console.log('Job ID:', result.job_id);
|
|
35
|
+
// 3. Video Generation (Hybrid: supports both Sync and Async)
|
|
36
|
+
const result = await client.video({
|
|
37
|
+
model: 'wan-2-2-i2v-14b-fast',
|
|
38
|
+
prompt: 'A cat playing piano',
|
|
39
|
+
image: 'base64_data_here...'
|
|
40
|
+
});
|
|
48
41
|
|
|
49
|
-
//
|
|
50
|
-
|
|
51
|
-
|
|
42
|
+
// Check if we got a Blob (sync) or a Job ID (async)
|
|
43
|
+
if (result instanceof Blob) {
|
|
44
|
+
await saveBlob(result, './video.mp4');
|
|
45
|
+
} else {
|
|
46
|
+
// We got a Job ID, poll for status
|
|
47
|
+
const status = await client.getJobStatus(result.job_id);
|
|
48
|
+
console.log('Job Status:', status.state);
|
|
49
|
+
}
|
|
52
50
|
```
|
|
53
51
|
|
|
54
52
|
## API Reference
|
|
@@ -60,7 +58,10 @@ Creates a new Chutes client.
|
|
|
60
58
|
| Option | Type | Default | Description |
|
|
61
59
|
|--------|------|---------|-------------|
|
|
62
60
|
| `apiKey` | `string` | *required* | Your Chutes API key |
|
|
63
|
-
| `timeout` | `number` | `60000` |
|
|
61
|
+
| `timeout` | `number` | `60000` | Default timeout in ms (Note: Video/Audio have higher defaults) |
|
|
62
|
+
|
|
63
|
+
> [!TIP]
|
|
64
|
+
> You can access `client.endpoints` to see the base URLs being used by the client.
|
|
64
65
|
|
|
65
66
|
---
|
|
66
67
|
|
|
@@ -104,6 +105,9 @@ import { saveBlob } from 'chutes-js';
|
|
|
104
105
|
await saveBlob(blob, './output.png');
|
|
105
106
|
```
|
|
106
107
|
|
|
108
|
+
> [!IMPORTANT]
|
|
109
|
+
> `saveBlob` is a Node.js utility. When using the SDK in browsers or Cloudflare Workers, handle the `Blob` response using native platform APIs.
|
|
110
|
+
|
|
107
111
|
| Option | Type | Default | Description |
|
|
108
112
|
|--------|------|---------|-------------|
|
|
109
113
|
| `model` | `string` | *required* | Model ID (e.g., `qwen-image`) |
|
|
@@ -127,16 +131,22 @@ import { readFileSync } from 'fs';
|
|
|
127
131
|
// For I2V models, provide a base64 image
|
|
128
132
|
const imageBase64 = readFileSync('./input.png').toString('base64');
|
|
129
133
|
|
|
130
|
-
const
|
|
134
|
+
const result = await client.video({
|
|
131
135
|
model: 'wan-2-2-i2v-14b-fast',
|
|
132
136
|
prompt: 'A cat playing piano',
|
|
133
|
-
image: imageBase64,
|
|
137
|
+
image: imageBase64,
|
|
134
138
|
resolution: '480p',
|
|
135
139
|
fps: 16,
|
|
136
140
|
frames: 81
|
|
137
141
|
});
|
|
138
142
|
|
|
139
|
-
|
|
143
|
+
if (result instanceof Blob) {
|
|
144
|
+
// 1. Synchronous: Video returned directly
|
|
145
|
+
await saveBlob(result, './output.mp4');
|
|
146
|
+
} else {
|
|
147
|
+
// 2. Asynchronous: Job ID returned
|
|
148
|
+
console.log('Job started:', result.job_id);
|
|
149
|
+
}
|
|
140
150
|
```
|
|
141
151
|
|
|
142
152
|
| Option | Type | Default | Description |
|
|
@@ -153,6 +163,9 @@ await saveBlob(blob, './output.mp4');
|
|
|
153
163
|
| `guidance_scale_2` | `number` | `1` | Secondary guidance scale |
|
|
154
164
|
| `negative_prompt` | `string` | - | Negative prompt |
|
|
155
165
|
|
|
166
|
+
> [!NOTE]
|
|
167
|
+
> Video generation has a default timeout of **5 minutes** (300,000ms).
|
|
168
|
+
|
|
156
169
|
> **Note**: All methods accept additional parameters via spread (`...extra`) for model-specific options.
|
|
157
170
|
|
|
158
171
|
---
|
|
@@ -192,6 +205,9 @@ await saveBlob(audio2, './output.wav');
|
|
|
192
205
|
| `voice` | `string` | - | Voice ID (Kokoro models) |
|
|
193
206
|
| `speed` | `number` | `1.0` | Speaking speed (Kokoro models) |
|
|
194
207
|
|
|
208
|
+
> [!NOTE]
|
|
209
|
+
> Audio generation has a default timeout of **2 minutes** (120,000ms).
|
|
210
|
+
|
|
195
211
|
---
|
|
196
212
|
|
|
197
213
|
### Invoke Methods (subdomain-based chutes)
|
|
@@ -199,6 +215,8 @@ await saveBlob(audio2, './output.wav');
|
|
|
199
215
|
For models using subdomain URLs (`chutes-{model}.chutes.ai`) not covered by built-in methods.
|
|
200
216
|
|
|
201
217
|
> **Note**: Some image models use subdomain URLs instead of `image.chutes.ai`. Use `invoke()` for these.
|
|
218
|
+
>
|
|
219
|
+
> `invoke()` returns a `Blob` if the `Content-Type` is an image, `JSON` if it's `application/json`, or `string` otherwise.
|
|
202
220
|
|
|
203
221
|
#### `client.invoke(target, path, payload)`
|
|
204
222
|
|
|
@@ -229,7 +247,11 @@ const video = await client.invoke(
|
|
|
229
247
|
|
|
230
248
|
#### `client.invokeStream(target, path, payload)`
|
|
231
249
|
|
|
232
|
-
For streaming responses from custom chutes.
|
|
250
|
+
For streaming responses from custom chutes. Returns an `AsyncGenerator`.
|
|
251
|
+
|
|
252
|
+
#### `parseSSE(stream)`
|
|
253
|
+
|
|
254
|
+
The internal SSE parser is exported for custom streaming implementations.
|
|
233
255
|
|
|
234
256
|
---
|
|
235
257
|
|