Skip to main content
Your application embeds the Decart SDK directly. End users connect to Decart for both signaling (WebSocket) and media (WebRTC). You handle authentication and billing on your side. This is the simplest integration path — no proxy infrastructure, no protocol translation, full media quality.

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
If you already use Decart’s batch models (video editing, image editing), SDK Direct for realtime works the same way — same API key, same SDK, same billing.

Characteristics

Media quality is identical to using Decart directly. There is no degradation — the SDK connects straight to Decart.

Architecture

How it works

1

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.
2

Connect from the frontend

Your frontend uses the client token to connect. The SDK handles WebSocket signaling, WebRTC negotiation, ICE candidates, and auto-reconnection.
3

Control the generation

Use set() to replace the session state at any time. Include all fields you want to keep — omitted fields are cleared:
4

Listen to events

Track session state and usage with event listeners:
5

Disconnect when done

Clean up the session when the user leaves. This closes the WebSocket and WebRTC connections.

API reference

connect(stream, options)

Creates a new realtime session and establishes the WebRTC connection.
model
ModelDefinition
required
The realtime model — use models.realtime("model_id").
onRemoteStream
(stream: MediaStream) => void
required
Called when the remote video/audio stream is ready.
initialState
object
Pre-configure a prompt and/or image before the first frame.
preferredVideoCodec
"h264" | "vp8" | "vp9"
Preferred local publish codec. Desktop Safari is always pinned to vp8. On React Native, use "vp8".
The 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)

Replace the session state with a new prompt, reference image, or both. Fields not included are cleared. At least one of prompt or image is required. Awaits server acknowledgment — throws if rejected by moderation or on timeout.
prompt
string
The text prompt to apply.
enhance
boolean
default:"true"
Enhance the prompt automatically. Set to false for exact prompt text.
image
Blob | File | string | null
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
boolean
default:"true"
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.
prompt
string
Set a prompt alongside the image.
enhance
boolean
default:"true"
Enhance the prompt automatically.
timeout
number
default:"15000"
Timeout in milliseconds.
Reference images must be under 10 MB. The SDK rejects oversized images before sending them.

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 with rt.on(event, listener) and remove listeners with rt.off(event, listener).
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 the error event and by throwing from async methods like set(), setPrompt(), and setImage().
Common error scenarios:
  • Moderation rejection — prompt or image violates content policy. Caught by set(), setPrompt(), and setImage() (all throw on rejection).
  • Connection lost — network issue or server disconnect. The SDK attempts to reconnect automatically. Listen to connectionChange for state transitions.
  • Invalid API key — the session fails to connect. Caught during connect().
  • Insufficient credits — the session ends with a connectionChange to "disconnected".

Next steps

Client Tokens

Set up secure token rotation for frontend auth

Streaming Best Practices

Optimize camera setup, prompts, and error handling