Skip to main content

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 operation
  • create.generate() - Creates an image generation operation
  • create.imagine() - Creates an imagination operation
  • create.proposePrompt() - Creates a prompt proposal operation
  • create.replaceArea() - Creates an area replacement operation
  • create.select() - Creates a selection operation
  • create.upload() - Creates an upload operation
  • create.upscale() - Creates an upscale operation

Each creation method accepts the following props:

NameTypeRequiredDescription
inputanyYesThe input data for the operation
metadataanyNoAdditional 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

NameTypeRequiredDescription
idstringYesThe 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

NameTypeRequiredDescription
idsstring[]YesArray 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

NameTypeRequiredDescription
lastIdstringNoID of the last item for pagination
limitnumberNoMaximum 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

NameTypeRequiredDescription
idstringYesThe operation's ID
metadataanyNoUpdated 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

NameTypeRequiredDescription
idstringYesThe operation's ID to wait for
timeoutInSecondsnumberNoTimeout 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 updates
  • updates.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.

NameTypeDescription
idstringUnique identifier for the operation
typeOperationTypeThe type of operation (e.g. 'generate', 'upscale')
status'pending' | 'finished' | 'failed'Current status of the operation
inputInputInput data provided when creating the operation
outputOutput | nullResult data (null while pending or failed)
metadataanyAdditional metadata associated with the operation
createdAtDateTimestamp when the operation was created
updatedAtDateTimestamp when the operation was last updated

Type Parameters

ParameterDescription
InputThe type of input data specific to the operation type
OutputThe 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:

NameTypeDescription
imageIdstringID of the image to describe

generate

Input for image generation:

NameTypeDescription
aspectRatioAspectRatioDesired aspect ratio ('1:1', '9:7', etc.)
productImageIdstringID of the product image to generate from
promptstringText prompt for image generation
quality'low' | 'high'Quality of the generated image
seednumberSeed for randomness
version1 | 2Version of inference model to use

imagine

Input for imagination operations:

NameTypeDescription
aspectRatioAspectRatioDesired aspect ratio
promptstringText prompt for imagination
seednumberSeed for randomness

proposePrompt

Input for prompt proposals:

NameTypeDescription
productDescriptionstringDescription of the product to propose a prompt for
imageIdstringID of the image to propose a prompt for

replaceArea

Input for area replacement:

NameTypeDescription
imageIdstringID of the image to modify
maskImageIdstringMask image ID
promptstringText prompt for the replacement
strengthnumberStrength of the replacement

retouch

Input for area replacement:

NameTypeDescription
category'bottom' | 'dress' | 'top'Category of the area to replace
imageIdstringID of the image to modify
productDescriptionstringDescription of the product to use for the replacement
productImageIdstringID of the product image to use for the replacement
seednumberSeed for randomness

select

Input for selection operations:

NameTypeDescription
imageIdstringID of the image to select

upload

Input for upload operations:

NameTypeDescription
imageIdstringID of the uploaded image

upscale

Input for upscaling:

NameTypeDescription
imageIdstringID of the image to upscale

Operation Output Types

Operations can return three types of outputs:

OperationOutputImageSingle

Output containing a single image:

NameTypeDescription
kind'image/single'Kind identifier
imageIdstringID of the generated/processed image

OperationOutputImageMultiple

Output containing multiple images:

NameTypeDescription
kind'image/multiple'Kind identifier
imageIdsstring[]Array of image IDs
previewImageIdstringID of the preview image

OperationOutputText

Output containing text:

NameTypeDescription
kind'text'Kind identifier
textstringThe output text

Each operation type returns a specific output type:

  • describeProduct: OperationOutputText
  • generate: OperationOutputImageSingle
  • imagine: OperationOutputImageMultiple
  • proposePrompt: OperationOutputText
  • replaceArea: OperationOutputImageSingle
  • retouch: OperationOutputImageSingle
  • select: OperationOutputImageSingle
  • upload: OperationOutputImageSingle
  • upscale: OperationOutputImageSingle