Operations
Description
Operations represent asynchronous tasks in the system. They can be created, monitored, and updated. The system supports various operation types like image generation, uploading, upscaling, and more.
Methods
create
Contains methods for creating different types of operations:
create.describeProduct()
- Creates a product description operationcreate.generate()
- Creates an image generation operationcreate.imagine()
- Creates an imagination operationcreate.proposePrompt()
- Creates a prompt proposal operationcreate.replaceArea()
- Creates an area replacement operationcreate.select()
- Creates a selection operationcreate.upload()
- Creates an upload operationcreate.upscale()
- Creates an upscale operation
Each creation method accepts the following props:
Name | Type | Required | Description |
---|---|---|---|
input | any | Yes | The input data for the operation |
metadata | any | No | Additional metadata for the operation |
Returns
Promise<Operation<Input, Output>>
- The created operation object
Example
const operation = await client.operations.create.generate({
input: {
aspectRatio: '1:1',
productImageId: '123',
prompt: 'Woman in a red dress on a red background',
quality: 'high',
seed: sdk.utils.seed(),
version: 1,
},
});
get
Retrieves a single operation by its ID.
Props
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The operation's ID |
Returns
Promise<Operation<any, any> | undefined>
- The operation object if found
Example
const operation = await client.operations.get({ id: '123' });
getMany
Retrieves multiple operations by their IDs.
Props
Name | Type | Required | Description |
---|---|---|---|
ids | string[] | Yes | Array of operation IDs to get |
Returns
Promise<Operation<any, any>[]>
- Array of operation objects
Example
const operations = await client.operations.getMany({ ids: ['123', '456'] });
list
Lists operations with optional pagination.
Props
Name | Type | Required | Description |
---|---|---|---|
lastId | string | No | ID of the last item for pagination |
limit | number | No | Maximum number of items to return |
Returns
Promise<Operation<any, any>[]>
- Array of operation objects
Example
const operations = await client.operations.list({ lastId: '123', limit: 10 });
update
Updates an existing operation.
Props
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The operation's ID |
metadata | any | No | Updated metadata for operation |
Returns
Promise<void>
Example
await client.operations.update({ id: '123', metadata: { message: 'Hello, world!' } });
wait
Waits for an operation to complete.
Props
Name | Type | Required | Description |
---|---|---|---|
id | string | Yes | The operation's ID to wait for |
timeoutInSeconds | number | No | Timeout in seconds (defaults to 360) |
Returns
Promise<Operation<any, any>>
- The completed operation object
Example
const operation = await client.operations.wait({ id: '123' });
updates
Provides real-time updates for operations through subscription methods:
updates.subscribe()
- Subscribe to operation updatesupdates.unsubscribe()
- Unsubscribe from operation updates
Example
const listen = (operation: Operation<any, any>) => {
console.log(operation);
};
client.operations.updates.subscribe(listen);
client.operations.updates.unsubscribe(listen);
Types
Operation
Represents an operation in the system with its status and associated data.
Name | Type | Description |
---|---|---|
id | string | Unique identifier for the operation |
type | OperationType | The type of operation (e.g. 'generate', 'upscale') |
status | 'pending' | 'finished' | 'failed' | Current status of the operation |
input | Input | Input data provided when creating the operation |
output | Output | null | Result data (null while pending or failed) |
metadata | any | Additional metadata associated with the operation |
createdAt | Date | Timestamp when the operation was created |
updatedAt | Date | Timestamp when the operation was last updated |
Type Parameters
Parameter | Description |
---|---|
Input | The type of input data specific to the operation type |
Output | The type of output data (extends OperationOutput) for results |
Operation Input Types
Each operation type has its own specific input requirements:
describeProduct
Input for creating product descriptions:
Name | Type | Description |
---|---|---|
imageId | string | ID of the image to describe |
generate
Input for image generation:
Name | Type | Description |
---|---|---|
aspectRatio | AspectRatio | Desired aspect ratio ('1:1', '9:7', etc.) |
productImageId | string | ID of the product image to generate from |
prompt | string | Text prompt for image generation |
quality | 'low' | 'high' | Quality of the generated image |
seed | number | Seed for randomness |
version | 1 | 2 | Version of inference model to use |
imagine
Input for imagination operations:
Name | Type | Description |
---|---|---|
aspectRatio | AspectRatio | Desired aspect ratio |
prompt | string | Text prompt for imagination |
seed | number | Seed for randomness |
proposePrompt
Input for prompt proposals:
Name | Type | Description |
---|---|---|
productDescription | string | Description of the product to propose a prompt for |
imageId | string | ID of the image to propose a prompt for |
replaceArea
Input for area replacement:
Name | Type | Description |
---|---|---|
imageId | string | ID of the image to modify |
maskImageId | string | Mask image ID |
prompt | string | Text prompt for the replacement |
strength | number | Strength of the replacement |
retouch
Input for area replacement:
Name | Type | Description |
---|---|---|
category | 'bottom' | 'dress' | 'top' | Category of the area to replace |
imageId | string | ID of the image to modify |
productDescription | string | Description of the product to use for the replacement |
productImageId | string | ID of the product image to use for the replacement |
seed | number | Seed for randomness |
select
Input for selection operations:
Name | Type | Description |
---|---|---|
imageId | string | ID of the image to select |
upload
Input for upload operations:
Name | Type | Description |
---|---|---|
imageId | string | ID of the uploaded image |
upscale
Input for upscaling:
Name | Type | Description |
---|---|---|
imageId | string | ID of the image to upscale |
Operation Output Types
Operations can return three types of outputs:
OperationOutputImageSingle
Output containing a single image:
Name | Type | Description |
---|---|---|
kind | 'image/single' | Kind identifier |
imageId | string | ID of the generated/processed image |
OperationOutputImageMultiple
Output containing multiple images:
Name | Type | Description |
---|---|---|
kind | 'image/multiple' | Kind identifier |
imageIds | string[] | Array of image IDs |
previewImageId | string | ID of the preview image |
OperationOutputText
Output containing text:
Name | Type | Description |
---|---|---|
kind | 'text' | Kind identifier |
text | string | The output text |
Each operation type returns a specific output type:
describeProduct
: OperationOutputTextgenerate
: OperationOutputImageSingleimagine
: OperationOutputImageMultipleproposePrompt
: OperationOutputTextreplaceArea
: OperationOutputImageSingleretouch
: OperationOutputImageSingleselect
: OperationOutputImageSingleupload
: OperationOutputImageSingleupscale
: OperationOutputImageSingle