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.
Cancel long-running operations using asyncio.Event:
import asynciocancel_token = asyncio.Event()try: result = await client.process({ "model": models.image("lucy-pro-i2i"), "prompt": "Epic fantasy landscape with dragons", "cancel_token": cancel_token, })except asyncio.CancelledError: print("Generation cancelled")# Cancel the request from another coroutinecancel_token.set()
You can use this to implement cancel buttons in your UI:
import asynciocurrent_cancel_token: asyncio.Event | None = Noneasync def edit_image(prompt: str): global current_cancel_token # Cancel previous request if any if current_cancel_token: current_cancel_token.set() current_cancel_token = asyncio.Event() result = await client.process({ "model": models.image("lucy-pro-i2i"), "prompt": prompt, "data": image_file, "cancel_token": current_cancel_token, }) return resultdef cancel_generation(): if current_cancel_token: current_cancel_token.set()
The SDK raises specific exception classes for different failure scenarios:
from decart import ( DecartClient, InvalidInputError, InvalidAPIKeyError, ProcessingError, DecartSDKError,)try: with open("image.jpg", "rb") as image_file: result = await client.process({ "model": models.image("lucy-pro-i2i"), "prompt": "Transform this image", "data": image_file, })except InvalidInputError as error: print(f"Invalid input: {error.message}")except InvalidAPIKeyError as error: print("Invalid API key - check your credentials")except ProcessingError as error: print(f"Processing failed: {error.message}")except DecartSDKError as error: # Catch-all for any other SDK errors print(f"SDK error: {error.message}")
Exception Types:
InvalidAPIKeyError - API key is invalid or missing
InvalidBaseURLError - Base URL is malformed
InvalidInputError - Invalid input parameters or validation failed
ProcessingError - Server-side processing error
ModelNotFoundError - Specified model doesn’t exist
DecartSDKError - Base class for all SDK errors
If you provide invalid inputs, you’ll get clear error messages:
# Missing required fieldawait client.process({ "model": models.image("lucy-pro-i2i"), "prompt": "test", # Missing 'data' field})# Raises InvalidInputError: Invalid inputs for lucy-pro-i2i: data is required
Import specific exception types for better error handling and type safety.