Skip to content

@voice213/agent-client puts your agent inside your own website or app, with your own interface. It takes care of the hard parts of real-time voice: the microphone, streaming audio both ways, interruptions, echo, transcripts and errors. You decide what the page looks like.

npm install @voice213/agent-client
import { AgentCall } from "@voice213/agent-client";

const call = new AgentCall({ agentId: "k3x9m2p7q4wz" });

call.on("status", (status) => (statusLabel.textContent = status)); // connecting → connected → ended
call.on("mode", (mode) => orb.classList.toggle("speaking", mode === "speaking"));
call.on("message", ({ role, text }) => addLine(role, text));
call.on("error", (error) => showError(error.code, error.message));

talkButton.addEventListener("click", () => call.start()); // from a click: browsers require it
hangUpButton.addEventListener("click", () => call.end());

​What's in the package

ImportWhat it is
@voice213/agent-clientAgentCall, the client. It has no framework or dependencies, and runs in every modern browser and in Node.js.
@voice213/agent-client/reactuseAgentCall, the client as a React hook, for React 18+ and Next.js
@voice213/agent-client/widget<voice213-agent>, a ready-made call button and panel that works in any framework or none
@voice213/agent-client/serverWebhook signature verification, with typed events, for Node.js, edge and serverless functions
dist/voice213.global.jsThe client and the widget element for a <script> tag, as window.Voice213 (the React hook and server helpers need a bundler or Node)

TypeScript types are included for every entry point, and every entry point works with import and require.

​Before you start

  • A published agent. Copy its public id (12 letters and digits, such as k3x9m2p7q4wz) from its Publish page. A draft agent, or one with Enable link and widget turned off, answers NOT_FOUND.
  • Your site in Allowed websites, if you set that list. Otherwise the call is refused with ORIGIN. Add http://localhost:3000 (or your dev port) while you develop.
  • HTTPS. Browsers only open the microphone on secure pages (localhost counts).
  • A click. Browsers only start the microphone and sound from a user gesture, so call start() in a click handler.

​How a call works

1

start()

In the click, the SDK opens the microphone and its audio processors, then asks the API for a single-use call ticket: POST /api/agents/public/{id}/call.

2

Connected

It opens the call socket with the ticket. When the agent is on the line, status becomes connected, start() resolves, and the agent opens with its greeting.

3

The conversation

The microphone streams as 16 kHz audio, and the agent's voice plays as it arrives. Transcripts, tool runs and interruptions come in as events. You can mute, send typed messages, switch microphones, and drive a visualiser from the audio levels.

4

end()

The SDK hangs up politely: the agent's voice stops, and the server closes the conversation and answers with its summary (reason, duration, minutes used). Then the microphone is released. When the agent hangs up instead, its goodbye plays out first.

​Audio built for voice

  • Echo-free on laptops. In Chrome and Edge, the agent's voice goes through WebRTC so the browser's echo canceller can remove it from the microphone, and the agent never hears itself. Everywhere, quiet sound reaching the microphone while the agent speaks is sent as silence, while a caller speaking up still interrupts.
  • Clean input. The microphone is filtered before it drops to the 16 kHz the agent hears, so high-frequency noise doesn't fold back into the voice.
  • Smooth output. The agent's voice plays through a small adaptive jitter buffer that grows after network hiccups. It fades out in 4 ms when the caller interrupts: no clicks, no stale words.
  • Off the main thread. All audio runs in AudioWorklets, so a busy page doesn't stutter the call.

​Next

Was this page helpful?