Skip to content

CreateRealtimeAvatarSession

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
SkipUnlessRealtimeTestsEnabled();

using var client = new RunwayClient(apiKey);

var sessionId = default(Guid);

try
{
    var session = await client.RealtimeSessions.CreateRealtimeSessionsAsync(
        request: new CreateRealtimeSessionsRequest
        {
            Avatar = new CreateRealtimeSessionsRequestAvatarRunwayPresetAvatar
            {
                PresetId = CreateRealtimeSessionsRequestAvatarRunwayPresetAvatarPresetId.Influencer,
            },
            MaxDuration = 60,
        });

    sessionId = session.Id;

    Console.WriteLine($"Realtime session ID: {sessionId}");

    var ready = await WaitForRealtimeSessionReadyAsync(
        client: client,
        sessionId: sessionId,
        timeout: TimeSpan.FromSeconds(90));

    var credentials = await client.RealtimeSessions.ConsumeRealtimeSessionAsync(
        id: sessionId,
        sessionKey: ready.SessionKey);

    Console.WriteLine($"Realtime credentials received for room '{credentials.RoomName}' at {credentials.Url.Host}.");
}
finally
{
    if (sessionId != default)
    {
        try
        {
            await client.RealtimeSessions.DeleteRealtimeSessionsByIdAsync(id: sessionId);
        }
        catch (ApiException exception)
        {
            Console.WriteLine($"Realtime session cleanup returned HTTP {(int)exception.StatusCode}.");
        }
    }
}