TypeScript SDK
@transcodely/sdk is the official TypeScript / JavaScript SDK for the Transcodely API. It runs on Node.js 20+, ships with full type definitions for every request and response, and bundles a hand-rolled Connect-RPC transport so you don’t need to install Connect-ES separately. The SDK is still pre-1.0 — breaking changes are possible on minor bumps until 1.0.0.
Install
npm install @transcodely/sdk
# or
pnpm add @transcodely/sdk
# or
yarn add @transcodely/sdkThe SDK has one dependency, @bufbuild/protobuf ^1.10.0, used for generated message types. Most package managers will install it automatically.
Command line
The package also ships the transcodely command-line tool. It runs without installing anything:
export TRANSCODELY_API_KEY={{API_KEY}}
npx @transcodely/sdk upload ./video.mp4
npx @transcodely/sdk upload https://example.com/talk.mp4 --wait
npx @transcodely/sdk --helpupload takes a local file or a public http(s) URL, encodes it, hosts it and prints the video’s playback link. Without --preset it encodes at your app’s hosting quality, which is standard by default and runs on the free tier too; there a video longer than 2 minutes is shortened to its first 2 minutes, and its truncation says so. It acts in the API key’s own app unless --app, TRANSCODELY_APP_ID or an app saved with login --app names another. --json prints one JSON document instead of human output, including on failure, and the exit code is 0 on success, 1 when the API refused the request (or, with --wait, when the video ended anywhere but ready), and 2 for a wrong command line. In a project that depends on the SDK, the same tool is npx transcodely-sdk. It is a separate build that the library never imports, so import { Transcodely } from "@transcodely/sdk" does not load it.
Authenticate
The SDK takes the API key as an explicit constructor argument. The conventional environment variable is TRANSCODELY_API_KEY.
import { Transcodely } from "@transcodely/sdk";
const client = new Transcodely({
apiKey: process.env.TRANSCODELY_API_KEY!,
});Never embed an API key in browser code; the main entry is server-side only. Browser uploads go through the /upload and /react subpaths, which never hold an API key; see Browser Uploads.
Create your first job
Resource methods live under lazy namespaces (client.jobs, client.videos, etc.). Method arguments are typed PartialMessage<T> shapes that auto-complete from the proto schema.
import {
Transcodely,
OutputFormat,
VideoCodec,
Resolution,
QualityTier,
} from "@transcodely/sdk";
const client = new Transcodely({ apiKey: process.env.TRANSCODELY_API_KEY! });
const job = await client.jobs.create({
inputUrl: "https://www.transcodely.com/samples/transcodely-sample-30s.mp4",
managed: true,
outputs: [
{
type: OutputFormat.HLS,
video: [
{ codec: VideoCodec.H264, resolution: Resolution.RESOLUTION_1080P, quality: QualityTier.STANDARD },
{ codec: VideoCodec.H264, resolution: Resolution.RESOLUTION_720P, quality: QualityTier.STANDARD },
],
},
],
});
console.log(job.id, job.status);It points at a public sample clip and delivers to Transcodely hosting, so it runs before you own any storage. It asks for standard quality, which the free tier includes; only premium needs a payment method. Method args use camelCase (inputUrl); the SDK serializes them to snake_case (input_url) on the wire automatically.
Watch a job to completion
client.jobs.watch(id) returns an AsyncIterable that emits one event per job-state change, auto-reconnecting on transient failures. Heartbeats are filtered by default. Pass an AbortSignal to cancel from your side:
import { JobStatus } from "@transcodely/sdk";
const ac = new AbortController();
setTimeout(() => ac.abort(), 10 * 60 * 1000); // 10-minute ceiling
for await (const event of client.jobs.watch(job.id, { signal: ac.signal })) {
console.log(event.event, event.job?.status, event.job?.progress);
if (
event.job?.status === JobStatus.COMPLETED ||
event.job?.status === JobStatus.FAILED ||
event.job?.status === JobStatus.CANCELED
) {
break;
}
}The SDK retries the underlying server-side stream on APIConnectionError with exponential backoff and re-emits a SNAPSHOT event on every reconnect, so resuming is idempotent on the consumer side.
List with auto-pagination
Every list method returns a Page<T> that you can either await for a single page or .autoPage() over to walk every result.
// Single page
const page = await client.jobs.list({ pagination: { limit: 50 } });
console.log(page.items, page.nextCursor);
// All items, automatically across pages
for await (const job of client.jobs.list({ pagination: { limit: 50 } }).autoPage()) {
console.log(job.id, job.status);
}autoPage() stops when the API returns an empty next_cursor. See Pagination for the cursor model.
Generate insights from existing captions
A hosted video that already has AI captions can get AI insights without transcribing again. Only the insights fee is billed, €0.05 per video plus €0.005 per minute of source, and only when the insights become ready. The call returns the TranscriptInsights entry in pending; pass the language only when the video has more than one AI caption track. See GenerateInsights.
const ins = await client.videos.generateInsights({
id: "vid_a1b2c3d4e5f6g7",
language: "eng", // only when the video has several AI caption tracks
});
console.log(ins.id, ins.status); // ins_..., InsightsStatus.PENDINGThe entry also appears on video.insights. The video.insights.ready and video.insights.failed webhook events carry the entry itself, not a Video: inside client.webhooks.isEventType(event, "video.insights.ready") (or a switch after isKnownEvent), event.data is a TranscriptInsights.
Your prices
client.apps.getPricing() lists every chargeable item with the EUR rate your app pays, a custom flag where your account has its own rate, and the public list price beside it. Omit the app id to price the API key’s own app. See Custom pricing and GetPricing.
const pricing = await client.apps.getPricing();
for (const entry of pricing.entries) {
if (entry.custom && entry.basePrice !== undefined) {
console.log(entry.label, entry.basePrice, pricing.currency, "list", entry.listBasePrice);
}
}Prices are fixed when a job is created, so a rate change applies to jobs created after it.
Handle typed errors
Every error inherits from TranscodelyError. Match concrete classes with instanceof:
import {
Transcodely,
TranscodelyError,
AuthenticationError,
NotFoundError,
RateLimitError,
InvalidRequestError,
} from "@transcodely/sdk";
try {
await client.jobs.create({ inputUrl: "...", outputs: [] });
} catch (err) {
if (err instanceof InvalidRequestError) {
for (const v of err.errors) {
console.error(`${v.field}: ${v.description}`);
}
} else if (err instanceof RateLimitError) {
await new Promise((r) => setTimeout(r, err.retryAfterMs ?? 1000));
} else if (err instanceof NotFoundError) {
console.error("not found:", err.message);
} else if (err instanceof AuthenticationError) {
console.error("bad API key");
} else if (err instanceof TranscodelyError) {
console.error(`[${err.requestId}] ${err.code}: ${err.message}`);
} else {
throw err;
}
}Every error carries code, httpStatus, requestId, and raw (the original response body). See Errors for the full hierarchy.
Override idempotency
client.jobs.create automatically generates a UUID v4 Idempotency-Key so retrying within the same process is safe. For cross-process safety (queue workers, cron jobs), pass your own:
const job = await client.jobs.create({
inputUrl: "...",
outputOriginId: "ori_x9y8z7w6v5",
outputs: [/* ... */],
idempotencyKey: `transcode_asset_${assetId}_v1`,
});All other write methods also ship an Idempotency-Key automatically. See Idempotency for replay semantics and key-format guidance.
Request IDs
The most recent request ID is exposed for log correlation:
const job = await client.jobs.get("job_a1b2c3d4e5f6");
console.log(client.lastRequestId); // "req_..."Errors also carry err.requestId directly.
Configuration
Pass any of these to the constructor:
| Option | Default | Notes |
|---|---|---|
apiKey | — required — | Your Transcodely API key |
baseUrl | https://api.transcodely.com | Override for staging or self-hosted |
timeoutMs | 30000 | Request timeout in milliseconds |
maxRetries | 3 | Retries on network errors, 5xx, 429, 503 with jittered backoff |
apiVersion | calendar version baked at SDK build time | Sent as Transcodely-Version |
defaultHeaders | — | Record<string, string> — sent on every request |
fetchImpl | globalThis.fetch | Inject a custom fetch (testing, browser shims) |
logger | — | (event: LogEvent) => void — structured request log hook |
const client = new Transcodely({
apiKey: process.env.TRANSCODELY_API_KEY!,
timeoutMs: 60_000,
maxRetries: 5,
defaultHeaders: { "X-Caller": "ingest-worker" },
logger: (event) =>
console.log(`${event.service}/${event.method} ${event.status ?? "-"} ${event.durationMs}ms`, event.requestId),
});LogEvent carries service, method, durationMs and attempt on every call, plus status, requestId and error when the response (or failure) supplied them. The hook fires on every
attempt rather than once per call, so a retried call produces several entries — attempt distinguishes them. A logger that throws is swallowed and never breaks the request.
Where to go next
- API Reference — the full RPC surface, with request and response shapes.
- Webhook Integration — verify signed deliveries and handle events with
client.webhooks.constructEvent. - Errors — the typed error hierarchy in one place.
- Pagination — cursor model and auto-paging idioms.
- Idempotency — when and how to set your own key.
- SDK source on GitHub — full source, runnable examples in
examples/, and changelog.