The Pipecat JavaScript SDK provides a lightweight client implementation that handles:

  • Device and media stream management
  • Managing bot configuration
  • Sending actions to the bot
  • Handling bot messages and responses
  • Managing session state and errors

Installation

Install the SDK and a transport implementation (e.g. Daily for WebRTC):

npm install @pipecat-ai/client-js
npm install @pipecat-ai/daily-transport

Example

Here’s a simple example using Daily as the transport layer:

import { RTVIClient } from "@pipecat-ai/client-js";
import { DailyTransport } from "@pipecat-ai/daily-transport";

// Handle incoming audio from the bot
function handleBotAudio(track, participant) {
  if (participant.local || track.kind !== "audio") return;

  const audioElement = document.createElement("audio");
  audioElement.srcObject = new MediaStream([track]);
  document.body.appendChild(audioElement);
  audioElement.play();
}

// Create and configure the client
const rtviClient = new RTVIClient({
  params: {
    baseUrl: process.env.PIPECAT_API_URL || "/api",
  },
  transport: new DailyTransport(),
  enableMic: true,
  callbacks: {
    onTrackStart: handleBotAudio,
  },
});

// Connect to your bot
rtviClient.connect();

Explore the SDK

The Pipecat JavaScript SDK implements the RTVI standard for real-time AI inference, ensuring compatibility with any RTVI-compatible server and transport layer.