{"id":11244,"library":"livekit-server-sdk","title":"LiveKit Server SDK","description":"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.","status":"active","version":"2.15.1","language":"javascript","source_language":"en","source_url":"https://github.com/livekit/node-sdks","tags":["javascript","typescript"],"install":[{"cmd":"npm install livekit-server-sdk","lang":"bash","label":"npm"},{"cmd":"yarn add livekit-server-sdk","lang":"bash","label":"yarn"},{"cmd":"pnpm add livekit-server-sdk","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"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.","wrong":"const AccessToken = require('livekit-server-sdk').AccessToken;","symbol":"AccessToken","correct":"import { AccessToken } from 'livekit-server-sdk';"},{"note":"Used for managing LiveKit rooms (list, create, delete) and participants. Requires API key and secret.","wrong":"const { RoomServiceClient } = require('livekit-server-sdk');","symbol":"RoomServiceClient","correct":"import { RoomServiceClient } from 'livekit-server-sdk';"},{"note":"This is a named export, not a default export. Used for decoding and verifying LiveKit webhook callbacks.","wrong":"import WebhookReceiver from 'livekit-server-sdk';","symbol":"WebhookReceiver","correct":"import { WebhookReceiver } from 'livekit-server-sdk';"}],"quickstart":{"code":"import { AccessToken } from 'livekit-server-sdk';\n\n// Load API keys from environment variables for security.\n// NEVER hardcode secrets in production code.\nconst LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY ?? '';\nconst LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET ?? '';\n\nconst roomName = 'my-dynamic-room-' + Math.random().toString(36).substring(7);\nconst participantIdentity = 'user-' + Math.random().toString(36).substring(7);\n\nasync function generateLiveKitToken() {\n  if (!LIVEKIT_API_KEY || !LIVEKIT_API_SECRET) {\n    console.error('LIVEKIT_API_KEY and LIVEKIT_API_SECRET must be set as environment variables or provided directly.');\n    return;\n  }\n\n  const at = new AccessToken(LIVEKIT_API_KEY, LIVEKIT_API_SECRET, {\n    identity: participantIdentity,\n    name: `User ${participantIdentity.substring(5)}`,\n    ttl: '1h', // Token expires in 1 hour\n  });\n\n  at.addGrant({\n    roomJoin: true,\n    room: roomName,\n    canPublish: true,      // Participant can publish audio/video\n    canSubscribe: true,    // Participant can subscribe to others' tracks\n    canUpdateOwnMetadata: true,\n    // Additional permissions like canPublishSources, canUpdateRoom, etc., can be added here\n  });\n\n  const token = await at.toJwt();\n  console.log(`Generated LiveKit Access Token for participant '${participantIdentity}' in room '${roomName}':`);\n  console.log(token);\n  console.log('\\nThis token can be used by a LiveKit client SDK to join the room.');\n}\n\ngenerateLiveKitToken().catch(console.error);","lang":"typescript","description":"Demonstrates how to generate an access token for a LiveKit participant to join a specified room, including setting basic permissions and token expiration."},"warnings":[{"fix":"Consult the official LiveKit Server SDK v2 migration guide for detailed instructions on updating your codebase.","message":"The 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.","severity":"breaking","affected_versions":">=2.0.0"},{"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.","message":"Exposing 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"When 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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"Incorrect LiveKit API Key or API Secret provided to the AccessToken constructor or when creating a WebhookReceiver.","error":"Error: signature verification failed"},{"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'}));`","cause":"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.","error":"TypeError: app.use() requires callback functions but got a [object Undefined]"},{"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).","cause":"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.","error":"ERR_REQUIRE_ESM: require() of ES Module <...>/livekit-server-sdk.js from <your-file>.js not supported"}],"ecosystem":"npm"}