Web/React SDK

The @echoai/web package lets you add voice AI to any web application. It provides a vanilla JavaScript client and React hooks/components.

Installation

npm install @echoai/web
# or
pnpm add @echoai/web

Vanilla JavaScript

import { EchoAI } from "@echoai/web";

const echoai = new EchoAI({
  apiUrl: "http://localhost:8000",
  token: "your-jwt-or-api-key",
});

// Start a voice session
await echoai.connect({
  assistantId: "optional-assistant-id",
});

// Listen for events
echoai.on("transcript", (text, isFinal) => {
  console.log(isFinal ? "Final:" : "Partial:", text);
});

echoai.on("agentSpeaking", (text) => {
  console.log("Agent:", text);
});

// Disconnect
echoai.disconnect();

React Hook: useEchoAI

import { useEchoAI } from "@echoai/web/react";

function VoiceChat() {
  const {
    connect,
    disconnect,
    isConnected,
    isSpeaking,
    transcript,
    agentText,
  } = useEchoAI({
    apiUrl: "http://localhost:8000",
    token: session.access_token,
  });

  return (
    <div>
      <button onClick={isConnected ? disconnect : connect}>
        {isConnected ? "Hang Up" : "Start Call"}
      </button>
      {transcript && <p>You: {transcript}</p>}
      {agentText && <p>Agent: {agentText}</p>}
    </div>
  );
}

React Component: EchoAIButton

A drop-in button that handles connection state, microphone permissions, and visual feedback:

import { EchoAIButton } from "@echoai/web/react";

function App() {
  return (
    <EchoAIButton
      apiUrl="http://localhost:8000"
      token={session.access_token}
      assistantId="your-assistant-id"
      onTranscript={(text) => console.log("User:", text)}
      onAgentSpeak={(text) => console.log("Agent:", text)}
    />
  );
}

Props

PropTypeDescription
apiUrlstringHostDesk API base URL
tokenstringJWT or API key for auth
assistantIdstring?Optional assistant to use
onTranscript(text: string) => voidCalled on user speech
onAgentSpeak(text: string) => voidCalled on agent speech
classNamestring?CSS class for the button

Events

EventPayloadDescription
connected—WebRTC session established
disconnected—Session ended
transcript(text, isFinal)User speech recognized
agentSpeaking(text)Agent is speaking
agentStopped—Agent finished speaking
error(error)Connection or runtime error

Connection flow

  1. The SDK fetches a LiveKit token from your HostDesk backend
  2. Connects to the LiveKit room via WebRTC
  3. The voice worker joins the room and starts the STT/LLM/TTS pipeline
  4. Audio streams bidirectionally with low latency

Requirements

  • A running HostDesk backend (apps/backend)
  • A valid JWT session token or API key
  • Browser with WebRTC and microphone access