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.
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",})# Save the imagewith open("output.png", "wb") as f: f.write(result)
Parameters:
prompt (required) - Text description of the image to generate
seed (optional) - Random seed for reproducible results
Cancel long-running operations using asyncio.Event:
Copy
Ask AI
import asynciocancel_token = asyncio.Event()try: result = await client.process({ "model": models.image("lucy-pro-t2i"), "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:
Copy
Ask AI
import asynciocurrent_cancel_token: asyncio.Event | None = Noneasync def generate_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-t2i"), "prompt": prompt, "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:
Copy
Ask AI
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:
Copy
Ask AI
# 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.