The official TypeScript/JavaScript SDK for KugelAudio provides a modern, type-safe interface for text-to-speech generation in Node.js and browsers.
The source is MIT-licensed and on GitHub at
Kugelaudio/js-sdk; issues and pull requests are
welcome there.
Installation
The SDK requires Node.js 18 or newer. The ws WebSocket package is installed
with it, so Node needs nothing extra.
Or with yarn/pnpm:
TypeScript types ship inside the package. There is no @types/kugelaudio to
install, and no extra configuration is required.
Module systems
The SDK ships both an ESM and a CommonJS build, each with its own type
declarations, so it works from either module system without a bundler or
transpiler.
Use named imports. The package intentionally has no default export, so
import KugelAudio from 'kugelaudio' is a type error.
Types resolve correctly under every TypeScript moduleResolution setting
(node, node16, nodenext, and bundler) for the main entry point and for
the kugelaudio/livekit subpath.
Quick Start
Create an API key at app.kugelaudio.com/settings/api-keys
and keep it out of your code, for example in an environment variable (see
Authentication). The SDK does not read the
environment on its own, so pass the key explicitly:
In a browser, play the audio instead: see
Playing audio in the browser.
Pre-connecting for Low Latency
For latency-sensitive applications, pre-establish the WebSocket connection at startup to keep the handshake out of your first TTS request. See Latency.
In the examples below, playAudio stands for your own playback function; the SDK does not ship one.
Using the Factory Method (Recommended)
Manual Connection
Without pre-connecting, the first TTS request includes WebSocket connection setup.
Subsequent requests reuse the connection. See Latency for typical numbers.
Pre-connecting moves this overhead to application startup. Call
client.close() when you are done so the process can exit.
Complete Example
Browser Support
The SDK also runs in modern browsers, using the native WebSocket. The
credential travels in the WebSocket URL, so never ship a project API key to a
browser: run the SDK on your backend and forward the audio to the browser.
Next steps
-
Configuration: options, authentication modes, regions, lifecycle
-
Generate Speech: one-shot generation, streamed output, word timestamps, utilities
-
Streaming: LLM integration, session reuse, barge-in, multi-context
-
Text Normalization: numbers, dates, languages, spell tags
-
Voices: list, create, and manage voices
-
Dictionaries: per-project pronunciation and replacement lists
-
Speech to Text: transcribe audio files
-
Types & Errors: error classes and the full TypeScript reference
-
Agent skill: teach your coding assistant to write correct KugelAudio code
Last modified on September 23, 2026