Skip to content
VoiceMint Developers

Web widget

A <voicemint-agent> voice button for any website. The page never holds a secret key.

@voicemint/widget is a Web Component (<voicemint-agent>, no dependencies, about 11 kB gzipped) that puts a voice button on any page and talks to an agent live.

How it works#

The widget never sees your secret key. It POSTs {"agent_id"} to an endpoint on your server, which mints a voice-session token with your key and returns it; the widget then opens the live socket with that token.

html
<voicemint-agent agent-id="AGENT_ID" token-endpoint="/voicemint-token"></voicemint-agent>
<script src="/voicemint-widget.js"></script>

Your token endpoint, with the server SDKs:

# what your endpoint does, as one HTTP call
curl -X POST https://api.voicemint.io/api/v1/agents/AGENT_ID/live-sessions \
  -H "Authorization: Bearer $VOICEMINT_API_KEY"

Check that the signed-in user may talk to that agent before minting: each session spends your credits.

Install#

Not on npm yet. Until it is, ask us for the built voicemint-widget.js (or build it from the source) and host it next to your page. Once published: npm install @voicemint/widget, or the script from a CDN.

Sites with a Content Security Policy need connect-src wss://api.voicemint.io and worker-src blob:.

Events#

The element dispatches voicemint:error with the close code (4402 out of credits, 4403 not allowed, 4404 agent not found, 4429 busy) and fetches a fresh token once on 4401.