When to use this path
- You want the fastest integration with zero infrastructure overhead It’s OK for end users to connect to Decart endpoints directly (visible in network traffic)
- You’re building a wrapper app, marketplace listing, or plugin that surfaces Decart models
Characteristics
| Property | Value |
|---|---|
| White-label | No — end users see Decart endpoints and SDK |
| Frame access | No |
| Provider visibility | Session events only (generationTick, connectionChange) |
| Client requirements | Browser or native app with WebRTC + Decart SDK |
| Your infrastructure | Backend for token minting only |
Media quality is identical to using Decart directly. There is no degradation — the SDK connects straight to Decart.
Architecture
How it works
Create a client token on your backend
Use your platform API key to mint a short-lived client token. This keeps your permanent key server-side.
Connect from the frontend
Your frontend uses the client token to connect. The SDK handles WebSocket signaling, WebRTC negotiation, ICE candidates, and auto-reconnection.
Control the generation
Use
set() to change the prompt, reference image, or both at any time during the session:API reference
connect(stream, options)
Creates a new realtime session and establishes the WebRTC connection.
The realtime model — use
models.realtime("model_id").Called when the remote video/audio stream is ready.
Pre-configure a prompt and/or image before the first frame.
Modify the SDP offer before sending (advanced).
initialState option lets you set a prompt and image in the same round-trip as session creation — the model starts generating with your configuration from the first frame.
set(input)
Update the prompt, reference image, or both. At least one of prompt or image is required. Awaits server acknowledgment — throws if rejected by moderation or on timeout.
The text prompt to apply.
Enhance the prompt automatically. Set to
false for exact prompt text.Reference image. Pass
null to clear the current image. Strings are treated as base64.setPrompt(prompt, options?)
Set the prompt and wait for server acknowledgment. Throws if the prompt is rejected by moderation or the request times out (15 seconds).
Enhance the prompt automatically.
setImage(image, options?)
Set a reference image and wait for server acknowledgment. Throws if the image is rejected by moderation or the request times out.
Set a prompt alongside the image.
Enhance the prompt automatically.
Timeout in milliseconds.
disconnect()
End the session and clean up all WebRTC and WebSocket connections.
isConnected()
Returns true if the SDK has an active connection.
getConnectionState()
Returns the current connection state.
sessionId
The current session identifier, or null if not connected.
Events
Listen to events withrt.on(event, listener) and remove listeners with rt.off(event, listener).
| Event | Payload | Description |
|---|---|---|
connectionChange | ConnectionState | Connection state changed — "connecting", "connected", "generating", "disconnected", "reconnecting" |
generationTick | { seconds: number } | Total elapsed generation time (cumulative). Use for billing. |
error | DecartSDKError | An error occurred. The error has a message property with details. |
The SDK automatically handles ICE restarts and WebRTC reconnection. You don’t need to manage the WebRTC lifecycle — just listen to
connectionChange to update your UI.Error handling
The SDK surfaces errors through theerror event and by throwing from async methods like set(), setPrompt(), and setImage().
- Moderation rejection — prompt or image violates content policy. Caught by
set(),setPrompt(), andsetImage()(all throw on rejection). - Connection lost — network issue or server disconnect. The SDK attempts to reconnect automatically. Listen to
connectionChangefor state transitions. - Invalid API key — the session fails to connect. Caught during
connect(). - Insufficient credits — the session ends with a
connectionChangeto"disconnected".