> ## Documentation Index
> Fetch the complete documentation index at: https://docs.platform.decart.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Process API

> Transform images on-demand

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.

<Note>
  For video processing (video editing, motion control), use the [Queue API](/sdks/javascript-queue) which provides asynchronous job-based processing.
</Note>

## Image

### Image Editing

Transform and restyle existing images:

```typescript theme={null}
const imageFile = document.querySelector('input[type="file"]').files[0];

const result = await client.process({
  model: models.image("lucy-image-2"),
  prompt: "Oil painting style with impressionist brushstrokes",
  data: imageFile,
  enhance_prompt: true,
  seed: 123,
});
```

You can also provide a reference image to guide the edit — for example, to add a specific item:

```typescript theme={null}
const imageFile = document.querySelector('input[type="file"]').files[0];
const referenceImage = document.querySelector('#reference-input').files[0];

const result = await client.process({
  model: models.image("lucy-image-2"),
  prompt: "Add these sunglasses to the person's face",
  data: imageFile,
  reference_image: referenceImage,
});
```

**Parameters:**

* `prompt` (required) - Text description of the style transformation
* `data` (required) - Input image (File, Blob, URL, or ReadableStream)
* `reference_image` (optional) - Reference image to guide the edit (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-image-2`

***

## Input Types

The `data`, `reference_image`, `start`, and `end` parameters accept flexible input types:

```typescript theme={null}
type FileInput = File | Blob | ReadableStream | URL | string;
```

**Examples:**

```typescript theme={null}
// 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:

```typescript theme={null}
const controller = new AbortController();

try {
  const result = await client.process({
    model: models.image("lucy-image-2"),
    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:

```typescript theme={null}
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-image-2"),
    prompt,
    data: imageFile,
    signal: currentController.signal,
  });

  return result;
}

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

## Error Handling

The SDK throws specific errors for different failure scenarios:

```typescript theme={null}
import { createDecartClient, type DecartSDKError } from "@decartai/sdk";

try {
  const result = await client.process({
    model: models.image("lucy-image-2"),
    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:

```typescript theme={null}
// Missing required field
await client.process({
  model: models.image("lucy-image-2"),
  prompt: "test",
  // Missing 'data' field
});
// Error: Invalid inputs for lucy-image-2: 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:**

<Accordion title="Image Editing (lucy-image-2)">
  * `prompt: string` - Style description (required)
  * `data: FileInput` - Input image (required)
  * `reference_image?: FileInput` - Reference image to guide the edit
  * `seed?: number` - Random seed
  * `resolution?: string` - Output resolution
  * `enhance_prompt?: boolean` - Auto-enhance prompt
</Accordion>

## Next Steps

<CardGroup cols={2}>
  <Card title="Queue API" icon="video" href="/sdks/javascript-queue">
    Asynchronous video processing with job-based queue
  </Card>

  <Card title="Realtime API" icon="bolt" href="/sdks/javascript-realtime">
    Transform video streams in realtime with WebRTC
  </Card>
</CardGroup>
