Skip to content

Realtime Session

Connect to a D-ID agent via a realtime WebRTC session.

This example assumes using DId; is in scope and apiKey contains your DId API key.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
// Connect to a D-ID agent using a realtime WebRTC session.
// This creates a live streaming connection via SIPSorcery's RTCPeerConnection
// and the D-ID REST signaling endpoints (CreateStream, StartConnection, AddIceCandidate).
using var client = new DIdClient(apiKey);

var agentId =
    Environment.GetEnvironmentVariable("DID_AGENT_ID") is { Length: > 0 } agentIdValue
        ? agentIdValue
        : throw new AssertInconclusiveException("DID_AGENT_ID environment variable is not found.");

// Create a realtime session with the agent. The ConnectAsync method handles
// the full SDP/ICE negotiation — creating a stream, exchanging SDP offer/answer,
// and forwarding ICE candidates.
await using var session = await DIdRealtimeSession.ConnectAsync(
    client: client,
    agentId: agentId);

// Verify the session was established with valid identifiers.