WayloAIWaylo Docs
Web SDK

Start and stop a call

Create a call, start it from a click, hang up.

import { WayloVoice } from '@waylovoice/client';

const wayloVoice = new WayloVoice({ sessionEndpoint: '/api/waylo/session' });

await wayloVoice.start({
  agentId: '3f9c2a7e-1b4d-4c8a-9e2f-5d6b7a8c9e01',
  metadata: { orderId: '42' },
});
// The call runs. Hang up later with:
await wayloVoice.stop();
  • Call start() from a click handler, before any await, so the browser allows audio playback.
  • start() resolves once the agent is ready (listening, thinking or speaking).
  • A WayloVoice starts once. Create a new one, with its own listeners, for the next call.
  • stop() is safe at any time and never rejects. During start() it makes start() reject with CANCELLED. After that it ends the call with reason caller_hangup.

Options

OptionMeaning
sessionEndpointRequired. Your server route that returns a session. Same-origin only (enforced).
headersOptional. () => Record<string, string> or a promise of one. Extra request headers.
agentTimeoutMsOptional. How long start() waits for the agent to be ready. Default 20000.

For a token-based app, add headers. The SDK calls it once per start() and sends the result only to sessionEndpoint. It never logs these headers or puts them in errors.

const wayloVoice = new WayloVoice({
  sessionEndpoint: '/api/waylo/session',
  headers: async () => ({ Authorization: `Bearer ${await getAppToken()}` }),
});

Listen to the call

wayloVoice.on('state', state => render(state)); // the whole snapshot on every change
wayloVoice.on('error', error => console.warn(error.code));

On this page