LiveKit ASP.NET Core Server SDK

API Reference LiveKit Protocol v1.45.0

ASP.NET Core SDK for LiveKit Server API. Provides HTTP clients and services for managing rooms, participants, recordings, ingress, SIP, and more.

Features

  • Room Management - Create, list, and delete rooms
  • Participant Management - Manage participants, tracks, and subscriptions
  • Egress - Record and stream rooms, participants, or tracks
  • Ingress - Bring external media (RTMP, WHIP, URL pull) into LiveKit
  • SIP Integration - Manage SIP trunks, dispatch rules, and make calls
  • Token Generation - JWT token builder with fluent API
  • Webhook Validation - Two-layer security (JWT + SHA256)
  • Agent Dispatch - Deploy AI agents to rooms
  • Phone Numbers - Search, purchase, and manage phone numbers

Installation

Install the packages from NuGet:

dotnet add package LiveKit.AspNetCore.ServerSdk
dotnet add package LiveKit.AspNetCore.ServerSdk.Abstractions

Or via Package Manager:

Install-Package LiveKit.AspNetCore.ServerSdk
Install-Package LiveKit.AspNetCore.ServerSdk.Abstractions

Quick Start

1. Configure Services

In your Program.cs or Startup.cs:

builder.Services.AddLiveKit(options =>
{
    options.BaseUrl = "wss://your-livekit-server.com";
    options.ApiKey = "your-api-key";
    options.ApiSecret = "your-api-secret";
});

2. Generate Access Tokens

public class TokenController : ControllerBase
{
    private readonly ILiveKitTokenService _tokenService;

    public TokenController(ILiveKitTokenService tokenService)
    {
        _tokenService = tokenService;
    }

    [HttpGet]
    public IActionResult GetToken(string identity, string roomName)
    {
        var token = _tokenService
            .CreateTokenBuilder(identity)
            .WithKind(ParticipantInfo.Types.Kind.Standard)
            .WithVideoGrant(video =>
            {
                video.RoomJoin = true;
                video.Room = roomName;
                video.CanPublish = true;
                video.CanSubscribe = true;
            })
            .ToJwt();

        return Ok(new { token });
    }
}

3. Manage Rooms

public class RoomsController : ControllerBase
{
    private readonly ILiveKitRoomService _roomService;

    public RoomsController(ILiveKitRoomService roomService)
    {
        _roomService = roomService;
    }

    [HttpPost]
    public async Task<IActionResult> CreateRoom(string name)
    {
        var request = new CreateRoomRequest { Name = name };
        var room = await _roomService.CreateRoomAsync(request);
        return Ok(room);
    }

    [HttpGet]
    public async Task<IActionResult> ListRooms()
    {
        var request = new ListRoomsRequest();
        var response = await _roomService.ListRoomsAsync(request);
        return Ok(response);
    }

    [HttpDelete("{roomName}")]
    public async Task<IActionResult> DeleteRoom(string roomName)
    {
        var request = new DeleteRoomRequest { Room = roomName };
        var response = await _roomService.DeleteRoomAsync(request);
        return NoContent();
    }
}

4. Handle Webhooks

Create a controller for receiving webhook events:

public class WebhookController : ControllerBase
{
    private readonly ILiveKitWebhookReceiver _webhookReceiver;

    public WebhookController(ILiveKitWebhookReceiver webhookReceiver)
    {
        _webhookReceiver = webhookReceiver;
    }

    [HttpPost("/webhook")]
    public async Task<IActionResult> ReceiveWebhook()
    {
        var body = await new StreamReader(Request.Body).ReadToEndAsync();
        var authHeader = Request.Headers["Authorization"].ToString();

        var webhookEvent = await _webhookReceiver.ReceiveAsync(body, authHeader);

        // Handle webhook event
        switch (webhookEvent.Event)
        {
            case LiveKitWebhookEvents.ROOM_STARTED:
                // Handle room started
                break;
            case LiveKitWebhookEvents.PARTICIPANT_JOINED:
                // Handle participant joined
                break;
            case LiveKitWebhookEvents.PARTICIPANT_LEFT:
                // Handle participant left
                break;
            case LiveKitWebhookEvents.TRACK_PUBLISHED:
                // Handle track published
                break;
            // Add more cases as needed
        }

        return Ok();
    }
}

Available Services

Room Service

ILiveKitRoomService - Manage rooms and participants

Egress Service

ILiveKitEgressService - Record and stream content

Ingress Service

ILiveKitIngressService - Create ingress endpoints for external media

SIP Service

ILiveKitSipService - Manage SIP trunks and dispatch rules

Token Service

ILiveKitTokenService - Generate JWT tokens for client authentication

Webhook Receiver

ILiveKitWebhookReceiver - Validate and parse webhook events

Additional Services

Documentation