@sogni-ai/sogni-client 4.0.0-alpha.5 → 4.0.0-alpha.50
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/CHANGELOG.md +345 -0
- package/README.md +295 -58
- package/dist/Account/index.d.ts +18 -16
- package/dist/Account/index.js +42 -21
- package/dist/Account/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.d.ts +66 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.js +332 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.js.map +1 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.d.ts +28 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js +203 -0
- package/dist/ApiClient/WebSocketClient/BrowserWebSocketClient/index.js.map +1 -0
- package/dist/ApiClient/WebSocketClient/events.d.ts +12 -0
- package/dist/ApiClient/WebSocketClient/index.d.ts +2 -2
- package/dist/ApiClient/WebSocketClient/index.js +13 -3
- package/dist/ApiClient/WebSocketClient/index.js.map +1 -1
- package/dist/ApiClient/WebSocketClient/types.d.ts +13 -0
- package/dist/ApiClient/index.d.ts +4 -4
- package/dist/ApiClient/index.js +23 -4
- package/dist/ApiClient/index.js.map +1 -1
- package/dist/Projects/Job.d.ts +44 -4
- package/dist/Projects/Job.js +83 -16
- package/dist/Projects/Job.js.map +1 -1
- package/dist/Projects/Project.d.ts +18 -0
- package/dist/Projects/Project.js +38 -10
- package/dist/Projects/Project.js.map +1 -1
- package/dist/Projects/createJobRequestMessage.d.ts +2 -1
- package/dist/Projects/createJobRequestMessage.js +173 -14
- package/dist/Projects/createJobRequestMessage.js.map +1 -1
- package/dist/Projects/index.d.ts +114 -11
- package/dist/Projects/index.js +504 -47
- package/dist/Projects/index.js.map +1 -1
- package/dist/Projects/types/ComfySamplerParams.d.ts +0 -0
- package/dist/Projects/types/ComfySamplerParams.js +2 -0
- package/dist/Projects/types/ComfySamplerParams.js.map +1 -0
- package/dist/Projects/types/EstimationResponse.d.ts +2 -0
- package/dist/Projects/types/ModelOptions.d.ts +31 -0
- package/dist/Projects/types/ModelOptions.js +56 -0
- package/dist/Projects/types/ModelOptions.js.map +1 -0
- package/dist/Projects/types/ModelTiersRaw.d.ts +67 -0
- package/dist/Projects/types/ModelTiersRaw.js +15 -0
- package/dist/Projects/types/ModelTiersRaw.js.map +1 -0
- package/dist/Projects/types/events.d.ts +5 -1
- package/dist/Projects/types/index.d.ts +201 -42
- package/dist/Projects/types/index.js +8 -0
- package/dist/Projects/types/index.js.map +1 -1
- package/dist/Projects/utils/index.d.ts +20 -0
- package/dist/Projects/utils/index.js +82 -0
- package/dist/Projects/utils/index.js.map +1 -0
- package/dist/Projects/utils/samplers.d.ts +6 -0
- package/dist/Projects/utils/samplers.js +39 -0
- package/dist/Projects/utils/samplers.js.map +1 -0
- package/dist/Projects/utils/scheduler.d.ts +6 -0
- package/dist/Projects/utils/scheduler.js +30 -0
- package/dist/Projects/utils/scheduler.js.map +1 -0
- package/dist/index.d.ts +11 -3
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/AuthManager/TokenAuthManager.js +0 -2
- package/dist/lib/AuthManager/TokenAuthManager.js.map +1 -1
- package/dist/lib/DataEntity.js +4 -2
- package/dist/lib/DataEntity.js.map +1 -1
- package/dist/lib/RestClient.js +15 -2
- package/dist/lib/RestClient.js.map +1 -1
- package/dist/lib/{utils.js → utils/index.js} +1 -1
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/validation.d.ts +31 -2
- package/dist/lib/validation.js +80 -13
- package/dist/lib/validation.js.map +1 -1
- package/package.json +4 -4
- package/src/Account/index.ts +39 -20
- package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/ChannelCoordinator.ts +426 -0
- package/src/ApiClient/WebSocketClient/BrowserWebSocketClient/index.ts +237 -0
- package/src/ApiClient/WebSocketClient/events.ts +14 -0
- package/src/ApiClient/WebSocketClient/index.ts +15 -5
- package/src/ApiClient/WebSocketClient/types.ts +16 -0
- package/src/ApiClient/index.ts +30 -8
- package/src/Projects/Job.ts +97 -16
- package/src/Projects/Project.ts +46 -13
- package/src/Projects/createJobRequestMessage.ts +234 -34
- package/src/Projects/index.ts +533 -51
- package/src/Projects/types/ComfySamplerParams.ts +0 -0
- package/src/Projects/types/EstimationResponse.ts +2 -0
- package/src/Projects/types/ModelOptions.ts +92 -0
- package/src/Projects/types/ModelTiersRaw.ts +86 -0
- package/src/Projects/types/events.ts +6 -0
- package/src/Projects/types/index.ts +235 -45
- package/src/Projects/utils/index.ts +77 -0
- package/src/Projects/utils/samplers.ts +36 -0
- package/src/Projects/utils/scheduler.ts +27 -0
- package/src/index.ts +36 -9
- package/src/lib/AuthManager/TokenAuthManager.ts +0 -2
- package/src/lib/DataEntity.ts +4 -2
- package/src/lib/RestClient.ts +16 -2
- package/src/lib/validation.ts +90 -17
- package/dist/Projects/types/SamplerParams.d.ts +0 -15
- package/dist/Projects/types/SamplerParams.js +0 -21
- package/dist/Projects/types/SamplerParams.js.map +0 -1
- package/dist/Projects/types/SchedulerParams.d.ts +0 -13
- package/dist/Projects/types/SchedulerParams.js +0 -19
- package/dist/Projects/types/SchedulerParams.js.map +0 -1
- package/dist/Projects/utils.d.ts +0 -2
- package/dist/Projects/utils.js +0 -14
- package/dist/Projects/utils.js.map +0 -1
- package/dist/lib/utils.js.map +0 -1
- package/src/Projects/types/SamplerParams.ts +0 -19
- package/src/Projects/types/SchedulerParams.ts +0 -17
- package/src/Projects/utils.ts +0 -12
- /package/dist/lib/{utils.d.ts → utils/index.d.ts} +0 -0
- /package/src/lib/{utils.ts → utils/index.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
# Sogni SDK for JavaScript & Node.js
|
|
2
|
-
This library provides an easy way to interact with the [Sogni
|
|
2
|
+
This library provides an easy way to interact with the [Sogni Supernet](https://www.sogni.ai/supernet) - a DePIN protocol for creative AI inference. It is written in TypeScript and can be used
|
|
3
3
|
in both TypeScript and JavaScript projects such as backend Node.js and browser environments.
|
|
4
4
|
|
|
5
|
-
Behind the scenes this SDK uses WebSocket connection for communication between clients, server, and workers. It harnesses an event-based API to interact with Supernet to make things super efficient.
|
|
5
|
+
Behind the scenes this SDK uses a WebSocket connection for communication between clients, server, and workers. It harnesses an event-based API to interact with Supernet to make things super efficient.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
- 🎨 **Image Generation** - Create images with the latest frontier Open Source models like Stable Diffusion, Z-Image Turbo, and Flux
|
|
9
|
+
- 🎨 **Image Edit** - Modify, merge, restyle, and transform images using prompts and/or multiple reference images using powerful models like Qwen Image Edit.
|
|
10
|
+
- 🎬 **Video Generation** - Generate videos using **Wan 2.2 14B FP8** models with five workflow types:
|
|
11
|
+
- Text-to-Video (t2v) - Generate videos from text prompts
|
|
12
|
+
- Image-to-Video (i2v) - Animate static images
|
|
13
|
+
- Sound-to-Video (s2v) - Generate videos synchronized with audio
|
|
14
|
+
- Animate-Move - Transfer motion from reference video to image subject
|
|
15
|
+
- Animate-Replace - Replace subjects in videos while preserving motion
|
|
16
|
+
- ⚡ **Fast & Relaxed Networks** - Choose between high-speed GPU network or cost-effective Mac network
|
|
17
|
+
- 🔄 **Real-time Progress** - Event-based API with progress tracking and live updates
|
|
18
|
+
- 🎯 **Advanced Controls** - Fine-tune generation with samplers, schedulers, ControlNets, and more
|
|
19
|
+
## Migration notes
|
|
20
|
+
### v3.x.x to v4.x.x
|
|
21
|
+
Version 4 adds support for video generation, including the new **Wan 2.2 14B FP8** model family with five workflow types (text-to-video, image-to-video, sound-to-video, animate-move, and animate-replace). There are the following breaking changes:
|
|
22
|
+
- `type` is required when calling `sogni.projects.create(params)`, valid values are `image` and `video`. See code examples below.
|
|
23
|
+
- `numberOfImages` renamed to `numberOfMedia`
|
|
24
|
+
- `hasResultImage` in `Job` class is now `hasResultMedia`
|
|
25
|
+
- `Job` and `Project` classes now have `type` property that can be `image` or `video`
|
|
6
26
|
|
|
7
27
|
## Installation
|
|
8
28
|
Add library to your project using npm or yarn:
|
|
@@ -23,17 +43,17 @@ Your account is tied to a [Base](https://www.base.org/) Wallet that is created d
|
|
|
23
43
|
|
|
24
44
|
### Supernet Types
|
|
25
45
|
There are 2 worker network types available:
|
|
26
|
-
- `fast` - this network runs on high-end GPUs and is optimized for speed. It is more expensive than `relaxed` network.
|
|
27
|
-
- `relaxed` - this network runs on Apple Mac devices and is optimized for cost. It is cheaper than `fast` network.
|
|
46
|
+
- `fast` - this network runs on high-end GPUs and is optimized for speed. It is more expensive than `relaxed` network. **Required for video generation**.
|
|
47
|
+
- `relaxed` - this network runs on Apple Mac devices and is optimized for cost. It is cheaper than `fast` network. Supports image generation only.
|
|
28
48
|
|
|
29
49
|
In both options, the more complex your query is (the more steps), the higher the cost in tokens.
|
|
30
50
|
|
|
31
51
|
### Inference definitions: Projects and Jobs
|
|
32
|
-
One request for image generation is called a **Project**.
|
|
33
|
-
Each image is represented by a **Job**.
|
|
52
|
+
One request for image or video generation is called a **Project**. A project can generate one or more images or videos.
|
|
53
|
+
Each generated image or video is represented by a **Job**.
|
|
34
54
|
|
|
35
|
-
When you send a project to Supernet, it will be processed by one or more workers. The resulting
|
|
36
|
-
uploaded to Sogni servers where it will be stored for 24 hours. After this period
|
|
55
|
+
When you send a project to Supernet, it will be processed by one or more workers. The resulting media will be encrypted and
|
|
56
|
+
uploaded to Sogni servers where it will be stored for 24 hours. After this period, media files will be auto-deleted.
|
|
37
57
|
|
|
38
58
|
## Client initialization
|
|
39
59
|
To initialize a client, you need to provide `appId`, and account credentials.
|
|
@@ -49,13 +69,13 @@ const options = {
|
|
|
49
69
|
network: 'fast', // Network to use, 'fast' or 'relaxed'
|
|
50
70
|
}
|
|
51
71
|
|
|
52
|
-
const
|
|
72
|
+
const sogni = await SogniClient.createInstance(options);
|
|
53
73
|
// Login to Sogni account and establish WebSocket connection to Supernet
|
|
54
|
-
await
|
|
74
|
+
await sogni.account.login(USERNAME, PASSWORD);
|
|
55
75
|
// Now wait until list of available models is received.
|
|
56
76
|
// This step is only needed if you want to create project immediately.
|
|
57
|
-
const models = await
|
|
58
|
-
// You can get list of available models any time from `
|
|
77
|
+
const models = await sogni.projects.waitForModels();
|
|
78
|
+
// You can get list of available models any time from `sogni.projects.availableModels`
|
|
59
79
|
```
|
|
60
80
|
**Important Note:**
|
|
61
81
|
- This sample assume you are using ES modules, which allow `await` on the top level, if you are CommomJS you will need to wrap `await` calls in an async function.
|
|
@@ -64,16 +84,44 @@ const models = await client.projects.waitForModels();
|
|
|
64
84
|
|
|
65
85
|
## Usage
|
|
66
86
|
After calling `login` method, the client will establish a WebSocket connection to Sogni Supernet. Within a short period of time the
|
|
67
|
-
client will receive the current balance and list of available models. After this you can start using the client to generate images.
|
|
87
|
+
client will receive the current balance and list of available models. After this you can start using the client to generate images or videos.
|
|
68
88
|
|
|
69
|
-
|
|
89
|
+
It is advised to watch for `connected` and `disconnected` events on the client instance to be notified when the connection is established or lost:
|
|
90
|
+
```typescript
|
|
91
|
+
// Will be triggered when the client is connected to Supernet
|
|
92
|
+
sogni.client.on('connected', ({network}) => {
|
|
93
|
+
console.log('Connected to Supernet:', network);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
// Will be triggered when websocket connection is lost or the client is disconnected from Supernet
|
|
97
|
+
sogni.client.on('disconnected', ({code, reason}) => {
|
|
98
|
+
console.log('Disconnected from Supernet:', code, reason);
|
|
99
|
+
});
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Image Generation
|
|
103
|
+
|
|
104
|
+
Sogni supports a wide range of models for image generation. You can find a list of available models in
|
|
105
|
+
`sogni.projects.availableModels` property during runtime or query it using `sogni.projects.getAvailableModels()` method.
|
|
106
|
+
|
|
107
|
+
For a start, you can try FLUX.1 \[schnell\] with the following parameters:
|
|
108
|
+
```javascript
|
|
109
|
+
const fluxDefaults = {
|
|
110
|
+
modelId: 'flux1-schnell-fp8',
|
|
111
|
+
steps: 4,
|
|
112
|
+
guidance: 1
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### Creating an image project
|
|
70
117
|
```javascript
|
|
71
118
|
// Find model that has the most workers
|
|
72
|
-
const mostPopularModel =
|
|
119
|
+
const mostPopularModel = sogni.projects.availableModels.reduce((a, b) =>
|
|
73
120
|
a.workerCount > b.workerCount ? a : b
|
|
74
121
|
);
|
|
75
122
|
// Create a project using the most popular model
|
|
76
|
-
const project = await
|
|
123
|
+
const project = await sogni.projects.create({
|
|
124
|
+
type: 'image',
|
|
77
125
|
modelId: mostPopularModel.id,
|
|
78
126
|
positivePrompt: 'A cat wearing a hat',
|
|
79
127
|
negativePrompt:
|
|
@@ -81,7 +129,7 @@ const project = await client.projects.create({
|
|
|
81
129
|
stylePrompt: 'anime',
|
|
82
130
|
steps: 20,
|
|
83
131
|
guidance: 7.5,
|
|
84
|
-
|
|
132
|
+
numberOfMedia: 1,
|
|
85
133
|
outputFormat: 'jpg' // Can be 'png' or 'jpg', defaults to 'png'
|
|
86
134
|
});
|
|
87
135
|
```
|
|
@@ -94,7 +142,8 @@ In general, there are 2 ways to work with API:
|
|
|
94
142
|
|
|
95
143
|
#### Using promises
|
|
96
144
|
```javascript
|
|
97
|
-
const project = await
|
|
145
|
+
const project = await sogni.projects.create({
|
|
146
|
+
type: 'image',
|
|
98
147
|
modelId: mostPopularModel.id,
|
|
99
148
|
steps: 20,
|
|
100
149
|
guidance: 7.5,
|
|
@@ -102,7 +151,7 @@ const project = await client.projects.create({
|
|
|
102
151
|
negativePrompt:
|
|
103
152
|
'malformation, bad anatomy, bad hands, missing fingers, cropped, low quality, bad quality, jpeg artifacts, watermark',
|
|
104
153
|
stylePrompt: 'anime',
|
|
105
|
-
|
|
154
|
+
numberOfMedia: 4
|
|
106
155
|
});
|
|
107
156
|
|
|
108
157
|
project.on('progress', (progress) => {
|
|
@@ -117,7 +166,8 @@ console.log('Image URLs:', imageUrls);
|
|
|
117
166
|
|
|
118
167
|
#### Using events
|
|
119
168
|
```javascript
|
|
120
|
-
const project = await
|
|
169
|
+
const project = await sogni.projects.create({
|
|
170
|
+
type: 'image',
|
|
121
171
|
modelId: mostPopularModel.id,
|
|
122
172
|
steps: 20,
|
|
123
173
|
guidance: 7.5,
|
|
@@ -125,7 +175,7 @@ const project = await client.projects.create({
|
|
|
125
175
|
negativePrompt:
|
|
126
176
|
'malformation, bad anatomy, bad hands, missing fingers, cropped, low quality, bad quality, jpeg artifacts, watermark',
|
|
127
177
|
stylePrompt: 'anime',
|
|
128
|
-
|
|
178
|
+
numberOfMedia: 4
|
|
129
179
|
});
|
|
130
180
|
|
|
131
181
|
// Fired when one of project jobs completed, you can get the resultUrl from the job
|
|
@@ -182,7 +232,7 @@ Turbo and LCM models are designed for quality output in as little as 1 step. ([M
|
|
|
182
232
|
- `disableNSFWFilter` - disable NSFW filter for this project. NSFW filter is enabled by default and workers won't upload resulting images if they are detected as NSFW.
|
|
183
233
|
- `seed` - uint32 number to use as seed. If not provided, random seed will be used. If `numberOfImages` is greater than 1, provided seed will be user only for one of them. ([More info](https://docs.sogni.ai/learn/basics/generation-seed)).
|
|
184
234
|
- `numberOfPreviews` - number of preview images to generate. If not provided, no preview images will be generated.
|
|
185
|
-
- `sampler` -
|
|
235
|
+
- `sampler` - sampler algorithm ([More info](https://docs.sogni.ai/sogni-studio/advanced/samplers-and-schedulers)). For available options, see the **"Samplers"** section below.
|
|
186
236
|
- `scheduler` - scheduler to use ([More info](https://docs.sogni.ai/sogni-studio/advanced/samplers-and-schedulers)). For available options, see the **"Schedulers"** section below.
|
|
187
237
|
- `startingImage` - guide image in PNG format. Can be [File](https://developer.mozilla.org/en-US/docs/Web/API/File), [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [Buffer](https://nodejs.org/api/buffer.html)
|
|
188
238
|
- `startingImageStrength` - strong effect of starting image should be. From 0 to 1, default 0.5.
|
|
@@ -192,9 +242,9 @@ Turbo and LCM models are designed for quality output in as little as 1 step. ([M
|
|
|
192
242
|
TypeScript type definitions for project parameters can be found in [ProjectParams](https://sdk-docs.sogni.ai/interfaces/ProjectParams.html) docs.
|
|
193
243
|
|
|
194
244
|
### Detecting available output presets
|
|
195
|
-
You can get a list of available output presets for a specific network and model using `
|
|
245
|
+
You can get a list of available output presets for a specific network and model using `sogni.projects.getOutputPresets` method.
|
|
196
246
|
```javascript
|
|
197
|
-
const presets = await
|
|
247
|
+
const presets = await sogni.projects.getSizePresets('fast', 'flux1-schnell-fp8');
|
|
198
248
|
console.log('Available output presets:', presets);
|
|
199
249
|
```
|
|
200
250
|
Sample response:
|
|
@@ -286,40 +336,42 @@ Sample response:
|
|
|
286
336
|
### Samplers
|
|
287
337
|
Samplers control the denoising process — the sequence of steps that transforms random noise into your final image.
|
|
288
338
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
| `lcm` | LCM (Latent Consistency Model) |
|
|
302
|
-
| `pndm_plms` | PNDM (Pseudo-linear multi-step) |
|
|
303
|
-
| `uni_pc` | UniPC |
|
|
304
|
-
|
|
305
|
-
**IMPORTANT:** Sampler compatibility depends on model and network. See [Samplers and Schedulers](https://docs.sogni.ai/sogni-studio/advanced/samplers-and-schedulers) docs for more info.
|
|
339
|
+
Avaliable sampler options depend on a model. You can use api to get available samplers for a specific model:
|
|
340
|
+
```javascript
|
|
341
|
+
const modelOptions = await sogni.projects.getModelOptions('flux1-schnell-fp8');
|
|
342
|
+
console.log(modelOptions.sampler);
|
|
343
|
+
/*
|
|
344
|
+
{
|
|
345
|
+
allowed: [ 'euler', 'euler_a', 'dpm_pp_2m', 'dpmpp_2m_sde', 'dpm_pp_sde' ],
|
|
346
|
+
default: 'euler'
|
|
347
|
+
}
|
|
348
|
+
*/
|
|
349
|
+
```
|
|
350
|
+
See [Samplers and Schedulers](https://docs.sogni.ai/sogni-studio/advanced/samplers-and-schedulers) docs for more info.
|
|
306
351
|
|
|
307
352
|
### Schedulers
|
|
308
353
|
Control how steps are distributed. For more info see [Schedulers and Samplers](https://docs.sogni.ai/sogni-studio/advanced/samplers-and-schedulers#schedulers) docs.
|
|
309
354
|
|
|
310
|
-
Available scheduler options:
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
355
|
+
Available scheduler options depend on a model. You can use api to get available schedulers for a specific model:
|
|
356
|
+
```javascript
|
|
357
|
+
const modelOptions = await sogni.projects.getModelOptions(modelId);
|
|
358
|
+
console.log(modelOptions.scheduler);
|
|
359
|
+
/*
|
|
360
|
+
{
|
|
361
|
+
allowed: [
|
|
362
|
+
'simple',
|
|
363
|
+
'karras',
|
|
364
|
+
'linear',
|
|
365
|
+
'sgm_uniform',
|
|
366
|
+
'beta',
|
|
367
|
+
'normal',
|
|
368
|
+
'ddim',
|
|
369
|
+
'kl_optimal'
|
|
370
|
+
],
|
|
371
|
+
default: 'simple'
|
|
372
|
+
}
|
|
373
|
+
*/
|
|
374
|
+
```
|
|
323
375
|
|
|
324
376
|
### ControlNets
|
|
325
377
|
**EXPERIMENTAL FEATURE:** This feature is still in development and may not work as expected. Use at your own risk.
|
|
@@ -356,10 +408,11 @@ To use ControlNet in your project, you need to provide `controlNet` object with
|
|
|
356
408
|
Example:
|
|
357
409
|
```javascript
|
|
358
410
|
const cnImage = fs.readFileSync('./cn.jpg');
|
|
359
|
-
const project = await
|
|
411
|
+
const project = await sogni.projects.create({
|
|
412
|
+
type: 'image',
|
|
360
413
|
network: 'fast',
|
|
361
414
|
modelId: 'coreml-cyberrealistic_v70_768',
|
|
362
|
-
|
|
415
|
+
numberOfMedia: 1,
|
|
363
416
|
positivePrompt: 'make men look older',
|
|
364
417
|
steps: 20,
|
|
365
418
|
guidance: 7.5,
|
|
@@ -400,5 +453,189 @@ export interface ControlNetParams {
|
|
|
400
453
|
```
|
|
401
454
|
|
|
402
455
|
|
|
403
|
-
##
|
|
404
|
-
|
|
456
|
+
## Video Generation with Wan 2.2 Models
|
|
457
|
+
|
|
458
|
+
The Sogni SDK supports advanced video generation workflows powered by **Wan 2.2 14B FP8** models. These models are available on the `fast` network and support various video generation workflows.
|
|
459
|
+
|
|
460
|
+
### Available Wan 2.2 Workflows
|
|
461
|
+
|
|
462
|
+
The Wan 2.2 model family supports five distinct video generation workflows:
|
|
463
|
+
|
|
464
|
+
1. **Text-to-Video (t2v)** - Generate videos from text prompts
|
|
465
|
+
2. **Image-to-Video (i2v)** - Animate a static image into a video (First and Last Frame supported)
|
|
466
|
+
3. **Sound-to-Video (s2v)** - Bring a character in an image to life with video and audio synchronization including lip syncing
|
|
467
|
+
4. **Animate-Move** - Transfer character motion and emotion from a reference video to a subject from an image into a new video
|
|
468
|
+
5. **Animate-Replace** - Replace a subject in a video while preserving motion
|
|
469
|
+
|
|
470
|
+
### Model Variants
|
|
471
|
+
|
|
472
|
+
Each workflow has two model variants optimized for different use cases:
|
|
473
|
+
|
|
474
|
+
- **Speed variant** (with `_lightx2v` suffix) - Faster inference (4-step), good quality
|
|
475
|
+
- **Quality variant** (without `_lightx2v`) - Slower inference, best quality
|
|
476
|
+
|
|
477
|
+
Example model IDs:
|
|
478
|
+
- `wan_v2.2-14b-fp8_t2v_lightx2v` (Text-to-Video, speed)
|
|
479
|
+
- `wan_v2.2-14b-fp8_t2v` (Text-to-Video, quality)
|
|
480
|
+
- `wan_v2.2-14b-fp8_i2v_lightx2v` (Image-to-Video, speed)
|
|
481
|
+
- `wan_v2.2-14b-fp8_i2v` (Image-to-Video, quality)
|
|
482
|
+
- `wan_v2.2-14b-fp8_s2v_lightx2v` (Sound-to-Video, speed)
|
|
483
|
+
- `wan_v2.2-14b-fp8_s2v` (Sound-to-Video, quality)
|
|
484
|
+
- `wan_v2.2-14b-fp8_animate-move_lightx2v` (Animate-Move, speed)
|
|
485
|
+
- `wan_v2.2-14b-fp8_animate-replace_lightx2v` (Animate-Replace, speed)
|
|
486
|
+
|
|
487
|
+
### Video Parameters
|
|
488
|
+
|
|
489
|
+
When creating video projects, you can specify:
|
|
490
|
+
|
|
491
|
+
- `fps` - Frames per second: 16 or 32 (default: 16)
|
|
492
|
+
- `frames` - Number of frames: 17-161 (default: 81, which is ~5 seconds at 16fps)
|
|
493
|
+
- `width` - Video width in pixels
|
|
494
|
+
- `height` - Video height in pixels
|
|
495
|
+
- `steps` - Increase inference steps to increase quality
|
|
496
|
+
- `seed` - Random seed for reproducibility
|
|
497
|
+
- `referenceImage` - Reference image for workflows that require it (i2v, s2v, animate-move, animate-replace)
|
|
498
|
+
- `referenceVideo` - Reference video for animate workflows (animate-move, animate-replace)
|
|
499
|
+
- `referenceAudio` - Reference audio for sound-to-video workflow
|
|
500
|
+
|
|
501
|
+
### Text-to-Video Example
|
|
502
|
+
|
|
503
|
+
```javascript
|
|
504
|
+
const project = await sogni.projects.create({
|
|
505
|
+
type: 'video',
|
|
506
|
+
network: 'fast',
|
|
507
|
+
modelId: 'wan_v2.2-14b-fp8_t2v_lightx2v',
|
|
508
|
+
positivePrompt: 'A serene ocean wave crashing on a beach at sunset',
|
|
509
|
+
fps: 16,
|
|
510
|
+
frames: 81,
|
|
511
|
+
width: 512,
|
|
512
|
+
height: 512
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
const videoUrls = await project.waitForCompletion();
|
|
516
|
+
console.log('Video URL:', videoUrls[0]);
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### Image-to-Video Example
|
|
520
|
+
|
|
521
|
+
```javascript
|
|
522
|
+
const referenceImage = fs.readFileSync('./input-image.png');
|
|
523
|
+
|
|
524
|
+
const project = await sogni.projects.create({
|
|
525
|
+
type: 'video',
|
|
526
|
+
network: 'fast',
|
|
527
|
+
modelId: 'wan_v2.2-14b-fp8_i2v_lightx2v',
|
|
528
|
+
positivePrompt: 'camera zooms in slowly',
|
|
529
|
+
referenceImage: referenceImage,
|
|
530
|
+
fps: 16,
|
|
531
|
+
frames: 81
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
const videoUrls = await project.waitForCompletion();
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
### Sound-to-Video Example
|
|
538
|
+
|
|
539
|
+
```javascript
|
|
540
|
+
const referenceImage = fs.readFileSync('./image.jpg');
|
|
541
|
+
const referenceAudio = fs.readFileSync('./audio.m4a');
|
|
542
|
+
|
|
543
|
+
const project = await sogni.projects.create({
|
|
544
|
+
type: 'video',
|
|
545
|
+
network: 'fast',
|
|
546
|
+
modelId: 'wan_v2.2-14b-fp8_s2v_lightx2v',
|
|
547
|
+
referenceImage: referenceImage,
|
|
548
|
+
referenceAudio: referenceAudio,
|
|
549
|
+
fps: 16,
|
|
550
|
+
frames: 81
|
|
551
|
+
});
|
|
552
|
+
|
|
553
|
+
const videoUrls = await project.waitForCompletion();
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
### Animate-Move Example
|
|
557
|
+
|
|
558
|
+
Transfer motion from a reference video to a subject in an image:
|
|
559
|
+
|
|
560
|
+
```javascript
|
|
561
|
+
const referenceImage = fs.readFileSync('./subject.jpg');
|
|
562
|
+
const referenceVideo = fs.readFileSync('./motion-source.mp4');
|
|
563
|
+
|
|
564
|
+
const project = await sogni.projects.create({
|
|
565
|
+
type: 'video',
|
|
566
|
+
network: 'fast',
|
|
567
|
+
modelId: 'wan_v2.2-14b-fp8_animate-move_lightx2v',
|
|
568
|
+
referenceImage: referenceImage,
|
|
569
|
+
referenceVideo: referenceVideo,
|
|
570
|
+
fps: 16,
|
|
571
|
+
frames: 81
|
|
572
|
+
});
|
|
573
|
+
|
|
574
|
+
const videoUrls = await project.waitForCompletion();
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
### Animate-Replace Example
|
|
578
|
+
|
|
579
|
+
Replace a subject in a video while preserving the original motion:
|
|
580
|
+
|
|
581
|
+
```javascript
|
|
582
|
+
const referenceImage = fs.readFileSync('./new-subject.jpg');
|
|
583
|
+
const referenceVideo = fs.readFileSync('./original-video.mp4');
|
|
584
|
+
|
|
585
|
+
const project = await sogni.projects.create({
|
|
586
|
+
type: 'video',
|
|
587
|
+
network: 'fast',
|
|
588
|
+
modelId: 'wan_v2.2-14b-fp8_animate-replace_lightx2v',
|
|
589
|
+
referenceImage: referenceImage,
|
|
590
|
+
referenceVideo: referenceVideo,
|
|
591
|
+
fps: 16,
|
|
592
|
+
frames: 81
|
|
593
|
+
});
|
|
594
|
+
|
|
595
|
+
const videoUrls = await project.waitForCompletion();
|
|
596
|
+
```
|
|
597
|
+
|
|
598
|
+
## Code Examples
|
|
599
|
+
|
|
600
|
+
The [examples](https://github.com/Sogni-AI/sogni-client/tree/main/examples) directory contains working examples for all workflows:
|
|
601
|
+
|
|
602
|
+
### Image Workflow Examples
|
|
603
|
+
- **`workflow_text_to_image.mjs`** - Text-to-image generation with multiple model options
|
|
604
|
+
- **`workflow_image_edit.mjs`** - Reference-based image generation using context images
|
|
605
|
+
|
|
606
|
+
### Video Workflow Examples
|
|
607
|
+
- **`workflow_text_to_video.mjs`** - Text-to-video generation with WAN 2.2 models
|
|
608
|
+
- **`workflow_image_to_video.mjs`** - Animate static images into videos
|
|
609
|
+
- **`workflow_sound_to_video.mjs`** - Audio-synchronized video generation with lip-sync
|
|
610
|
+
- **`workflow_video_to_video.mjs`** - Motion transfer and character replacement (Animate-Move/Animate-Replace)
|
|
611
|
+
|
|
612
|
+
### Basic Examples
|
|
613
|
+
- **`promise_based.mjs`** - Image generation using promises/async-await
|
|
614
|
+
- **`event_driven.js`** - Image generation using event listeners
|
|
615
|
+
|
|
616
|
+
### Featured Models
|
|
617
|
+
|
|
618
|
+
The workflow examples showcase a few powerful open-source frontier models supported by Sogni Supernet:
|
|
619
|
+
|
|
620
|
+
| Model ID | Description | Use Case |
|
|
621
|
+
|----------|-------------|----------|
|
|
622
|
+
| `z_image_turbo_bf16` | **Z-Image Turbo** - Ultra-fast 4-step generation | Quick text-to-image prototyping and iteration |
|
|
623
|
+
| `qwen_image_edit_2511_fp8_lightning` | **Qwen Image Edit Lightning** - Fast 4-step editing | Rapid reference-based image generation |
|
|
624
|
+
| `qwen_image_edit_2511_fp8` | **Qwen Image Edit** - High quality 20-step editing | Professional image editing with context awareness |
|
|
625
|
+
| `wan_v2.2-14b-fp8_t2v_lightx2v` | **Wan 2.2 T2V** - Text-to-video | Generate videos from text prompts |
|
|
626
|
+
|
|
627
|
+
All workflow examples include:
|
|
628
|
+
- Interactive model and parameter selection
|
|
629
|
+
- Balance checking and cost confirmation
|
|
630
|
+
- Real-time progress tracking with ETA
|
|
631
|
+
- Error handling with detailed feedback
|
|
632
|
+
- Automatic file download and preview
|
|
633
|
+
|
|
634
|
+
Run any workflow example:
|
|
635
|
+
```bash
|
|
636
|
+
cd examples
|
|
637
|
+
npm install
|
|
638
|
+
node workflow_text_to_image.mjs
|
|
639
|
+
node workflow_image_edit.mjs
|
|
640
|
+
node workflow_text_to_video.mjs
|
|
641
|
+
```
|
package/dist/Account/index.d.ts
CHANGED
|
@@ -6,11 +6,11 @@ import CurrentAccount from './CurrentAccount';
|
|
|
6
6
|
import { SupernetType } from '../ApiClient/WebSocketClient/types';
|
|
7
7
|
/**
|
|
8
8
|
* Account API methods that let you interact with the user's account.
|
|
9
|
-
* Can be accessed via `
|
|
9
|
+
* Can be accessed via `sogni.account`. Look for more samples below.
|
|
10
10
|
*
|
|
11
11
|
* @example Retrieve the current account balance
|
|
12
12
|
* ```typescript
|
|
13
|
-
* const balance = await
|
|
13
|
+
* const balance = await sogni.account.refreshBalance();
|
|
14
14
|
* console.log(balance);
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
@@ -19,6 +19,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
19
19
|
readonly currentAccount: CurrentAccount;
|
|
20
20
|
constructor(config: ApiConfig);
|
|
21
21
|
private handleBalanceUpdate;
|
|
22
|
+
private handleChangeNetwork;
|
|
22
23
|
private handleServerConnected;
|
|
23
24
|
private handleServerDisconnected;
|
|
24
25
|
private handleAuthUpdated;
|
|
@@ -35,7 +36,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
35
36
|
*
|
|
36
37
|
* @example Create a wallet from username and password
|
|
37
38
|
* ```typescript
|
|
38
|
-
* const wallet =
|
|
39
|
+
* const wallet = sogni.account.getWallet('username', 'password');
|
|
39
40
|
* console.log(wallet.address);
|
|
40
41
|
* ```
|
|
41
42
|
*
|
|
@@ -53,7 +54,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
53
54
|
*
|
|
54
55
|
* @example Login with username and password
|
|
55
56
|
* ```typescript
|
|
56
|
-
* await
|
|
57
|
+
* await sogni.account.login('username', 'password');
|
|
57
58
|
* console.log('Logged in');
|
|
58
59
|
* ```
|
|
59
60
|
*
|
|
@@ -68,7 +69,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
68
69
|
*
|
|
69
70
|
* @example Logout the user
|
|
70
71
|
* ```typescript
|
|
71
|
-
* await
|
|
72
|
+
* await sogni.account.logout();
|
|
72
73
|
* console.log('Logged out');
|
|
73
74
|
* ```
|
|
74
75
|
*/
|
|
@@ -82,7 +83,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
82
83
|
*
|
|
83
84
|
* @example Refresh user account balance
|
|
84
85
|
* ```typescript
|
|
85
|
-
* const balance = await
|
|
86
|
+
* const balance = await sogni.account.refreshBalance();
|
|
86
87
|
* console.log(balance);
|
|
87
88
|
* ```
|
|
88
89
|
*/
|
|
@@ -93,7 +94,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
93
94
|
*
|
|
94
95
|
* @example Get the account balance of the current user
|
|
95
96
|
* ```typescript
|
|
96
|
-
* const balance = await
|
|
97
|
+
* const balance = await sogni.account.accountBalance();
|
|
97
98
|
* console.log(balance);
|
|
98
99
|
* ```
|
|
99
100
|
*/
|
|
@@ -105,15 +106,16 @@ declare class AccountApi extends ApiGroup {
|
|
|
105
106
|
*
|
|
106
107
|
* @example Get the balance of the wallet address
|
|
107
108
|
* ```typescript
|
|
108
|
-
* const address =
|
|
109
|
-
* const balance = await
|
|
109
|
+
* const address = sogni.account.currentAccount.walletAddress;
|
|
110
|
+
* const balance = await sogni.account.walletBalance(address);
|
|
110
111
|
* console.log(balance);
|
|
111
112
|
* // { token: '100.000000', ether: '0.000000' }
|
|
112
113
|
* ```
|
|
113
114
|
*
|
|
114
115
|
* @param walletAddress
|
|
116
|
+
* @param provider - blockchain provider, 'base' or 'etherlink' defaults to 'base'
|
|
115
117
|
*/
|
|
116
|
-
walletBalance(walletAddress: string): Promise<{
|
|
118
|
+
walletBalance(walletAddress: string, provider?: 'base' | 'etherlink'): Promise<{
|
|
117
119
|
sogni: string;
|
|
118
120
|
spark: string;
|
|
119
121
|
ether: string;
|
|
@@ -132,9 +134,9 @@ declare class AccountApi extends ApiGroup {
|
|
|
132
134
|
*
|
|
133
135
|
* @example Switch to the fast network
|
|
134
136
|
* ```typescript
|
|
135
|
-
* await
|
|
137
|
+
* await sogni.account.switchNetwork('fast');
|
|
136
138
|
* console.log('Switched to the fast network, now lets wait until we get list of models');
|
|
137
|
-
* await
|
|
139
|
+
* await sogni.projects.waitForModels();
|
|
138
140
|
* ```
|
|
139
141
|
* @param network - Network type to switch to
|
|
140
142
|
*/
|
|
@@ -144,10 +146,10 @@ declare class AccountApi extends ApiGroup {
|
|
|
144
146
|
*
|
|
145
147
|
* @example Get the transaction history
|
|
146
148
|
* ```typescript
|
|
147
|
-
* const { entries, next } = await
|
|
149
|
+
* const { entries, next } = await sogni.account.transactionHistory({
|
|
148
150
|
* status: 'completed',
|
|
149
151
|
* limit: 10,
|
|
150
|
-
* address:
|
|
152
|
+
* address: sogni.account.currentAccount.walletAddress
|
|
151
153
|
* });
|
|
152
154
|
* ```
|
|
153
155
|
*
|
|
@@ -176,7 +178,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
176
178
|
* Withdraw funds from the current account to wallet.
|
|
177
179
|
* @example withdraw to current wallet address
|
|
178
180
|
* ```typescript
|
|
179
|
-
* await
|
|
181
|
+
* await sogni.account.withdraw('your-account-password', 100);
|
|
180
182
|
* ```
|
|
181
183
|
*
|
|
182
184
|
* @param password - account password
|
|
@@ -187,7 +189,7 @@ declare class AccountApi extends ApiGroup {
|
|
|
187
189
|
* Deposit tokens from wallet to account
|
|
188
190
|
* @example withdraw to current wallet address
|
|
189
191
|
* ```typescript
|
|
190
|
-
* await
|
|
192
|
+
* await sogni.account.deposit('your-account-password', 100);
|
|
191
193
|
* ```
|
|
192
194
|
*
|
|
193
195
|
* @param password - account password
|