Skip to main content
The Hamsa Web SDK (@hamsa-ai/voice-agents-sdk) starts calls with your Hamsa agents from a web page: voice calls through the visitor’s microphone, or text chats. You build the interface; the SDK connects the call, plays the agent, and tells your page what happens through events. If you only need a button on your site, you don’t need the SDK: embed the widget with one script tag.

Before you start

  • An agent published to an environment. Calls run what the environment (dev, staging or prod) serves, never the draft. See Environments and releases.
  • A public key for that environment. Create it on the API keys page, under Website or app. Limit it to your site with Allowed origins.
  • A secure page. Browsers give the microphone only to pages served over https://, or from localhost while you build.
  • A current browser. Chrome, Edge, Firefox or Safari, on desktop or mobile.

Install

Without a build step, load it from a CDN. Pin the version, so your page doesn’t change when a new one is released:
The script puts the SDK on window.HamsaVoiceAgent: the class is HamsaVoiceAgent.HamsaVoiceAgent and the error class is HamsaVoiceAgent.HamsaApiError.

Quickstart: a call button

A button that starts a call, shows what the agent is doing, and ends the call:
When the visitor clicks the button:
  1. start() gets a call token with your public key and connects the call.
  2. The browser asks for the microphone the first time.
  3. callStarted fires with jobId, the call’s ID. It’s the same ID you see in Call history and in the agent’s webhook.
  4. The agent says its greeting, and agentStateChanged follows the conversation.
  5. agent.end(), or the agent ending the call, fires callEnded.
Replace pk_... with your public key and YOUR_AGENT_ID with the agent’s ID (in the editor’s menu, Copy agent ID).

Pass values to the agent

params fill the agent’s variables. An agent whose greeting is “Hello {{customer_name}}” greets Sara by name:
See Pass values when a call starts.

Next steps

Start calls

Public keys or call tokens from your server, the microphone, and why a call can’t start.

During a call

End, pause, mute, volume, keypad digits and the call’s ID.

Chat

Text conversations without a microphone.

Events

Every event, what it sends, and live transcripts.

Audio

Levels, visualizers, and capturing the call’s audio.

Reference

Every option and method, with types.
Already starting calls with an older API key? See Migrate.

Good to know

  • Leaving the page ends the call. Closing the tab, reloading or going to another site hangs up. In a single-page app, keep the HamsaVoiceAgent outside the views that come and go.
  • The screen stays on during a call, on devices that support it. It can sleep again while the call is paused.
  • Website calls count like phone calls. They use credits, count against your plan’s concurrent calls, show in Call history, and send the agent’s webhook.
  • Page tools. The agent can call functions in your page, such as reading the cart. See Web tools.
  • Debugging. new HamsaVoiceAgent({ publicKey: "pk_...", debug: true }) logs what the SDK does to the browser console.