Generate and transform videos and images on-demand
The Process API enables you to generate videos and images from text, or transform existing media with style transfer. Perfect for building content creation tools, media processing pipelines, batch transformations, and creative applications.
result = await client.process({ "model": models.video("lucy-pro-t2v"), "prompt": "A serene lake at sunset with mountains in the background", "seed": 42, "resolution": "720p", "orientation": "landscape",})# Save the videowith open("output.mp4", "wb") as f: f.write(result)
Parameters:
prompt (required) - Text description of the video to generate
seed (optional) - Random seed for reproducible results
# Using a file pathwith open("image.jpg", "rb") as image_file: result = await client.process({ "model": models.video("lucy-pro-i2v"), "prompt": "Animate with gentle motion and wind", "data": image_file, "seed": 123, "resolution": "720p", })
Parameters:
prompt (required) - Text description of the animation style
data (required) - Input image (file object, bytes, or URL)
seed (optional) - Random seed for reproducible results
# Using a file pathwith open("video.mp4", "rb") as video_file: result = await client.process({ "model": models.video("lucy-pro-v2v"), "prompt": "Convert to anime style with vibrant colors", "data": video_file, "enhance_prompt": True, "num_inference_steps": 50, })
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.video("lucy-pro-t2v"), "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_video(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.video("lucy-pro-t2v"), "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.video("lucy-pro-i2v"), "prompt": "Animate 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.video("lucy-pro-i2v"), "prompt": "test", # Missing 'data' field})# Raises InvalidInputError: Invalid inputs for lucy-pro-i2v: data is required
Import specific exception types for better error handling and type safety.