Registry / communication / livekit-server-sdk

livekit-server-sdk

JSON →
library2.15.1jsnpmunverified

The LiveKit Server SDK, currently at version 2.15.1, provides a comprehensive set of APIs for managing LiveKit rooms, generating access tokens, and processing webhooks from a server-side JavaScript, TypeScript, Node.js, Deno, or Bun environment. This SDK is actively maintained with frequent patch releases, as evidenced by recent updates addressing memory leaks and adding new features like `ringingTimeout` for SIP participants. A key differentiator of this SDK is its multi-runtime compatibility, supporting Node.js (>=18), Deno, and Bun, a significant evolution from its v1 predecessor which was primarily Node.js focused. It allows developers to programmatically control aspects of LiveKit sessions, such as listing, creating, and deleting rooms, and assigning granular permissions to participants joining rooms. The library ships with TypeScript types, facilitating robust development. While it theoretically runs in browsers, the documentation strongly advises against it due to security implications of exposing API secrets.

npm install livekit-server-sdk
INSTALL
IMPORT
SIG · LIVEKIT-SERVER-SDK
L
livekit-server-sdk
communicationjavascriptv2.15.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AccessToken
import { AccessToken } from 'livekit-server-sdk';
const AccessToken = require('livekit-server-sdk').AccessToken;
The v2 SDK is primarily designed for ESM usage. While CJS might work via transpilation, direct require() is not the recommended or native way for Node.js >=18.
RoomServiceClient
import { RoomServiceClient } from 'livekit-server-sdk';
const { RoomServiceClient } = require('livekit-server-sdk');
Used for managing LiveKit rooms (list, create, delete) and participants. Requires API key and secret.
WebhookReceiver
import { WebhookReceiver } from 'livekit-server-sdk';
import WebhookReceiver from 'livekit-server-sdk';
This is a named export, not a default export. Used for decoding and verifying LiveKit webhook callbacks.

Demonstrates how to generate an access token for a LiveKit participant to join a specified room, including setting basic permissions and token expiration.

import { AccessToken } from 'livekit-server-sdk'; // Load API keys from environment variables for security. // NEVER hardcode secrets in production code. const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY ?? ''; const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET ?? ''; const roomName = 'my-dynamic-room-' + Math.random().toString(36).substring(7); const participantIdentity = 'user-' + Math.random().toString(36).substring(7); async function generateLiveKitToken() { if (!LIVEKIT_API_KEY || !LIVEKIT_API_SECRET) { console.error('LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set as environment variables or provided directly.'); return; } const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, { identity: participantIdentity, name: `User ${participantIdentity.substring(5)}`, ttl: '1h', // Token expires in 1 hour }); at.addGrant({ roomJoin: true, room: roomName, canPublish: true, // Participant can publish audio/video canSubscribe: true, // Participant can subscribe to others' tracks canUpdateOwnMetadata: true, // Additional permissions like canPublishSources, canUpdateRoom, etc., can be added here }); const token = await at.toJwt(); console.log(`Generated LiveKit Access Token for participant '${participantIdentity}' in room '${roomName}':`); console.log(token); console.log('\nThis token can be used by a LiveKit client SDK to join the room.'); } generateLiveKitToken().catch(console.error);
Debug
Known issues
breakingThe SDK underwent a major rewrite from v1.x to v2.x, introducing breaking changes in API structure and package exports. Users migrating from v1 will need to review the dedicated migration guide.
fix
Consult the official LiveKit Server SDK v2 migration guide for detailed instructions on updating your codebase.
affects: >=2.0.0
gotchaExposing LiveKit API keys and secrets in client-side code (e.g., browsers) is a severe security risk. This SDK should ONLY be used in secure server-side environments.
fix
Ensure that the `livekit-server-sdk` is only used on your backend, and that API keys/secrets are managed securely (e.g., environment variables, secret management services) and never transmitted to the client.
affects: >=1.0.0
gotchaWhen integrating webhooks, ensure your HTTP server is configured to correctly parse `application/webhook+json` content type. Standard JSON parsers (e.g., `express.json()`) may not work.
fix
For Express.js, use `app.use(express.raw({type: 'application/webhook+json'}));` before your webhook route handler to get the raw body string required by `WebhookReceiver` for verification.
affects: >=1.0.0
Errors
Common errors & fixes
Error: signature verification failed
Incorrect LiveKit API Key or API Secret provided to the AccessToken constructor or when creating a WebhookReceiver.
fix
Double-check your `LIVEKIT_API_KEY` and `LIVEKIT_API_SECRET` environment variables or constructor arguments. Ensure they match the credentials from your LiveKit Cloud project or self-hosted instance.
TypeError: app.use() requires callback functions but got a [object Undefined]
Often seen in Express.js applications when trying to use middleware like `express.raw()` without importing it correctly or if Express.js is not initialized properly, specifically when handling webhook bodies.
fix
Ensure `express` is imported and `express.raw()` is correctly configured for the webhook endpoint: `import express from 'express'; const app = express(); app.use(express.raw({type: 'application/webhook+json'}));`
ERR_REQUIRE_ESM: require() of ES Module <...>/livekit-server-sdk.js from <your-file>.js not supported
Attempting to use CommonJS `require()` syntax with `livekit-server-sdk` v2+ in a Node.js project that is configured for ES Modules, or vice-versa with a mixed configuration.
fix
If your project is ESM-first (e.g., `"type": "module"` in `package.json`), use `import { ... } from 'livekit-server-sdk';`. If your project is CJS, you might need to ensure your transpilation setup is correct or check if an older CJS-compatible version is available (though v2 is primarily ESM).
Upgrade
Version history
2.15.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
34 hits · last 30 days
node
30
OpenAI (training)
1
Resources
livekit-server-sdk — npm install livekit-server-sdk · libregistry