The SDK is fully async and uses standard Python async/await patterns:
import asynciofrom decart import DecartClient, modelsimport osasync def main(): # Using context manager (recommended for automatic cleanup) async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client: # Edit a video using the Queue API result = await client.queue.submit_and_poll({ "model": models.video("lucy-2-v2v"), "data": video_file, "prompt": "Transform into anime style", "resolution": "720p", "on_status_change": lambda job: print(f"Status: {job.status}"), }) if result.status == "completed": with open("output.mp4", "wb") as f: f.write(result.data) print("Video saved!")asyncio.run(main())
For client-side applications (browsers, mobile apps) using the Realtime API, create short-lived client tokens instead of exposing your permanent API key:
# On your backend — basic (60s TTL, unrestricted)async with DecartClient(api_key=os.getenv("DECART_API_KEY")) as client: token = await client.tokens.create() # token.api_key - send to your frontend for secure client-side authentication # token.expires_at - expiration timestamp # Or scoped to specific models with a longer TTL token = await client.tokens.create( expires_in=300, allowed_models=["lucy_2_rt"], )
See Client Tokens for details on secure realtime auth.
The SDK includes full type hints for better IDE support and type checking. Each model enforces its own required inputs, so you’ll get autocomplete and helpful errors if something is missing.
# Video editing requires 'data' fieldawait client.queue.submit_and_poll({ "model": models.video("lucy-2-v2v"), "prompt": "Transform into anime style", "data": video_file, # ✅ Required})# Image editing requires 'data' fieldawait client.process({ "model": models.image("lucy-pro-i2i"), "prompt": "Change the background to a beach", "data": image_file, # ✅ Required})