Skip to main content
The Process API enables you to transform existing images with style transfer and edits. Perfect for building content creation tools, media processing pipelines, batch transformations, and creative applications.
For video processing (video editing, motion control), use the Queue API which provides asynchronous job-based processing.

Image

Image Editing

Transform and restyle existing images:
const imageFile = document.querySelector('input[type="file"]').files[0];

const result = await client.process({
  model: models.image("lucy-pro-i2i"),
  prompt: "Oil painting style with impressionist brushstrokes",
  data: imageFile,
  enhance_prompt: true,
  seed: 123,
});
Parameters:
  • prompt (required) - Text description of the style transformation
  • data (required) - Input image (File, Blob, URL, or ReadableStream)
  • seed (optional) - Random seed for reproducible results
  • resolution (optional) - Output resolution
  • enhance_prompt (optional) - Auto-enhance the prompt for better results
Model: lucy-pro-i2i

Input Types

The data, start, and end parameters accept flexible input types:
type FileInput = File | Blob | ReadableStream | URL | string;
Examples:
// Browser file input
const file = document.querySelector('input[type="file"]').files[0];

// Blob
const blob = new Blob([arrayBuffer], { type: 'image/jpeg' });

// URL string
const url = "https://example.com/image.jpg";

// URL object
const urlObj = new URL("https://example.com/video.mp4");

// ReadableStream (advanced)
const stream = response.body;

Cancellation

Cancel long-running operations using AbortController:
const controller = new AbortController();

try {
  const result = await client.process({
    model: models.image("lucy-pro-i2i"),
    prompt: "Transform into epic fantasy landscape with dragons",
    data: imageFile,
    signal: controller.signal,
  });
} catch (error) {
  if (error.name === 'AbortError') {
    console.log('Generation cancelled');
  }
}

// Cancel the request
controller.abort();
You can use this to implement cancel buttons in your UI:
let currentController: AbortController | null = null;

async function editImage(prompt: string) {
  // Cancel previous request if any
  currentController?.abort();

  currentController = new AbortController();

  const result = await client.process({
    model: models.image("lucy-pro-i2i"),
    prompt,
    data: imageFile,
    signal: currentController.signal,
  });

  return result;
}

function cancelGeneration() {
  currentController?.abort();
}

Error Handling

The SDK throws specific errors for different failure scenarios:
import { createDecartClient, type DecartSDKError } from "@decartai/sdk";

try {
  const result = await client.process({
    model: models.image("lucy-pro-i2i"),
    prompt: "Oil painting style with impressionist brushstrokes",
    data: imageFile,
  });
} catch (error) {
  const sdkError = error as DecartSDKError;

  switch (sdkError.code) {
    case "INVALID_INPUT":
      console.error("Invalid input:", sdkError.message);
      break;
    case "INVALID_API_KEY":
      console.error("Invalid API key");
      break;
    case "PROCESSING_ERROR":
      console.error("Processing failed:", sdkError.message);
      break;
    default:
      console.error("Unknown error:", sdkError.message);
  }
}
If you provide invalid inputs, you’ll get clear error messages:
// Missing required field
await client.process({
  model: models.image("lucy-pro-i2i"),
  prompt: "test",
  // Missing 'data' field
});
// Error: Invalid inputs for lucy-pro-i2i: data is required

API Reference

client.process(options)

Generate or transform images. Parameters:
  • options - Configuration object with model and inputs:
    • model - Model from models.image()
    • signal? - Optional AbortSignal for cancellation
    • Additional fields depend on the model (see below)
Returns: Promise<Blob> - The generated/transformed image Inputs by Model:
  • prompt: string - Style description (required)
  • data: FileInput - Input image (required)
  • seed?: number - Random seed
  • resolution?: string - Output resolution
  • enhance_prompt?: boolean - Auto-enhance prompt

Next Steps

Queue API

Asynchronous video processing with job-based queue

Realtime API

Transform video streams in realtime with WebRTC