The SDK is fully async and uses standard Python async/await patterns:
Copy
Ask AI
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: # Generate a video from text using the Queue API result = await client.queue.submit_and_poll({ "model": models.video("lucy-pro-t2v"), "prompt": "A cat walking in a lego world", "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:
Copy
Ask AI
# On your backendasync 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
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.
Copy
Ask AI
# Image-to-video requires 'data' fieldawait client.queue.submit_and_poll({ "model": models.video("lucy-pro-i2v"), "prompt": "Make it cinematic", "data": image_file, # ✅ Required})# Text-to-video doesn't need 'data'await client.queue.submit_and_poll({ "model": models.video("lucy-pro-t2v"), "prompt": "A cat walking", "data": image_file, # ❌ Type error})