@supertone/supertone on npm. Source: supertone-inc/supertone-ts.
At a glance
| Package | @supertone/supertone on npm |
| Repo | supertone-inc/supertone-ts |
| Languages | TypeScript 5+ / Node 18+ |
| Module formats | ESM + CommonJS |
| Auth | new Supertone({ apiKey: ... }) |
| Sync API | n/a |
| Async API | All methods (Promises) |
| Streaming | ReadableStream reader |
| Auto-chunk long text | ✅ 300 chars, sequential |
| Custom retries | ✅ via retryConfig |
| HTTP backend | fetch |
Installation
- npm
- pnpm
- bun
- yarn
fetch and ReadableStream). Works in Bun and Deno; not designed for the browser (your API key should never live client-side).
Set your API key
Generate speech
Stream speech
sona_speech_1 only.
Long text auto-chunking
createSpeech and streamSpeech both auto-chunk text longer than 300 characters. Pass the text as-is — the SDK splits it, generates each segment, and merges (or streams) the result.
predictDuration does not auto-chunk — its 300-character limit is enforced.
See Long text for details.
Common operations
Type-safe enums (optional)
For type safety, the SDK exposes enum constants in@supertone/supertone/models:
"en", "sona_speech_1") work too — use whichever style you prefer.
Error handling
Errors live in@supertone/supertone/models/errors and all extend SupertoneError:
| Error class | HTTP status |
|---|---|
BadRequestErrorResponse | 400 |
UnauthorizedErrorResponse | 401 |
PaymentRequiredErrorResponse | 402 |
ForbiddenErrorResponse | 403 |
NotFoundErrorResponse | 404 |
RequestTimeoutErrorResponse | 408 |
PayloadTooLargeErrorResponse | 413 |
UnsupportedMediaTypeErrorResponse | 415 |
TooManyRequestsErrorResponse | 429 |
InternalServerErrorResponse | 500 |
ConnectionError, RequestTimeoutError, RequestAbortedError, etc.) extend HTTPClientError, not SupertoneError.
Configuration
Related
Python SDK
The equivalent SDK for Python.
Examples
Recipes for common workflows.