Skip to main content
This guide will help you get up and running with the Decart AI SDK quickly. You’ll learn how to use the three main APIs: Real-time (WebRTC), Queue (async video), and Process (sync image).

Prerequisites

1

Install the SDK

Install the Decart AI SDK using your preferred package manager:
npm install @decartai/sdk
2

Get your API key

Sign up at Decart Platform to get your API key. Set it as an environment variable:
export DECART_API_KEY="your-api-key-here"

Real-time Video Transformation

Transform video streams in real-time using WebRTC. Perfect for live video effects and interactive applications.
1

Import the SDK

import { createDecartClient, models } from "@decartai/sdk";
2

Get the camera stream

const model = models.realtime("mirage_v2");

// Get user's camera stream
const stream = await navigator.mediaDevices.getUserMedia({
  audio: true,
  video: { 
    frameRate: model.fps,
    width: model.width,
    height: model.height,
  }
});
3

Create a client and connect

// Create a client
const client = createDecartClient({
  apiKey: "your-api-key-here"
});

// Connect and transform the video stream
const realtimeClient = await client.realtime.connect(stream, {
  model,
  onRemoteStream: (transformedStream) => {
    videoElement.srcObject = transformedStream;
  },
  initialState: {
    prompt: {
      text: "Anime",
      enhance: true
    }
  }
});
4

Update the style dynamically

// Change the style on the fly
realtimeClient.setPrompt("Cyberpunk city");

// Disconnect when done
realtimeClient.disconnect();

Async Video Generation (Queue API)

Generate videos asynchronously using the queue API. Perfect for longer video generation tasks.
1

Submit and poll automatically

The easiest way to generate videos is using submitAndPoll():
import { createDecartClient, models } from "@decartai/sdk";

const client = createDecartClient({
  apiKey: "your-api-key-here"
});

// Submit and poll automatically
const result = await client.queue.submitAndPoll({
  model: models.video("lucy-pro-t2v"),
  prompt: "A cat playing piano",
  onStatusChange: (job) => {
    console.log(`Status: ${job.status}`);
  }
});

if (result.status === "completed") {
  videoElement.src = URL.createObjectURL(result.data);
} else {
  console.error("Job failed:", result.error);
}
2

Or manage polling manually

For more control, you can manually poll for job status:
// Submit the job
const job = await client.queue.submit({
  model: models.video("lucy-pro-t2v"),
  prompt: "A cat playing piano"
});
console.log(`Job ID: ${job.job_id}`);

// Poll for status
const status = await client.queue.status(job.job_id);
console.log(`Status: ${status.status}`);

// Get result when completed
if (status.status === "completed") {
  const blob = await client.queue.result(job.job_id);
  videoElement.src = URL.createObjectURL(blob);
}

Synchronous Image Generation (Process API)

Generate images synchronously for immediate results.
1

Text-to-image generation

import { createDecartClient, models } from "@decartai/sdk";

const client = createDecartClient({
  apiKey: "your-api-key-here"
});

// Generate an image
const blob = await client.process({
  model: models.image("lucy-pro-t2i"),
  prompt: "A beautiful sunset over the ocean",
  resolution: "720p"
});

// Display the image
const imageUrl = URL.createObjectURL(blob);
imageElement.src = imageUrl;
2

Image-to-image transformation

// Transform an existing image
const blob = await client.process({
  model: models.image("lucy-pro-i2i"),
  prompt: "Turn this into a watercolor painting",
  data: imageFile, // File or Blob
  resolution: "720p"
});

Next Steps

Core Concepts

Learn about the client, models, and authentication

Real-time API

Deep dive into real-time video transformation

Queue API

Master async video generation

API Reference

Explore the complete API reference
For production use, consider using proxy mode to keep your API key secure on the server side.

Build docs developers (and LLMs) love