> ## Documentation Index
> Fetch the complete documentation index at: https://daily-main.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# LiveKit Transport

> LiveKitTransport for the Pipecat JavaScript SDK: WebRTC audio and video on LiveKit's infrastructure, wrapping a LiveKit client.

The LiveKitTransport class provides a WebRTC transport layer using [LiveKit's](https://livekit.io) infrastructure. It wraps a LiveKit client to handle audio/video device management, WebRTC connections, and real-time communication between clients and bots. For complete documentation on LiveKit's API, see the [LiveKit Client SDK Reference](https://docs.livekit.io/client-sdk-js/).

This transport is designed for production use cases, leveraging LiveKit's infrastructure for low-latency, high-quality audio and video streaming. It expects your Pipecat server to include the corresponding [`LiveKitTransport` server-side](/api-reference/server/services/transport/livekit) implementation.

## Installation

```bash theme={null}
npm install @pipecat-ai/client-js @pipecat-ai/livekit-transport
```

## Usage

### Basic Setup

```javascript theme={null}
import { PipecatClient } from "@pipecat-ai/client-js";
import { LiveKitTransport } from "@pipecat-ai/livekit-transport";

const pcClient = new PipecatClient({
  transport: new LiveKitTransport({
    // LiveKitTransport constructor options (RoomOptions)
  }),
  enableCam: false, // Default camera off
  enableMic: true, // Default microphone on
  callbacks: {
    // Event handlers
  },
  // ...
});

await pcClient.connect({
  url: "wss://your-livekit-server.com",
  token: "your-livekit-token",
});
```

## API Reference

### Constructor Options

```typescript theme={null}
interface LiveKitTransportConstructorOptions extends RoomOptions {}
```

The `LiveKitTransportConstructorOptions` extends the `RoomOptions` type from the `livekit-client` library. These options are passed directly through to the LiveKit `Room` constructor. See the [LiveKit RoomOptions documentation](https://docs.livekit.io/client-sdk-js/interfaces/RoomOptions.html) for a complete list of options.

### TransportConnectionParams

On `connect()`, the `LiveKitTransport` requires a `url` and `token` to connect to a LiveKit room. This can be provided directly to the `PipecatClient`'s `connect()` method or via a starting endpoint passed to the `PipecatClient`'s `startBotAndConnect()` method. If using an endpoint, your endpoint should return a JSON object with `url`, `token`, and optional `roomConnectionOptions`. See the [client connect()](/api-reference/client/js/client-methods#connect) documentation for more information.

<ParamField path="url" type="string" required>
  The WebSocket URL of your LiveKit server (e.g.,
  `wss://your-server.livekit.cloud`).
</ParamField>

<ParamField path="token" type="string" required>
  Authentication token for the LiveKit room. Generate this on your server using
  LiveKit's access token API.
</ParamField>

<ParamField path="roomConnectionOptions" type="RoomConnectOptions">
  Optional LiveKit room connection options. See the [LiveKit RoomConnectOptions
  documentation](https://docs.livekit.io/client-sdk-js/interfaces/RoomConnectOptions.html)
  for available options.
</ParamField>

<CodeGroup>
  ```typescript client theme={null}
  pcClient.connect({
    url: 'wss://your-server.livekit.cloud',
    token: 'your-livekit-token'
  });
  // OR...
  pcClient.startBotAndConnect({
    endpoint: '/api/start', // Your server endpoint to start the bot
  });
  ```

  ```python server theme={null}
  @app.post("/api/start")
  async def start(request: Request) -> Dict[Any, Any]:
      print("Creating room and token for RTVI connection")
      room_url, token = await create_livekit_room_and_token()

      # Start the bot process
      print("Starting bot subprocess")
      try:
          subprocess.Popen(
              [f"python3 -m bot.py -u {room_url} -t {token}"],
              shell=True,
              bufsize=1,
              cwd=os.path.dirname(os.path.abspath(__file__)),
          )
      except Exception as e:
          raise HTTPException(status_code=500, detail=f"Failed to start subprocess: {e}")

      # Return the LiveKit connection params
      return {"url": room_url, "token": token}
  ```
</CodeGroup>

## Events

The transport implements the various [`PipecatClient` event handlers](/api-reference/client/js/callbacks). For LiveKit-specific events, you can attach listeners to the underlying LiveKit room. For a list of available events, see the [LiveKit Events Reference](https://docs.livekit.io/client-sdk-js/enums/RoomEvent.html).

```typescript theme={null}
// Access the underlying LiveKit Room instance
const room = pcClient.transport._room;
room.on("trackSubscribed", (track, publication, participant) => {
  // Handle LiveKit-specific event
});
```

## More Information

<CardGroup cols={2}>
  <Card horizontal title="LiveKit Docs" icon="book" href="https://docs.livekit.io">
    Official LiveKit Documentation
  </Card>

  <Card horizontal title="Source" icon="github" href="https://github.com/pipecat-ai/pipecat-client-web-transports/tree/main/transports/livekit-transport">
    `LiveKitTransport`
  </Card>

  <Card horizontal title="Package" icon="browser" href="https://www.npmjs.com/package/@pipecat-ai/livekit-transport">
    `@pipecat-ai/livekit-transport`
  </Card>

  <Card horizontal title="Choosing a Transport" icon="compass" href="/client/concepts/choosing-a-transport">
    Transport Selection Guide
  </Card>
</CardGroup>
