> ## 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/swift-queue) which provides asynchronous job-based processing.
</Note>

## Image Editing

Transform and restyle existing images:

```swift theme={null}
import Foundation
import DecartSDK

let imageData = try Data(contentsOf: imageURL)
let input = try ImageToImageInput(
    prompt: "Oil painting style with impressionist brushstrokes",
    data: .image(data: imageData),
    enhancePrompt: true,
    seed: 123
)

let processClient = try client.createProcessClient(
    model: .lucy_image_2,
    input: input
)

let result = try await processClient.process()
// result is Data containing the transformed image
```

**`ImageToImageInput` parameters:**

* `prompt` (required) - Text description of the style transformation
* `data` (required) - Input image as `FileInput`
* `seed` (optional) - Random seed for reproducible results
* `resolution` (optional) - Output resolution (`.res720p` or `.res480p`)
* `enhancePrompt` (optional) - Auto-enhance the prompt for better results

**Model:** `lucy_image_2`

***

## Input Types

The `FileInput` type provides static factory methods for creating inputs:

```swift theme={null}
// From image data
let imageInput = try FileInput.image(data: imageData, filename: "image.jpg")

// From video data
let videoInput = try FileInput.video(data: videoData, filename: "video.mp4")

// Auto-detect from UTType
let input = try FileInput.from(data: fileData, uniformType: .jpeg)
```

***

## Error Handling

```swift theme={null}
do {
    let processClient = try client.createProcessClient(
        model: .lucy_image_2,
        input: input
    )
    let result = try await processClient.process()
} catch let error as DecartError {
    switch error {
    case .invalidAPIKey:
        print("Invalid API key - check your credentials")
    case .invalidInput(let message):
        print("Invalid input: \(message)")
    case .processingError(let message):
        print("Processing failed: \(message)")
    case .networkError(let underlying):
        print("Network error: \(underlying)")
    default:
        print("Error: \(error.localizedDescription)")
    }
}
```

**Error Cases:**

* `.invalidAPIKey` - API key is invalid or missing
* `.invalidInput(String)` - Invalid input parameters or validation failed
* `.processingError(String)` - Server-side processing error
* `.modelNotFound(String)` - Specified model doesn't exist
* `.networkError(Error)` - Network request failed

***

## Complete Example

```swift theme={null}
import DecartSDK
import UIKit

func editImage() async throws {
    let config = DecartConfiguration(apiKey: "your-api-key-here")
    let client = DecartClient(decartConfiguration: config)

    // Load image
    guard let image = UIImage(named: "input"),
          let imageData = image.jpegData(compressionQuality: 0.9) else {
        return
    }

    // Create input
    let input = try ImageToImageInput(
        prompt: "Transform to watercolor style",
        data: .image(data: imageData),
        resolution: .res720p,
        enhancePrompt: true
    )

    // Process
    let processClient = try client.createProcessClient(
        model: .lucy_image_2,
        input: input
    )
    let resultData = try await processClient.process()

    // Use the result
    if let resultImage = UIImage(data: resultData) {
        // Display or save the transformed image
        print("Image transformed successfully")
    }
}
```

***

## API Reference

### `client.createProcessClient(model:input:)`

Creates a process client for image editing.

**Parameters:**

* `model: ImageModel` - Image model (`.lucy_image_2`)
* `input: ImageToImageInput` - Image editing input

**Returns:** `ProcessClient`

**Throws:** `DecartError` if the model URL cannot be constructed

***

### `processClient.process()`

Sends the image for processing and returns the result.

**Returns:** `Data` - The transformed image bytes

**Throws:** `DecartError` on network or processing failure

***

## Next Steps

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

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