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

OptionTypeDefaultDescription
apiKeystringrequiredYour VoiceLayer API key
wsUrlstringwss://api.voicelayer.co/wsWebSocket server URL. Override to self-host.
selectorstring'input, textarea, [contenteditable]'CSS selector for elements to activate
trigger'space' | 'ctrl' | false'space'Keyboard trigger. Set to false to disable keyboard (tap-only)
triggerLabelstring'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
showBrandingbooleantrueShow "Powered by VoiceLayer" in the pill. Set to false on paid plans.
languagestring'en'BCP-47 language code for transcription
onTranscriptfunctionCallback fired with each final transcript. Return a string to override what's injected.
onErrorfunctionError callback (err: Error) => void

Instance methods

MethodDescription
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:

AttributeEquivalent option
data-keyapiKey
data-ws-urlwsUrl
data-show-brandingshowBranding ("false" to disable)
data-selectorselector
data-themetheme
data-triggertrigger
data-languagelanguage
<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);