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

Image

Image Generation

Generate images from text prompts:
const result = await client.process({
  model: models.image("lucy-pro-t2i"),
  prompt: "A futuristic cityscape at night with neon lights",
  seed: 42,
  orientation: "portrait",
  resolution: "720p",
});

const img = document.querySelector("img");
img.src = URL.createObjectURL(result);
Parameters:
  • prompt (required) - Text description of the image to generate
  • seed (optional) - Random seed for reproducible results
  • resolution (optional) - Output resolution
  • orientation (optional) - Output orientation (“landscape”, “portrait”)
Model: lucy-pro-t2i

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-t2i"),
    prompt: "Epic fantasy landscape with dragons",
    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 generateImage(prompt: string) {
  // Cancel previous request if any
  currentController?.abort();

  currentController = new AbortController();

  const result = await client.process({
    model: models.image("lucy-pro-t2i"),
    prompt,
    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 - Text description (required)
  • seed?: number - Random seed
  • resolution?: string - Output resolution
  • orientation?: string - Output orientation
  • 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