Agent Web SDK
A JavaScript library that opens a live voice conversation with a Smallest agent from a web page. Published on npm as @smallest-ai/agent-sdk. Wraps the Realtime Agent WebSocket API, plus microphone capture, PCM playback, and an event API.
When to use it
- Voice widget or “click to talk” button on a marketing or product site.
- In-app voice input in a web dashboard.
- Agent demo, playground, or sandbox pages.
- Any browser experience where the user speaks to a Smallest agent and hears a reply.
When to use something else
You need an API key (from app.smallest.ai/dashboard/api-keys) and an agent ID. Create an agent from the Agents dashboard or follow the Developer Quickstart.
Install
Quickstart
Do not put your raw API key in a browser. On your server, call
POST /conversation/register-call to get a short-lived, single-use access
token. See the Register Call endpoint under Realtime Agent in the API
reference. Then pass that token as apiKey. For the full three-step flow, see
the Browser Voice Cookbook.
A raw sk_ key also works. Use it only on a server or on a trusted client.
The CDN equivalent uses the AtomsSdk global:
connect() calls navigator.mediaDevices.getUserMedia(). A browser gives access to the microphone only on a secure context. In production, use HTTPS. In development, you can also use http://localhost or http://127.0.0.1. If you serve the page from a different HTTP origin, the browser throws a permission error.
Configuration
You do not declare your input format. The SDK reads the rate the browser actually gave its AudioContext and sends that as input_audio_format at connect, on both auth paths. Declaring one on /register-call has no effect when you use this SDK, because the measured value replaces it. The SDK resamples automatically, so the format it declares always matches the audio it sends. See Audio Formats.
Output depends on how you authenticate. With a /register-call token the backend already chose the format and outputAudioFormat is ignored. With a raw API key nothing has chosen it, so set outputAudioFormat; leave it unset for pcm_24000. pcm_44100 needs a lightning-v3.1 voice, and a rate the agent’s voice cannot render is refused at connect.
sampleRate only controls microphone capture; it does not set the session’s audio rate. Lower it if your users are on metered connections.
Methods
Events
Subscribe with agent.on(eventName, handler).
Patterns
Push-to-talk
Connect normally, mute immediately, then toggle on button events.
Do not use autoCaptureMic: false for push-to-talk. That mode does not start the microphone. No public method starts the microphone after connect(). Thus mute() and unmute() do nothing, and isMuted always returns false. Keep the default value autoCaptureMic: true. Then call mute() immediately after connect().
Agent-speaking indicator
Reflect agent turn state in the UI.
Clean teardown on page unload
Text input
Send a text message instead of speech. The reply still returns as audio.
Error handling
Errors arrive through three different paths. Handle each.
Handshake failure (bad API key, wrong agent ID, network issue, denied microphone permission) rejects the connect() promise with a generic Error("WebSocket connection failed"). The error event does not fire for these.
Mid-session server error arrives as an error event with { code, message }. These are sent by the server during an active session, not during the handshake.
Session termination fires session_ended with a reason string. Handle this to detect both graceful ends and abnormal closes.
Smoke-test the integration
A minimal standalone test to confirm the SDK reaches the agent and produces audio. No build step required.
Serve it from localhost and open with the key and agent ID in the query string:
Expected console output, in order: session_started with session_id and call_id, then agent_start_talking, then agent_stop_talking after the agent’s first turn completes. If the agent has a greeting, it plays through the default audio output.
Limitations
For non-browser runtimes, connect to the Realtime Agent WebSocket API directly. A raw-protocol guide with tested reference clients for Python, React Native, Swift, and Kotlin is in progress.

