SDKs & CLI
Official JavaScript/TypeScript SDK and command-line tool for the ListenHub API, plus guidance on when to use each.
ListenHub ships two official client libraries on top of the OpenAPI: a JavaScript/TypeScript SDK and a command-line tool. Both talk to the same endpoints, unwrap the standard { code, message, data } envelope for you, and handle 429 retries automatically — so you write less plumbing than calling the HTTP API directly.
Pick your tool
JavaScript SDK
Typed client for Node and browsers. Use it inside an app, a backend service, or a script.
Command-line tool
Run podcasts, TTS, images, music, and video from your terminal or a CI job — no code required.
Install
npm i @marswave/listenhub-sdkESM-only. Requires Node.js >= 20.
npm i -g @marswave/listenhub-cliInstalls the listenhub binary globally. Requires Node.js >= 20.
Which one should I use?
| You want to… | Reach for |
|---|---|
| Build a product feature that generates audio, images, or video | SDK (OpenAPIClient for servers, ListenHubClient for user-facing apps) |
| Script a one-off job, batch generation, or a CI/CD step | CLI — pipe --json output through jq |
| Explore endpoints, parameters, and exact response shapes | OpenAPI reference |
| Drive ListenHub from an AI agent or assistant | MCP server |
The SDK and CLI are convenience layers. Anything they do, you can also do with raw HTTP against the OpenAPI — the reference is the source of truth for every endpoint, parameter, and enum.
Two auth models
Both clients support the same two ways to authenticate. Choose based on where the code runs.
- API key — for servers, scripts, and CI. Pass the key as
Authorization: Bearer $LISTENHUB_API_KEY. Create keys at listenhub.ai/settings/api-keys. In the SDK this isOpenAPIClient; in the CLI it is thelistenhub openapi …command group. - OAuth login — for interactive and user-facing use, where actions run on behalf of a signed-in account. In the SDK this is
ListenHubClient; in the CLI it islistenhub auth login, which opens a browser and stores tokens under~/.config/listenhub/.
Treat API keys as secrets. Keep them server-side — never ship a key in browser or mobile client code. For user-facing apps, use OAuth so each request runs under the user's own account.
// Server-side, API key
import { OpenAPIClient } from '@marswave/listenhub-sdk';
const client = new OpenAPIClient({ apiKey: process.env.LISTENHUB_API_KEY });
const { items: speakers } = await client.listSpeakers({ language: 'en' });# Same thing from the terminal
export LISTENHUB_API_KEY="lh_sk_..."
listenhub openapi speakers list --language en --jsonError handling at a glance
Every response is wrapped in { "code": 0, "message": "", "data": { … } }. A non-zero code means an error.
- SDK — unwraps
dataoncode 0and throwsListenHubError(withstatus,code, andrequestId) otherwise. On429, it readsRetry-Afterand retries up tomaxRetries(default2).client.apiis a ky escape hatch for endpoints the SDK does not wrap yet. - CLI — prints errors to stderr and uses exit codes:
0success,1error,2auth,3timeout. Long-running generations poll every 10s; pass--no-waitto return the ID immediately or--timeout <s>to bound the wait.