JavaScript SDK
bakbak is the official JavaScript and TypeScript client for the Bakbak
text-to-speech API. It has no runtime dependencies, is typed end to end, and
runs on Node 20+, Bun, Deno, Cloudflare Workers and browsers.
Install
Quickstart
Request fields keep the API’s names (voice_id, output_format), so code, curl
and the API reference read the same.
Whole files
Streaming (SSE)
An AudioStream can also become a ReadableStream (stream.toReadableStream()),
for example to answer an HTTP request with audio as it is generated.
WebSocket for voice agents
The WebSocket carries many requests over one connection, the fastest path to first audio. Requests on a context play in order; different contexts run at the same time.
Speak an LLM’s reply as it is written
sendStream() splits the tokens into sentences and sends each one as soon as it
is complete. It accepts strings and stream events from the OpenAI, Anthropic,
Google Gemini and Vercel AI SDKs, and Gemini’s raw REST JSON. If the stream
yields events it can’t read and no text at all, it throws instead of sending
nothing; map such events to strings first.
Interruptions
stops the running request, drops queued ones, discards audio not yet played and
stops a sendStream feeding the context. The context stays usable.
Voices
Errors
Everything the SDK throws is a BakbakError. Errors from the service have
status, errorCode, message, retryable and requestId (see
Errors).
Retries and timeouts
Failures before any audio are retried up to maxRetries times (default 2),
honouring Retry-After. Once audio has been delivered the SDK never retries.
Browsers
An API key in a web page is visible to anyone who uses the page. The SDK refuses
to run in a browser with a key unless you pass dangerouslyAllowBrowser: true;
call the API from your server instead.
The README covers every option, runtimes, telephony formats and the sentence segmenter.

