Use this SDK to add realtime video, audio and data features to your Rust app. By connecting to LiveKit Cloud or a self-hosted server, you can quickly build applications such as multi-modal AI, live streaming, or video calls with just a few lines of code.
[!IMPORTANT] If you're building Voice AI, LiveKit Agents is the SDK for code-first realtime voice agents. STT, LLM, TTS, turn detection, expressive speech, keyterm accuracy, tool usage, and telephony all come bundled in the framework. It's available in both Python and Node.js.
# agent.py from livekit import agents from livekit.agents import Agent, AgentServer, AgentSession, STTContextOptions, TurnHandlingOptions, inference server = AgentServer() @server.rtc_session(agent_name="my-agent") async def my_agent(ctx: agents.JobContext): session = AgentSession( stt=inference.STT(model="deepgram/nova-3", language="multi"), llm=inference.LLM(model="google/gemma-4-31b-it"), tts=inference.TTS(model="inworld/inworld-tts-2", voice="Ashley"), turn_handling=TurnHandlingOptions(turn_detection=inference.TurnDetector()), stt_context_options=STTContextOptions(keyterms=["LiveKit", "Acme Corp"]), expressive=True, ) await session.start(room=ctx.room, agent=Agent(instructions="You are a helpful voice AI assistant.")) await session.generate_reply(instructions="Greet the user and offer your assistance.") if __name__ == "__main__": agents.cli.run_app(server)Models come from LiveKit Inference with no per-provider API keys, and LiveKit Cloud handles deployment and observability. Visit the docs for more info at docs.livekit.io/agents.
Using a coding agent? Install the LiveKit skill with
npx skills add livekit/agent-skillsand add the docs MCP athttps://docs.livekit.io/mcp/(see coding agent support).
livekit-api: Server APIs and auth token generationlivekit: LiveKit real-time SDKlivekit-ffi: Internal crate, used to generate bindings for other languageslivekit-protocol: LiveKit protocol generated codeWhen adding the SDK as a dependency to your project, make sure to add the necessary rustflags to your cargo config, otherwise linking may fail.
Also, please refer to the list of the supported platform toolkits.
Tokio is required to use this SDK.
use livekit_api::access_token;
use std::env;
fn create_token() -> Result<String, access_token::AccessTokenError> {
let api_key = env::var("LIVEKIT_API_KEY").expect("LIVEKIT_API_KEY is not set");
let api_secret = env::var("LIVEKIT_API_SECRET").expect("LIVEKIT_API_SECRET is not set");
let token = access_token::AccessToken::with_api_key(&api_key, &api_secret)
.with_identity("rust-bot")
.with_name("Rust Bot")
.with_grants(access_token::VideoGrants {
room_join: true,
room: "my-room".to_string(),
..Default::default()
})
.to_jwt();
return token
}
use livekit_api::services::room::{CreateRoomOptions, RoomClient};
#[tokio::main]
async fn main() {
let room_service = RoomClient::new("http://localhost:7880").unwrap();
let room = room_service
.create_room("my_room", CreateRoomOptions::default())
.await
.unwrap();
println!("Created room: {:?}", room);
}
use livekit::prelude::*;
#[tokio::main]
async fn main() -> Result<()> {
let (room, mut room_events) = Room::connect(&url, &token).await?;
while let Some(event) = room_events.recv().await {
match event {
RoomEvent::TrackSubscribed { track, publication, participant } => {
// ...
}
_ => {}
}
}
Ok(())
}
...
use futures::StreamExt; // this trait is required for iterating on audio & video frames
use livekit::prelude::*;
match event {
RoomEvent::TrackSubscribed { track, publication, participant } => {
match track {
RemoteTrack::Audio(audio_track) => {
let rtc_track = audio_track.rtc_track();
let mut audio_stream = NativeAudioStream::new(rtc_track);
tokio::spawn(async move {
// Receive the audio frames in a new task
while let Some(audio_frame) = audio_stream.next().await {
log::info!("received audio frame - {audio_frame:#?}");
}
});
},
RemoteTrack::Video(video_track) => {
let rtc_track = video_track.rtc_track();
let mut video_stream = NativeVideoStream::new(rtc_track);
tokio::spawn(async move {
// Receive the video frames in a new task
while let Some(video_frame) = video_stream.next().await {
log::info!("received video frame - {video_frame:#?}");
}
});
},
}
},
_ => {}
}

Building on Ubuntu 24 x86_64:
# install required libs
sudo apt install -y \
libglib2.0-dev build-essential \
libclang-dev libc6-dev pkg-config libjpeg-turbo8-dev
# webrtc-sys compiles against the hermetic libc++ shipped inside the libwebrtc
# artifact, which tracks LLVM trunk and needs clang 21 or later. Ubuntu 24's
# clang is 18, so install a newer one from apt.llvm.org:
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 21
export CC=clang-21 CXX=clang++-21
# install cuda-toolkit if you have an Nvidia GPU and want to use NVENC for video encoding
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install -y cuda-toolkit
# ensure CUDA_HOME env var is set
export CUDA_HOME="$(dirname "$(dirname "$(sudo find /usr/local /usr -path '*/include/cuda.h' -print 2>/dev/null | grep -v '/linux/' | sort -V | tail -1)")")"
cargo build
When building on MacOS, -ObjC linker flag is needed. LiveKit's WebRTC implementation make use of ObjectiveC libraries on the Mac. You may get the following error if the app isn't linked with ObjC:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RTCVideoCodecInfo nativeSdpVideoFormat]: unrecognized selector sent to instance 0x600003bc6660'
LiveKit aims to provide an open source, end-to-end WebRTC stack that works everywhere. We have two goals in mind with this SDK:
Regarding (2), we've already developed a number of client SDKs for several platforms and encountered a few challenges in the process:
Thus, we posited a Rust SDK, something we wanted build anyway, encapsulating all our business logic and platform-specific APIs into a clean set of abstractions, could also serve as the foundation for our other SDKs!
We'll first use it as a basis for our Unity SDK (under development), but over time, it will power our other SDKs, as well.
| LiveKit Ecosystem | |
|---|---|
| Agents SDKs | Python · Node.js |
| LiveKit SDKs | Browser · Swift · Android · Flutter · React Native · Rust · Node.js · Python · Unity · Unity (WebGL) · ESP32 · C++ |
| Starter Apps | Python Agent · TypeScript Agent · React App · SwiftUI App · Android App · Flutter App · React Native App · Web Embed |
| UI Components | React · Android Compose · SwiftUI · Flutter |
| Server APIs | Node.js · Golang · Ruby · Java/Kotlin · Python · Rust · PHP (community) · .NET (community) |
| Resources | Docs · Docs MCP Server · CLI · LiveKit Cloud |
| LiveKit Server OSS | LiveKit server · Egress · Ingress · SIP |
| Community | Developer Community · Slack · X · YouTube |