Web SDK
@voice213/agent-client: put your agent in any website or app, with your own interface
@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-clientimport { 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());"use client";
import { useAgentCall } from "@voice213/agent-client/react";
export function TalkToUs() {
const { status, isSpeaking, transcript, error, start, end } = useAgentCall({ agentId: "k3x9m2p7q4wz" });
return (
<section>
{status === "connected" ? <button onClick={end}>Hang up</button> : <button onClick={start} disabled={status === "connecting"}>Talk to us</button>}
<p>{status === "connected" ? (isSpeaking ? "Speaking…" : "Listening…") : status}</p>
{error && <p role="alert">{error.message}</p>}
{transcript.map((m) => (
<p key={m.id} dir="auto"><b>{m.role === "user" ? "You" : "Agent"}:</b> {m.text}</p>
))}
</section>
);
}<script src="https://cdn.jsdelivr.net/npm/@voice213/agent-client@0.2.0/dist/voice213.global.js" integrity="sha384-uC0Le1b+8b6nZJG677oFQhHDxkXIBxBpQlUAAagUB87AO8yyCfYNurb87rOCGVKw" crossorigin="anonymous" defer></script>
<voice213-agent agent-id="k3x9m2p7q4wz" variant="inline" lang="fr"></voice213-agent>What's in the package
| Import | What it is |
|---|---|
@voice213/agent-client | AgentCall, the client. It has no framework or dependencies, and runs in every modern browser and in Node.js. |
@voice213/agent-client/react | useAgentCall, 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/server | Webhook signature verification, with typed events, for Node.js, edge and serverless functions |
dist/voice213.global.js | The 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, answersNOT_FOUND. - Your site in Allowed websites, if you set that list. Otherwise the call is refused with
ORIGIN. Addhttp://localhost:3000(or your dev port) while you develop. - HTTPS. Browsers only open the microphone on secure pages (
localhostcounts). - A click. Browsers only start the microphone and sound from a user gesture, so call
start()in a click handler.
How a call works
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.
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.
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.
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?