# Node.js SDK

> Use @transcript1/sdk to transcribe video links and local files from server code. Download text or subtitles, track progress and handle errors.

Canonical: https://transcript1.com/docs/sdk
Last updated: 2026-11-08

Use `@transcript1/sdk` to create transcriptions, upload files and wait for results from TypeScript or JavaScript server code.

Use SDK 1.1.0 or newer for social links. SDK 1.0.1 accepts only YouTube links and rejects the new links locally. Run `npm i @transcript1/sdk@latest` to update.

That version is the baseline for the original six platforms. Twitch, Dailymotion, Pinterest, LinkedIn and Snapchat require an SDK release that includes those platforms; older clients can reject them locally.

## Install

```bash
npm i @transcript1/sdk
```

The examples use ES modules. Save them as `.mjs` files, or set `"type": "module"` in `package.json` for `.js` files. `require()` also works on Node 20.19+, for example `require('@transcript1/sdk')`.

## API key

Create a key on the [API keys page](https://transcript1.com/dashboard/account/tokens). Set `TRANSCRIPT1_API_KEY` in your server's environment, or pass `apiKey` to the constructor:

```javascript
import { Transcript1 } from '@transcript1/sdk';

const t1 = new Transcript1(); // reads TRANSCRIPT1_API_KEY
const other = new Transcript1({ apiKey: 't1_...' });
```

Without a key, the constructor throws `Transcript1Error` with code `missing_api_key`.

## Transcribe

`transcribe(input, options)` creates a job and waits for its transcript. It returns a `CompletedTranscription` with `status: 'completed'` and a `transcript` field. Failed or canceled jobs reject.

```javascript
const done = await t1.transcribe('https://youtu.be/dQw4w9WgXcQ');
console.log(done.transcript.text);

const file = await t1.transcribe('./interview.m4a', { speakers: true });
```

For a Buffer or Uint8Array, supply the filename so the SDK can identify the media type:

```javascript
import { readFile } from 'node:fs/promises';

const buffer = await readFile('./call.mp3');
const call = await t1.transcribe(buffer, { filename: 'call.mp3' });
```

Strings starting with `http://` or `https://` are links; other strings are file paths. YouTube, X, TikTok, Instagram, Facebook, Bluesky, Twitch, Dailymotion, Pinterest, LinkedIn and Snapchat links and file uploads are supported. See [Sources and options](https://transcript1.com/docs/sources-and-options) for the public recorded media forms, caption matrix and restrictions. The additional sources require HTTPS. Files can be up to 2,000,000,000 bytes, with extensions mp3, wav, m4a, flac, ogg, opus, mp4, mov, webm or mkv.

Social posts must be public. For posts with several videos, only the first video is transcribed. The API detects the platform from the link. See [Sources and options](https://transcript1.com/docs/sources-and-options) for accepted short links and limits.

You can also pass a Blob, a `ReadableStream<Uint8Array>` or an async iterable of Uint8Array chunks. A Blob needs `filename` unless it is a named File. Streams and async iterables need both `filename` and `size` in bytes.

## Download

`download(id, options)` waits for completion and returns a string. JSON is the API's JSON text, not a parsed object.

```javascript
const text = await t1.download(done.id); // text is the default
const withTimes = await t1.download(done.id, { timestamps: true });
const srt = await t1.download(done.id, { format: 'srt' });
const vtt = await t1.download(done.id, { format: 'vtt' });
const json = await t1.download(done.id, { format: 'json' });
```

`timestamps: true` works only with `text`; other formats reject with `invalid_input`. Failed or canceled jobs also make `download` reject.

## Background jobs

Use `transcriptions.create` to submit work without waiting for the transcript. For a file, it finishes uploading before returning.

```javascript
const job = await t1.transcriptions.create('./long-interview.mp4');
const now = await t1.transcriptions.get(job.id);
const finished = await t1.transcriptions.get(job.id, { wait: true });
```

Without `wait`, `get` returns the current state. With `wait: true`, it resolves when the job reaches `completed`, `failed` or `canceled`. Check `finished.status` before reading its transcript. Unlike `transcribe`, `get` does not reject because a job failed or was canceled.

## Translation

Pass `translateTo` (an ISO 639-1 code such as `pl`) to `transcribe` or `transcriptions.create` to translate the finished transcript. Translation is free, uses 0 minutes and produces text only; it is not dubbing. See [Translation](https://transcript1.com/docs/translation) for supported languages and behavior.

```javascript
const job = await t1.transcribe('https://youtu.be/dQw4w9WgXcQ', { translateTo: 'pl' });
console.log(job.translation); // { language: 'pl', status: 'completed' }
console.log(job.transcript.segments[0].translation);

// translate a completed transcription later (idempotent)
const { status } = await t1.transcriptions.translate(job.id, 'de');
const german = await t1.download(job.id, { format: 'srt', translation: { mode: 'only', language: 'de' } });
```

`translation` on `get` and `download` is `{ mode: 'only' | 'both', language: 'de' }`: segments carry the translation in that language next to the original text (`both`) or instead of it (`only`). Omit it to get the original text only. A language without a translation rejects with `translation_not_found` (404); a malformed language is `invalid_request` (422). `Segment.translation` is optional. `Transcription.translation` is `null` when none was requested, otherwise `{ language, status, error?, same_as_source? }` with `status` of `processing`, `completed` or `failed`. `Transcription.translations` lists every translation (`{ language, status, same_as_source? }`), oldest first. `same_as_source: true` marks a translation into the language the transcript is already in: nothing was translated, its text is the original, and text, SRT and VTT downloads show each line once.

`transcriptions.translate(id, language, { signal })` resolves to `{ transcription_id, language, status }`, plus `same_as_source: true` with `status: 'completed'` when the transcript is already in that language. It rejects with `not_found` (404), `transcript_not_ready` (409, the transcript is not completed yet) or `invalid_request` (422, bad language). Translation requires SDK 1.3.0 or newer, and choosing a language on `get` and `download` requires 1.4.0. `same_as_source` is typed from SDK 1.5.1.

## Live transcription

`t1.live` streams audio to transcript1 and gives you subtitle lines, with optional real-time translation, while people speak. It requires SDK 1.5.0 or newer. The [Live transcription](https://transcript1.com/docs/live) page has the protocol, billing and limits; this section covers the SDK.

```javascript
const live = await t1.live.start({ language: 'en', translateTo: 'es', sampleRate: 16000 });

live.on('line', line => render(line));
live.send(pcm); // Int16Array | Uint8Array | ArrayBuffer
live.lines; // every line so far, in order

const result = await live.end();
console.log(result.reason, result.transcriptionId, result.minutesCharged);
```

`live.start(options)` creates the session and resolves after it has started, so you can send audio at once. Options are `language` (`auto` by default), `translateTo`, `diarize`, `sampleRate` (8000 to 48000, default 16000), `save` (default `true`) and `signal`. Audio is raw PCM only: signed 16-bit little-endian, mono, at `sampleRate`.

| Method | Meaning |
|---|---|
| `live.send(audio)` | Send a chunk of PCM. About 100 ms per chunk works well, and at most 256 KB. |
| `live.finalize()` | Close the current line now, for example when the video is paused. |
| `live.end()` | Finish the session and save it. Resolves with `{ reason, transcriptionId, minutesCharged, connectedMs, audioMs }`. |
| `live.lines` | All lines so far, in order. A line is replaced when a newer version with the same `id` arrives. |
| `t1.live.capabilities()` | What live transcription supports right now, and the live rate. |
| `t1.live.get(id)` | The state of a session. |

Line fields are `camelCase`: `id`, `startMs`, `endMs`, `speaker`, `language`, `text`, `final` and `translation` (`{ language, text, final, sameLanguage? }`, or `null`). `sameLanguage` is `true` for a line already in the target language: its translation is its own text, so show the line once. `sameLanguage` needs SDK 1.5.1 or newer.

`live.on(event, handler)` returns a function that removes the handler:

| Event | Payload |
|---|---|
| `started` | `sessionId`, `transcriptionId`, `resumed`, `offsetMs`, and `sameLanguage` (`true` when the session's `language` equals `translateTo`, so no line is translated). |
| `line` | The line, with its latest text. Fires for partial and final updates. |
| `usage` | `connectedMs`, `audioMs`, `minutesCharged`, `minutesRemaining`. |
| `warning` | `code`: `balance_low`, `audio_dropped` or `idle_timeout_soon`. |
| `reconnecting` | `attempt`: the connection dropped and the SDK is resuming. |
| `reconnected` | The session is streaming again. |
| `ended` | The same object `end()` resolves with. |
| `error` | `code` and `message` of a non-fatal problem. |

Resume is built in. When the connection drops or the server asks clients to reconnect, the SDK gets a new token and reconnects with a backoff from 0.5 to 8 seconds, for up to 2 minutes. It replays the last 10 seconds of audio that you sent during the gap, and `end()` called during a reconnect still finishes cleanly.

`start` throws `Transcript1Error` with the API's code, for example `insufficient_minutes`, `unsupported_translation`, `too_many_live_sessions` or the retryable `live_capacity`. Every ending, including `balance_exhausted`, resolves `end()` and fires `ended`; endings never throw.

Node 22+, Bun, Deno and browsers use the built-in `WebSocket`. On Node 20, pass one in, for example from the `ws` package:

```javascript
import WebSocket from 'ws';
import { Transcript1 } from '@transcript1/sdk';

const t1 = new Transcript1({ WebSocket });
```

Without a `WebSocket`, `live.start` rejects with `websocket_unavailable`.

### Live in the browser

Never put an API key in a browser. The `@transcript1/sdk/live` entry point is the same live client without Node-only imports. It takes `getAccessToken`, which returns an OAuth access token. The SDK calls it for every new session and every reconnect, because access tokens expire after 1 hour:

```javascript
import { createLiveClient } from '@transcript1/sdk/live';

const client = createLiveClient({ getAccessToken: () => myApp.getOAuthAccessToken() });
const live = await client.start({ language: 'auto', sampleRate: 16000 });
```

`createLiveClient` returns the same `start`, `get` and `capabilities` as `t1.live`. See [Capture audio in a browser](https://transcript1.com/docs/live#capture-audio-in-a-browser) for turning the microphone into 16 kHz PCM.

## List, delete and account

```javascript
for await (const item of t1.transcriptions.list({ status: 'completed', limit: 50 })) {
  console.log(item.id, item.created_at);
}

await t1.transcriptions.delete(job.id);
const account = await t1.account();
console.log(account.minutes.remaining);
```

`list` fetches pages as you iterate. Filter by `status` or `platform` (`youtube`, `x`, `tiktok`, `instagram`, `facebook`, `bluesky`, `twitch`, `dailymotion`, `pinterest`, `linkedin`, `snapchat` or `upload`). `limit` is the page size, from 1 to 100; the API defaults to 20. Returned objects keep the API's `snake_case` fields. Treat `media_id` as an opaque string.

`delete` cancels a running job or deletes a finished job and its transcript. `account` returns your plan, minutes and limits.

## Options

The constructor accepts `apiKey`, `baseUrl`, `fetch` and `maxRetries`. `baseUrl` defaults to `TRANSCRIPT1_API_URL` when set, otherwise `https://api.transcript1.com`. Pass `fetch` to use your own implementation. `maxRetries` defaults to 2 and accepts integers from 0 to 10.

`transcribe` and `transcriptions.create` share these options:

| Option | Meaning |
|---|---|
| `speakers` | Request speaker labels. |
| `language` | `auto` (default) or an ISO 639-1 language code. |
| `source` | `auto` or `stt` for links. YouTube, X, TikTok, Bluesky, Dailymotion and LinkedIn also accept `captions` when a usable track exists. |
| `translateTo` | Translate the finished transcript into this ISO 639-1 language. See [Translation](https://transcript1.com/docs/sdk#translation). |
| `fresh` | For links, skip reusing a transcription from the last 24 hours. |
| `filename` | Required for Buffers, unnamed Blobs and streams. Can override a file's name. |
| `size` | Required for streams and async iterables, in bytes. |
| `idempotencyKey` | Defaults to a new UUID per call. |
| `onProgress` | Receive progress events. |
| `signal` | An AbortSignal to cancel the call. |

`transcriptions.get` accepts `wait`, `includeWords`, `translation`, `onProgress` and `signal`. Use `includeWords: true` for word timings; `onProgress` reports changes while waiting.

`download` accepts `format`, `timestamps`, `translation` and `signal`. `list` also accepts `signal`. Pass `{ signal }` as the options argument to `transcriptions.delete(id, options)` or `account(options)`.

## Progress

Pass `onProgress` to `transcribe`, `transcriptions.create` or a waiting `transcriptions.get` call:

```javascript
await t1.transcribe('./interview.m4a', {
  onProgress(event) {
    console.log(event);
  },
});
```

| Event type | Fields |
|---|---|
| `upload` | `sent` and `total`, in bytes. |
| `status` | `status`: the job's current status. |
| `waiting_slot` | `retryAfter`: seconds until the next attempt to get a job slot. |
| `reconnecting` | No extra fields; emitted once per connection outage while waiting. |

## Cancel a call

Pass an `AbortSignal` from an AbortController to cancel a call, or use `AbortSignal.timeout` to set a time limit:

```javascript
await t1.transcribe('https://youtu.be/dQw4w9WgXcQ', {
  signal: AbortSignal.timeout(10 * 60_000),
});
```

An abort before the first request rejects with `aborted` and no job id. During an upload, the SDK tries to delete the job if it is still `awaiting_upload`, then rejects with `aborted` and the id.

Aborting a wait leaves the job running. The error's `transcriptionId` lets you resume with `transcriptions.get(id, { wait: true })`. To cancel the job itself, call `transcriptions.delete(id)`.

While waiting for a job, the SDK retries network errors and HTTP 429, 500, 502, 503 and 504 responses without a retry limit. Reconnection waits increase from 2 to 4, 8, 16 and then 30 seconds. Other requests use `maxRetries`. Job creation waits and retries when all active-job slots are busy. Use `signal` to bound the total time.

## Errors

Catch `Transcript1Error` to read API, job and SDK error codes:

```javascript
import { Transcript1Error } from '@transcript1/sdk';

try {
  await t1.transcribe('./call.mp3');
} catch (error) {
  if (error instanceof Transcript1Error) {
    console.error(error.code, error.message, error.transcriptionId);
  }
}
```

| Field | Meaning |
|---|---|
| `message` | Description of the error. |
| `code` | API or job failure code, `canceled`, or a local SDK code. |
| `status` | HTTP status, absent for job and local errors. |
| `details` | Extra API error fields, such as `minutes_needed` or `action_url`; defaults to an empty object. |
| `retryable` | Whether another attempt may help; defaults to false. |
| `transcriptionId` | Job id when available. |
| `transcription` | Last transcription object when available. |

Local codes are `missing_api_key`, `invalid_input`, `aborted`, `network_error`, `upload_token_refused` and `websocket_unavailable`. Non-JSON error responses use `http_<status>`.

A failed job without an error object produces `transcription_failed`. If a completed job has no transcript after fetching it, `transcribe` rejects with `internal_error`. See [Errors](https://transcript1.com/docs/errors) for API codes and [API reference](https://transcript1.com/docs/api-reference) for response fields.

## Runtimes

Node 20.19+. Bun and Deno should work through their `node:` compatibility; the automated tests run on Node only. Use the SDK with an API key server-side only; never ship an API key to a browser. The browser entry point for [live transcription](https://transcript1.com/docs/sdk#live-in-the-browser) takes an OAuth access token instead.
