-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpredictions.ts
More file actions
1538 lines (1363 loc) · 52.5 KB
/
Copy pathpredictions.ts
File metadata and controls
1538 lines (1363 loc) · 52.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../core/resource';
import { APIPromise } from '../core/api-promise';
import { RequestOptions } from '../internal/request-options';
import { path } from '../internal/utils/path';
const DEFAULT_POLL_INTERVAL = 1000;
const DEFAULT_TIMEOUT = 5 * 60 * 1000; // 5 minutes
const DEFAULT_MAX_RETRIES = 3;
const CREDITS_HEADER = 'x-fashn-credits-used';
/**
* AI prediction operations
*/
export class Predictions extends APIResource {
/**
* Submit a prediction request for AI-powered fashion processing. Supports multiple
* model types including:
*
* - Try-on max (tryon-max)
* - Virtual try-on v1.6 (tryon-v1.6)
* - Model creation (model-create)
* - Model swap (model-swap)
* - Product to model (product-to-model)
* - Face to model (face-to-model)
* - Background operations (background-remove, background-change)
* - Image reframing (reframe)
* - Image to video (image-to-video)
* - Image editing (edit)
* - Product packshot (packshot)
*
* All requests use the versioned format with model_name and inputs structure.
*
* @example
* ```ts
* const response = await client.predictions.run({
* inputs: {
* product_image: 'https://example.com/garment.jpg',
* model_image: 'https://example.com/model.jpg',
* },
* model_name: 'tryon-max',
* });
* ```
*/
run(params: PredictionRunParams, options?: RequestOptions): APIPromise<PredictionRunResponse> {
const { webhook_url, ...body } = params;
return this._client.post('/v1/run', { query: { webhook_url }, body, ...options });
}
/**
* Poll for the status of a specific prediction using its ID. Use this endpoint to
* track prediction progress and retrieve results.
*
* **Status States:**
*
* - `starting` - Prediction is being initialized
* - `in_queue` - Prediction is waiting to be processed
* - `processing` - Model is actively generating your result
* - `completed` - Generation finished successfully, output available
* - `failed` - Generation failed, check error details
*
* **Output Availability:**
*
* - **CDN URLs** (default): Available for 72 hours after completion
* - **Base64 outputs** (when `return_base64: true`): Available for 60 minutes
* after completion
*
* @example
* ```ts
* const response = await client.predictions.status(
* '123a87r9-4129-4bb3-be18-9c9fb5bd7fc1-u1',
* );
* ```
*/
status(id: string, options?: RequestOptions): APIPromise<PredictionStatusResponse> {
return this._client.get(path`/v1/status/${id}`, options);
}
/**
* Submit a prediction request and automatically poll for completion. Combines
* the `run` and `status` endpoints into a single call with real-time progress
* updates via callbacks.
*
* Polls every 1 second by default with a 5-minute timeout. Automatically stops
* polling when prediction reaches a terminal state and returns the final result.
*
* **Returned Status Values:**
* - `completed` - Generation finished successfully, output available
* - `failed` - Generation failed, check error details
* - `canceled` - Prediction was canceled
* - `time_out` - Prediction timed out
*
* Note: `starting`, `in_queue`, and `processing` statuses are only available
* via the `onQueueUpdate` callback during polling, never in the final response.
*
* @example
* ```ts
*
* const result = await client.predictions.subscribe({
* inputs: {
* model_image: 'https://example.com/model.jpg',
* garment_image: 'https://example.com/garment.jpg',
* },
* model_name: 'tryon-v1.6',
* onEnqueued: (requestId) => console.log('Started:', requestId),
* onQueueUpdate: (status) => console.log('Status:', status.status),
* });
* // result.status will be one of: 'completed', 'failed', 'canceled', 'time_out'
* ```
*/
async subscribe(
body: PredictionSubscribeParams,
options?: RequestOptions,
): Promise<PredictionSubscribeResponse> {
const response = await this._client.predictions.run(body, options);
if (body.onEnqueued) body.onEnqueued(response.id);
return this.subscribeToStatus(response.id, body, options);
}
private subscribeToStatus(
id: string,
body: PredictionSubscribeParams,
options?: RequestOptions,
): Promise<PredictionSubscribeResponse> {
return new Promise((resolve, reject) => {
const pollInterval = body.pollInterval ?? DEFAULT_POLL_INTERVAL;
const timeout = body.timeout ?? DEFAULT_TIMEOUT;
const maxRetries = body.maxRetries ?? DEFAULT_MAX_RETRIES;
let pollIntervalId: NodeJS.Timeout;
let timeoutId: NodeJS.Timeout;
const clearScheduledTasks = () => {
if (timeoutId) clearTimeout(timeoutId);
if (pollIntervalId) clearTimeout(pollIntervalId);
};
if (timeout) {
timeoutId = setTimeout(() => {
clearScheduledTasks();
// TODO: Cancel prediction on server when cancellation API is available
const timeoutStatus: PredictionSubscribeResponse = {
id,
status: 'time_out',
error: {
name: 'PollingTimeout',
message: 'Prediction polling timed out.',
},
output: null,
};
if (body.onQueueUpdate) {
body.onQueueUpdate(timeoutStatus);
}
return resolve(timeoutStatus);
}, timeout);
}
const pool = async () => {
try {
const { data: status, response } = await this._client.predictions
.status(id, {
...options,
maxRetries,
})
.withResponse();
if (body.onQueueUpdate) {
body.onQueueUpdate(status);
}
if (
status.status !== 'starting' &&
status.status !== 'in_queue' &&
status.status !== 'processing'
) {
clearScheduledTasks();
const result = { ...status } as PredictionSubscribeResponse;
const creditsUsedHeader = response.headers.get(CREDITS_HEADER);
if (creditsUsedHeader) {
result.creditsUsed = Number(creditsUsedHeader);
}
return resolve(result);
}
pollIntervalId = setTimeout(pool, pollInterval);
} catch (error) {
clearScheduledTasks();
reject(error);
}
};
pool().catch(reject);
});
}
}
export interface PredictionRunResponse {
/**
* Unique prediction identifier
*/
id: string;
/**
* Error message if prediction failed to start
*/
error: string | null;
}
export interface PredictionStatusResponse {
/**
* The unique prediction ID
*/
id: string;
/**
* Structured error object with name and message fields
*/
error: PredictionStatusResponse.Error | null;
/**
* Current status of the prediction
*/
status: 'starting' | 'in_queue' | 'processing' | 'completed' | 'failed' | 'canceled' | 'time_out';
/**
* Generated media - for images, outputs are either CDN URLs or base64 (when
* requested); for videos, outputs are CDN MP4 URLs
*/
output?: Array<string> | Array<string> | null;
}
export namespace PredictionStatusResponse {
/**
* Structured error object with name and message fields
*/
export interface Error {
/**
* Detailed error message explaining the specific failure
*/
message: string;
/**
* Error type/category with troubleshooting guidance:
*
* **ImageLoadError** - Unable to load image from provided inputs
*
* - _Cause_: Pipeline cannot load product image, model image, garment image, or
* reference image
* - _Solution_: For URLs - ensure public accessibility and correct Content-Type
* headers. For Base64 - include proper data:image/format;base64 prefix
*
* **ContentModerationError** - Prohibited content detected
*
* - _Cause_: Content moderation flagged product, garment, or model image. More
* sensitive when model_image contains an actual person (virtual try-on mode)
* - _Solution_: For try-on models - adjust moderation_level to 'permissive' or
* 'none' if appropriate. For product-to-model - explicit or inappropriate
* imagery is prohibited, particularly with real people. For intimate apparel
* (lingerie/swimwear), use FASHN Virtual Try-On endpoint with full moderation
* control. Product generation without model_image operates under more permissive
* policies. Contact support@fashn.ai with prediction ID if content was
* incorrectly flagged
*
* **PoseError** - Unable to detect body pose (try-on models only)
*
* - _Cause_: Body pose not detectable in model or garment image
* - _Solution_: Improve image quality following model photo guidelines
*
* **InputValidationError** - Invalid parameter combination (reframe only)
*
* - _Cause_: Missing required parameters or invalid values for selected mode
* - _Solution_: Ensure target_aspect_ratio is provided when mode is
* 'aspect_ratio'. Check aspect ratio values are from supported list
*
* **PipelineError** - Unexpected pipeline execution error
*
* - _Cause_: Internal processing failure
* - _Solution_: Retry request (no charge for failures). Contact support@fashn.ai
* with prediction ID if persists
*
* **ThirdPartyError** - Third-party processor failure
*
* - _Cause_: External service restrictions (content/prompt limitations)
* - _Model-specific solutions_:
* - _Try-on_: Modify image inputs for captioning restrictions
* - _Product-to-model_: Try modifying image inputs, most likely caused by
* content restrictions in image captioning
* - _Model-swap_: Try different inputs or disable prompt enhancement
* - _Background-change_: Modify image inputs or background prompt
* - _Reframe_: Try different image inputs for captioning restrictions
* - Contact support@fashn.ai with prediction ID if persists
*
* **3rdPartyProviderError** - Third-party provider failure (fallback error type)
*
* - _Cause_: External provider error without specific classification
* - _Solution_: Retry request. Contact support@fashn.ai with prediction ID if
* persists
*
* **InternalServerError** - General server error (fallback error type)
*
* - _Cause_: Unexpected server-side failure
* - _Solution_: Retry request. Contact support@fashn.ai with prediction ID if
* persists
*
* **PollingTimeout** - Prediction polling timed out
*
* - _Cause_: Prediction polling timed out
* - _Solution_: Retry request or increase the timeout parameter
*/
name: | 'ImageLoadError'
| 'ContentModerationError'
| 'PoseError'
| 'InputValidationError'
| 'PipelineError'
| 'ThirdPartyError'
| '3rdPartyProviderError'
| 'InternalServerError'
| 'PollingTimeout';
}
}
export type PredictionRunParams =
| PredictionRunParams.TryOnMaxRequest
| PredictionRunParams.TryOnRequest
| PredictionRunParams.ProductToModelRequest
| PredictionRunParams.FaceToModelRequest
| PredictionRunParams.ModelCreateRequest
| PredictionRunParams.ModelSwapRequest
| PredictionRunParams.ReframeRequest
| PredictionRunParams.BackgroundChangeRequest
| PredictionRunParams.BackgroundRemoveRequest
| PredictionRunParams.ImageToVideoRequest
| PredictionRunParams.EditRequest
| PredictionRunParams.PackshotRequest;
export declare namespace PredictionRunParams {
export interface TryOnMaxRequest {
/**
* Body param
*/
inputs: TryOnMaxRequest.Inputs;
/**
* Body param: Premium virtual try-on built for AI fashion photoshoots and
* publishable e-commerce content. Places products onto model images with enhanced
* fidelity, producing images suitable for PDPs, catalogs, and marketing assets.
*/
model_name: 'tryon-max';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace TryOnMaxRequest {
export interface Inputs {
/**
* URL or base64 encoded image of the person to wear the product. The try-on
* process preserves the model's identity, pose, and styling while seamlessly
* integrating the product. Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
model_image: string;
/**
* URL or base64 encoded image of the product (garment, accessory, etc.) to place
* on the model. Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
product_image: string;
/**
* Optional aspect ratio for the output image.
*/
aspect_ratio?: '21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16';
/**
* Sets the generation quality level. 'quality' produces the most detailed and
* realistic output but takes longer to process and costs more credits. 'fast'
* prioritizes speed and lower cost.
*/
generation_mode?: 'balanced' | 'quality';
/**
* Number of images to generate per request (1-4).
*/
num_images?: number;
/**
* Specifies the desired output image format.
*
* - `png`: Delivers the highest quality image, ideal for use cases such as content
* creation where quality is paramount.
* - `jpeg`: Provides a faster response with a slightly compressed image, more
* suitable for real-time applications.
*/
output_format?: 'png' | 'jpeg';
/**
* Optional instructions to customize the try-on result. Use this to adjust how the
* product is worn or make minor styling changes.
*
* **Examples:** "remove scarf", "tuck in shirt", "roll up sleeves", "open jacket"
*/
prompt?: string;
/**
* Resolution setting for the output image.
*/
resolution?: '1k' | '2k' | '4k';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed according to the
* `output_format` (e.g., `data:image/png;base64,...` or
* `data:image/jpeg;base64,...`). This option offers enhanced privacy as
* user-generated outputs are not stored on our servers when `return_base64` is
* enabled.
*/
return_base64?: boolean;
/**
* Sets random operations to a fixed state. Use the same seed to reproduce results
* with the same inputs, or different seed to force different results.
*/
seed?: number;
}
}
export interface TryOnRequest {
/**
* Body param
*/
inputs: TryOnRequest.Inputs;
/**
* Body param: Virtual Try-On v1.6 enables realistic garment visualization using
* just a single photo of a person and a garment
*/
model_name: 'tryon-v1.6';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace TryOnRequest {
export interface Inputs {
/**
* Reference image of the clothing item to be tried on the `model_image`. Base64
* images must include the proper prefix (e.g.,
* `data:image/jpg;base64,<YOUR_BASE64>`)
*/
garment_image: string;
/**
* Primary image of the person on whom the virtual try-on will be performed. Models
* Studio users can use their saved models by passing `saved:<model_name>`. Base64
* images must include the proper prefix (e.g.,
* `data:image/jpg;base64,<YOUR_BASE64>`)
*/
model_image: string;
/**
* Use `auto` to enable automatic classification of the garment type. For flat-lay
* or ghost mannequin images, the system detects the garment type automatically.
* For on-model images, full-body shots default to a full outfit swap. For focused
* shots (upper or lower body), the system selects the most likely garment type
* (tops or bottoms).
*/
category?: 'auto' | 'tops' | 'bottoms' | 'one-pieces';
/**
* Specifies the type of garment photo to optimize internal parameters for better
* performance. `model` is for photos of garments on a model, `flat-lay` is for
* flat-lay or ghost mannequin images, and `auto` attempts to automatically detect
* the photo type.
*/
garment_photo_type?: 'auto' | 'flat-lay' | 'model';
/**
* Specifies the mode of operation.
*
* - `performance` mode is faster but may compromise quality (5 seconds).
* - `balanced` mode is a perfect middle ground between speed and quality (8
* seconds).
* - `quality` mode is slower, but delivers the highest quality results (12–17
* seconds).
*/
mode?: 'performance' | 'balanced' | 'quality';
/**
* Sets the content moderation level for garment images.
*
* - `conservative` enforces stricter modesty standards suitable for culturally
* sensitive contexts. Blocks underwear, swimwear, and revealing outfits.
* - `permissive` allows swimwear, underwear, and revealing garments, while still
* blocking explicit nudity.
* - `none` disables all content moderation.
*
* **This technology is designed for ethical virtual try-on applications.
* Misuse—such as generating inappropriate imagery without consent—violates our
* Terms of Service. Setting moderation_level: none does not remove your
* responsibility for ethical and lawful use. Violations may result in service
* denial.**
*/
moderation_level?: 'conservative' | 'permissive' | 'none';
/**
* Number of images to generate per request (1-4).
*/
num_samples?: number;
/**
* Specifies the desired output image format.
*
* - `png`: Delivers the highest quality image, ideal for use cases such as content
* creation where quality is paramount.
* - `jpeg`: Provides a faster response with a slightly compressed image, more
* suitable for real-time applications like consumer virtual try-on experiences.
*/
output_format?: 'png' | 'jpeg';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed according to the
* `output_format` (e.g., `data:image/png;base64,...` or
* `data:image/jpeg;base64,...`). This option offers enhanced privacy as
* user-generated outputs are not stored on our servers when `return_base64` is
* enabled.
*/
return_base64?: boolean;
/**
* Sets random operations to a fixed state. Use the same seed to reproduce results
* with the same inputs, or different seed to force different results.
*/
seed?: number;
/**
* Direct garment fitting without clothing segmentation, enabling bulkier garment
* try-ons with improved preservation of body shape and skin texture. Set to
* `false` if original garments are not removed properly.
*/
segmentation_free?: boolean;
}
}
export interface ProductToModelRequest {
/**
* Body param
*/
inputs: ProductToModelRequest.Inputs;
/**
* Body param: Product to Model endpoint transforms product images into people
* wearing those products. It supports dual-mode operation: standard
* product-to-model (generates new person) and try-on mode (adds product to
* existing person)
*/
model_name: 'product-to-model';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace ProductToModelRequest {
export interface Inputs {
/**
* URL or base64 encoded image of the product to be worn. Supports clothing,
* accessories, shoes, and other wearable fashion items. Base64 images must include
* the proper prefix (e.g., data:image/jpg;base64,<YOUR_BASE64>)
*/
product_image: string;
/**
* Desired aspect ratio for the output image. Only applies when `model_image` is
* not provided (standard product-to-model mode).
*
* When `model_image` is provided (try-on mode), this parameter is ignored and the
* output will match the `model_image`'s aspect ratio.
*
* **Default:** product_image's aspect ratio (standard mode only)
*/
aspect_ratio?: '21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16';
/**
* Sets the generation quality level. 'quality' produces the most detailed and
* realistic output but takes longer to process and costs more credits. 'fast'
* prioritizes speed and lower cost.
*/
generation_mode?: 'fast' | 'balanced' | 'quality';
/**
* Optional URL or base64 of an inspiration image to guide pose, environment, and
* lighting while keeping the final edit product-centric.
*/
image_prompt?: string;
/**
* URL or base64 encoded image of the person to wear the product. When provided,
* enables try-on mode. When omitted, generates a new person wearing the product.
* Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
model_image?: string;
/**
* Specifies the desired output image format.
*
* - `png`: Delivers the highest quality image, ideal for use cases such as content
* creation where quality is paramount.
* - `jpeg`: Provides a faster response with a slightly compressed image, more
* suitable for real-time applications.
*/
output_format?: 'png' | 'jpeg';
/**
* Additional instructions for person appearance (when `model_image` is not
* provided), styling preferences, or background.
*
* **Examples:** "man with tattoos", "tucked-in", "open jacket", "rolled-up
* sleeves", "studio background", "professional office setting"
*
* **Default:** None
*/
prompt?: string;
/**
* Resolution setting for the output image.
*/
resolution?: '1k' | '2k' | '4k';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed
* `data:image/png;base64,....`
*
* This option offers enhanced privacy as user-generated outputs are not stored on
* our servers when `return_base64` is enabled.
*/
return_base64?: boolean;
/**
* Seed for reproducible results. Use the same seed to reproduce results with the
* same inputs, or different seed to force different results. Must be between 0 and
* 2^32-1.
*/
seed?: number;
}
}
export interface FaceToModelRequest {
/**
* Body param
*/
inputs: FaceToModelRequest.Inputs;
/**
* Body param: Face to Model endpoint transforms face images into try-on ready
* upper-body avatars. It converts cropped headshots or selfies into full
* upper-body representations that can be used in virtual try-on applications when
* full-body photos are not available, while preserving facial identity.
*/
model_name: 'face-to-model';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace FaceToModelRequest {
export interface Inputs {
/**
* URL or base64 encoded image of the face to transform into an upper-body avatar.
* The AI will analyze facial features, hair, and skin tone to create a
* representation suitable for virtual try-on applications.
*
* Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
face_image: string;
/**
* Desired aspect ratio for the output image. Vertical ratios (e.g. `2:3`, `3:4`,
* `9:16`) produce the most natural upper-body portraits.
*
* **Default:** `2:3`
*/
aspect_ratio?: '21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16';
/**
* Sets the generation quality level. 'quality' produces the most detailed and
* realistic output but takes longer to process and costs more credits. 'fast'
* prioritizes speed and lower cost.
*/
generation_mode?: 'fast' | 'balanced' | 'quality';
/**
* Number of images to generate in a single run.
*/
num_images?: number;
/**
* Specifies the output image format.
*
* - `png` - PNG format, original quality
* - `jpeg` - JPEG format, smaller file size
*
* **Default:** `"jpeg"`
*/
output_format?: 'png' | 'jpeg';
/**
* Optional styling or body shape guidance for the avatar representation. Examples:
* "athletic build", "curvy figure", "slender frame".
*
* If you don't provide a prompt, the body shape will be inferred from the face
* image.
*
* **Default:** Empty string
*/
prompt?: string;
/**
* Resolution setting for the output image.
*/
resolution?: '1k' | '2k' | '4k';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed
* `data:image/png;base64,...`.
*
* This option offers enhanced privacy as user-generated outputs are not stored on
* our servers when `return_base64` is enabled.
*
* **Default:** `false`
*/
return_base64?: boolean;
/**
* Sets random operations to a fixed state. Use the same seed to reproduce results
* with the same inputs, or different seed to force different results.
*/
seed?: number;
}
}
export interface ModelCreateRequest {
/**
* Body param
*/
inputs: ModelCreateRequest.Inputs;
/**
* Body param: Model creation endpoint
*/
model_name: 'model-create';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace ModelCreateRequest {
export interface Inputs {
/**
* Prompt for the model image generation. Describes the desired fashion model,
* clothing, pose, and scene.
*/
prompt: string;
/**
* Defines the width-to-height ratio of the generated image. This parameter
* controls the canvas dimensions for text-only generation. When image_reference is
* provided, the output inherits the reference image's aspect ratio and this
* parameter is ignored.
*
* **Supported Resolutions**
*
* Each aspect ratio corresponds to a specific resolution optimized for ~1MP
* output:
*
* | Aspect Ratio | Resolution | Use Case |
* | ------------ | ----------- | ----------------------------- |
* | 21:9 | 1568 × 672 | Ultra-wide cinematic |
* | 1:1 | 1024 × 1024 | Square format, social media |
* | 2:3 | 832 × 1248 | Portrait, fashion photography |
* | 3:4 | 880 × 1176 | Standard portrait |
* | 4:5 | 912 × 1144 | Instagram portrait |
* | 5:4 | 1144 × 912 | Landscape portrait |
* | 4:3 | 1176 × 880 | Traditional landscape |
* | 3:2 | 1176 × 784 | Wide landscape |
* | 16:9 | 1360 × 768 | Widescreen, banners |
* | 9:16 | 760 × 1360 | Vertical video format |
*/
aspect_ratio?: '21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16';
/**
* Optional face reference image to guide facial features in the generated model.
* When provided, the generated person will resemble the face in this image.
*
* Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
face_reference?: string;
/**
* Controls how the face reference is applied.
*
* - `match_base` adapts the reference face to match the base image's style and
* lighting.
* - `match_reference` preserves the reference face as closely as possible.
*/
face_reference_mode?: 'match_base' | 'match_reference';
/**
* Sets the generation quality level. 'quality' produces the most detailed and
* realistic output but takes longer to process and costs more credits. 'fast'
* prioritizes speed and lower cost.
*/
generation_mode?: 'fast' | 'balanced' | 'quality';
/**
* Optional reference image that guides the generation process. The model extracts
* structural information from this image to control the output composition.
*
* Processing Behavior:
*
* - Aspect Ratio: When image_reference is provided and aspect_ratio is omitted,
* the output matches the reference image's dimensions. If aspect_ratio is
* explicitly set, it overrides the reference image's proportions.
* - Image Processing: Automatically resized while preserving aspect ratio.
*
* Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
image_reference?: string;
/**
* Number of images to generate.
*/
num_images?: number;
/**
* Specifies the desired output image format.
*
* - `png`: Delivers the highest quality image, ideal for use cases such as content
* creation where quality is paramount.
* - `jpeg`: Provides a faster response with a slightly compressed image, more
* suitable for real-time applications.
*/
output_format?: 'png' | 'jpeg';
/**
* Resolution setting for the output image.
*/
resolution?: '1k' | '2k' | '4k';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed according to the
* `output_format` (e.g., `data:image/png;base64,...` or
* `data:image/jpeg;base64,...`). This option offers enhanced privacy as
* user-generated outputs are not stored on our servers when `return_base64` is
* enabled.
*/
return_base64?: boolean;
/**
* Sets random operations to a fixed state. Use the same seed to reproduce results
* with the same inputs, or different seed to force different results.
*/
seed?: number;
}
}
export interface ModelSwapRequest {
/**
* Body param
*/
inputs: ModelSwapRequest.Inputs;
/**
* Body param: Model swap endpoint for transforming model identity while preserving
* clothing and pose
*/
model_name: 'model-swap';
/**
* Query param: Optional webhook URL to receive completion notifications
*/
webhook_url?: string;
}
export namespace ModelSwapRequest {
export interface Inputs {
/**
* Source fashion model image containing the clothing and pose to preserve. The
* model's identity (face, skin tone, hair) will be transformed while keeping the
* outfit exactly as shown. Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
model_image: string;
/**
* Optional aspect ratio for the output image.
*/
aspect_ratio?: '21:9' | '1:1' | '4:3' | '3:2' | '2:3' | '5:4' | '4:5' | '3:4' | '16:9' | '9:16';
/**
* Optional face reference image to guide facial features of the replacement
* person. When provided, the new person will resemble the face in this image.
*
* Base64 images must include the proper prefix (e.g.,
* data:image/jpg;base64,<YOUR_BASE64>)
*/
face_reference?: string;
/**
* Controls how the face reference is applied.
*
* - `match_base` adapts the reference face to match the base image's style and
* lighting.
* - `match_reference` preserves the reference face as closely as possible.
*/
face_reference_mode?: 'match_base' | 'match_reference';
/**
* Sets the generation quality level. 'quality' produces the most detailed and
* realistic output but takes longer to process and costs more credits. 'fast'
* prioritizes speed and lower cost.
*/
generation_mode?: 'fast' | 'balanced' | 'quality';
/**
* Number of images to generate.
*/
num_images?: number;
/**
* Specifies the desired output image format.
*
* - `png`: Delivers the highest quality image, ideal for use cases such as content
* creation where quality is paramount.
* - `jpeg`: Provides a faster response with a slightly compressed image, more
* suitable for real-time applications.
*/
output_format?: 'png' | 'jpeg';
/**
* Description of the desired model identity transformation. Specify ethnicity,
* facial features, hair color, and other physical characteristics.
*
* **Default: Empty string (Random identity change)**
*/
prompt?: string;
/**
* Resolution setting for the output image.
*/
resolution?: '1k' | '2k' | '4k';
/**
* When set to `true`, the API will return the generated image as a base64-encoded
* string instead of a CDN URL. The base64 string will be prefixed according to the
* `output_format` (e.g., `data:image/png;base64,...` or
* `data:image/jpeg;base64,...`). This option offers enhanced privacy as
* user-generated outputs are not stored on our servers when `return_base64` is
* enabled.
*/
return_base64?: boolean;
/**
* Sets random operations to a fixed state. Use the same seed to reproduce results
* with the same inputs, or different seed to force different results.
*/
seed?: number;
}
}
export interface ReframeRequest {
/**
* Body param
*/
inputs: ReframeRequest.Inputs;
/**
* Body param: Image reframing endpoint
*/