SDK Reference
Complete API documentation for @voicelayer/sdk.
VoiceLayer.init(config)
Initialize the SDK. Returns a VoiceLayer instance. Call once per page — subsequent calls destroy the previous instance.
const vl = VoiceLayer.init({
apiKey: 'pk_live_YOUR_KEY',
// ... options
});
Config options
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | required | Your VoiceLayer API key |
| wsUrl | string | wss://api.voicelayer.co/ws | WebSocket server URL. Override to self-host. |
| selector | string | 'input, textarea, [contenteditable]' | CSS selector for elements to activate |
| trigger | 'space' | 'ctrl' | false | 'space' | Keyboard trigger. Set to false to disable keyboard (tap-only) |
| triggerLabel | string | 'Space' | Label shown in the pill indicator |
| theme | 'light' | 'dark' | 'auto' | 'auto' | Pill indicator color scheme |
| position | 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | 'bottom-right' | Pill position relative to the focused input |
| showBranding | boolean | true | Show "Powered by VoiceLayer" in the pill. Set to false on paid plans. |
| language | string | 'en' | BCP-47 language code for transcription |
| onTranscript | function | — | Callback fired with each final transcript. Return a string to override what's injected. |
| onError | function | — | Error callback (err: Error) => void |
Instance methods
| Method | Description |
|---|---|
| destroy() | Remove all listeners, disconnect WebSocket, and remove the indicator from the DOM |
| VoiceLayer.getInstance() | Static method — returns the current active instance or null |
onTranscript callback
Called with each finalized transcript segment. Return a modified string to override what gets injected into the input.
VoiceLayer.init({
apiKey: 'pk_live_YOUR_KEY',
onTranscript: (text) => {
console.log('Got:', text);
// Auto-capitalize first letter
return text.charAt(0).toUpperCase() + text.slice(1);
// Or just observe without modifying:
// (don't return anything)
},
});
data-* attributes (script tag)
When using the script tag integration, all config options can be passed as data-* attributes:
| Attribute | Equivalent option |
|---|---|
| data-key | apiKey |
| data-ws-url | wsUrl |
| data-show-branding | showBranding ("false" to disable) |
| data-selector | selector |
| data-theme | theme |
| data-trigger | trigger |
| data-language | language |
<script
src="https://voicelayer.co/sdk.js"
data-key="pk_live_YOUR_KEY"
data-show-branding="false"
data-theme="dark"
data-selector="textarea">
</script>
TypeScript support
The SDK is written in TypeScript and ships full type definitions. Import types directly:
import { VoiceLayer, VoiceLayerConfig } from '@voicelayer/sdk';
const config: VoiceLayerConfig = {
apiKey: process.env.VOICELAYER_KEY!,
showBranding: false,
onTranscript: (text) => text.trim(),
};
const vl = VoiceLayer.init(config);