Edit video with controlled, targeted prompts
import { createDecartClient, models } from "@decartai/sdk";
const model = models.realtime("lucy-2.5");
// Get user's camera stream with model specifications
const stream = await navigator.mediaDevices.getUserMedia({
audio: true,
video: {
frameRate: model.fps,
width: model.width,
height: model.height,
}
});
// Create a client. Never ship your permanent API key to the browser: fetch a short-lived
// client token from your backend instead. The SDK calls this before every connect and reconnect.
const client = createDecartClient({
apiKeyProvider: async () => {
const res = await fetch("/api/realtime-token", { method: "POST" }); // your server: client.tokens.create(...)
const { apiKey } = await res.json();
return apiKey;
}
});
// Connect and edit the video stream
const realtimeClient = await client.realtime.connect(stream, {
model,
// Fast mode (4 credits/sec, 2x standard): lower latency and higher throughput.
// speed: "fast",
mirror: "auto",
onRemoteStream: (editedStream) => {
// Display the edited video
const videoElement = document.querySelector("#video-output");
videoElement.srcObject = editedStream;
}
});
// set() replaces the full state — prompt + image atomically
await realtimeClient.set({
prompt: "A person wearing a superhero costume",
enhance: true,
image: "https://example.com/superhero-reference.png",
});
// Prompt-only update
await realtimeClient.set({ prompt: "Add sunglasses to the person" });
// setPrompt() also works as a shorthand
await realtimeClient.setPrompt("Change the person's shirt to red");
// Disconnect when done
realtimeClient.disconnect();
promptRequiredEdit description for live transformation
streamRequiredVideo stream (WebRTC)
speedOptionalFast mode: connect-time option that gives the session lower latency and higher throughput; output quality is unchanged. Billed at 4 credits/sec, 2x standard. Omit for standard mode. (options: fast)
promptstringYesEdit description for live transformationstreamFileYesVideo stream (WebRTC)speedstringNoFast mode: connect-time option that gives the session lower latency and higher throughput; output quality is unchanged. Billed at 4 credits/sec, 2x standard. Omit for standard mode. (options: fast)Edit video in realtime with controlled, targeted prompts
Lucy enables targeted video edits, modifying specific elements while preserving the rest. Edit infinite long videos in realtime, with zero latency, and see your changes as you type.
Video models are charged per second of generated video. Final cost depends on video duration and selected resolution. Fast mode gives realtime sessions lower latency and higher throughput; output quality is unchanged.