Using an AI coding agent? Run npx skills add https://docs.platform.decart.ai to teach it Decart’s APIs, or connect the MCP server for live docs search.
import { createDecartClient, models } from "@decartai/sdk";const model = models.realtime("lucy-latest");// Request camera access — will throw if the user denies permissionlet stream: MediaStream;try { stream = await navigator.mediaDevices.getUserMedia({ video: { frameRate: model.fps, width: model.width, height: model.height }, audio: true, });} catch (err) { if (err instanceof DOMException && err.name === "NotAllowedError") { console.error("Camera permission denied. Please allow camera access and reload."); } else { console.error("Could not access camera:", err); } throw err;}const client = createDecartClient({ apiKey: process.env.DECART_API_KEY });const realtimeClient = await client.realtime.connect(stream, { model, mirror: "auto", onRemoteStream: (remoteStream) => { document.getElementById("output").srcObject = remoteStream; }, onError: (err) => { console.error("Realtime connection error:", err); }, onDisconnect: (reason) => { console.log("Disconnected:", reason); }, initialState: { prompt: { text: "Substitute the character in the video with an anime-style hero with spiky silver hair and glowing blue eyes.", enhance: true }, },});// Switch to a different transformation on the flyawait realtimeClient.setPrompt("Substitute the character in the video with a Renaissance oil painting portrait.");