@transcribe-api/sdk 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -52,7 +52,8 @@ console.log(result);
52
52
  The SDK automatically chooses the right API flow:
53
53
 
54
54
  - One small local file is sent through the direct synchronous upload path.
55
- - Remote URLs, webhook jobs, multiple files, files larger than 30 MB, and files estimated over 10 minutes are sent through the async job flow.
55
+ - One remote URL is sent through the direct `/v1/transcribe` endpoint and the API decides whether it can finish immediately or should continue as an async job.
56
+ - Multiple files, files larger than 30 MB, and files estimated over 10 minutes are sent through the async job flow.
56
57
  - Large local async uploads use signed R2 upload URLs returned by the API.
57
58
  - Multipart upload is used automatically when the backend returns multipart upload instructions.
58
59
  - If `polling` is configured, async calls wait until the job reaches a terminal status.
@@ -131,7 +132,7 @@ const job = await client.transcribe({
131
132
  });
132
133
  ```
133
134
 
134
- Remote URL jobs are async because the API fetches the audio from the URL.
135
+ For one remote URL, the SDK submits the request to the direct `/v1/transcribe` endpoint and lets the API decide the final route. Small remote files may complete immediately, while larger or longer remote files automatically fall back to the async job flow.
135
136
 
136
137
  ## Batch and mixed input transcription
137
138
 
@@ -184,6 +185,8 @@ You can also pass a comma-separated string:
184
185
  exclude: "metadata,billing"
185
186
  ```
186
187
 
188
+ For single-file outputs, if `exclude` leaves only one transcript field and removes metadata, billing, and detected language, the API returns that remaining value directly instead of a JSON object. Text-only responses return a plain string, VTT-only responses return a plain string, and segments-only responses return an array. Multi-file outputs still return JSON so each result stays associated with its `reference_id`.
189
+
187
190
  ## Webhooks
188
191
 
189
192
  ```js
@@ -195,7 +198,7 @@ const job = await client.transcribe({
195
198
  });
196
199
  ```
197
200
 
198
- Any request with `webhookUrl` uses the async job flow.
201
+ For a single file or URL, `webhookUrl` is sent through the direct `/v1/transcribe` endpoint and the API decides whether it can finish immediately or should continue as a job. Multi-file requests still use the async batch flow.
199
202
 
200
203
  ## Progress and logs
201
204
 
package/index.js CHANGED
@@ -1364,8 +1364,6 @@ export class TranscribeAPI {
1364
1364
  : (normalizedItem.durationEstimateSec || await estimateDurationFromFile(normalizedSingleFile));
1365
1365
  const effectiveLanguage = normalizedItem.hasLanguage ? normalizedItem.language : normalizeLanguageCode(language);
1366
1366
  const isAsync = files.length > 1
1367
- || Boolean(normalizedItem.url)
1368
- || Boolean(webhookUrl)
1369
1367
  || (
1370
1368
  normalizedSingleFile
1371
1369
  && (
@@ -1387,6 +1385,18 @@ export class TranscribeAPI {
1387
1385
  });
1388
1386
  }
1389
1387
 
1388
+ if (normalizedItem.url) {
1389
+ return this.transcribeUrlDirect({
1390
+ url: normalizedItem.url,
1391
+ referenceId: normalizedItem.referenceId,
1392
+ language: effectiveLanguage,
1393
+ exclude,
1394
+ webhookUrl,
1395
+ showLogs: showLogs ?? this.showLogs,
1396
+ logger: logger ?? this.logger,
1397
+ });
1398
+ }
1399
+
1390
1400
  return this.transcribeDirect({
1391
1401
  file: normalizedSingleFile,
1392
1402
  referenceId: normalizedItem.referenceId,
@@ -1485,6 +1495,44 @@ export class TranscribeAPI {
1485
1495
  return result;
1486
1496
  }
1487
1497
 
1498
+ async transcribeUrlDirect({
1499
+ url,
1500
+ referenceId,
1501
+ language,
1502
+ exclude,
1503
+ webhookUrl,
1504
+ showLogs = false,
1505
+ logger = console,
1506
+ } = {}) {
1507
+ const form = new FormData();
1508
+ form.set("url", String(url || "").trim());
1509
+ if (String(referenceId || "").trim()) form.set("reference_id", String(referenceId).trim());
1510
+ if (language) form.set("language", language);
1511
+ if (exclude) form.set("exclude", Array.isArray(exclude) ? exclude.join(",") : exclude);
1512
+ if (webhookUrl) form.set("webhook_url", webhookUrl);
1513
+
1514
+ const response = await fetch(`${this.baseUrl}/transcribe`, {
1515
+ method: "POST",
1516
+ headers: {
1517
+ Authorization: `Bearer ${this.apiKey}`,
1518
+ },
1519
+ body: form,
1520
+ });
1521
+ const result = await parseApiResponse(response);
1522
+ if (this.polling && result && typeof result === "object" && result.job_status && !TERMINAL_JOB_STATUSES.has(String(result.job_status))) {
1523
+ return this.waitForJobCompletion(result.job_id, {
1524
+ polling: this.polling,
1525
+ showLogs,
1526
+ logger,
1527
+ initialJob: result,
1528
+ });
1529
+ }
1530
+ if (showLogs && typeof logger?.log === "function") {
1531
+ logger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
1532
+ }
1533
+ return result;
1534
+ }
1535
+
1488
1536
  async transcribeMany({
1489
1537
  files,
1490
1538
  webhookUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transcribe-api/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Official JavaScript SDK for Transcribe API.",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -25,4 +25,4 @@
25
25
  ],
26
26
  "author": "Transcribe API",
27
27
  "license": "MIT"
28
- }
28
+ }
package/worker.js CHANGED
@@ -1364,8 +1364,6 @@ export class TranscribeAPI {
1364
1364
  : (normalizedItem.durationEstimateSec || await estimateDurationFromFile(normalizedSingleFile));
1365
1365
  const effectiveLanguage = normalizedItem.hasLanguage ? normalizedItem.language : normalizeLanguageCode(language);
1366
1366
  const isAsync = files.length > 1
1367
- || Boolean(normalizedItem.url)
1368
- || Boolean(webhookUrl)
1369
1367
  || (
1370
1368
  normalizedSingleFile
1371
1369
  && (
@@ -1387,6 +1385,18 @@ export class TranscribeAPI {
1387
1385
  });
1388
1386
  }
1389
1387
 
1388
+ if (normalizedItem.url) {
1389
+ return this.transcribeUrlDirect({
1390
+ url: normalizedItem.url,
1391
+ referenceId: normalizedItem.referenceId,
1392
+ language: effectiveLanguage,
1393
+ exclude,
1394
+ webhookUrl,
1395
+ showLogs: showLogs ?? this.showLogs,
1396
+ logger: logger ?? this.logger,
1397
+ });
1398
+ }
1399
+
1390
1400
  return this.transcribeDirect({
1391
1401
  file: normalizedSingleFile,
1392
1402
  referenceId: normalizedItem.referenceId,
@@ -1485,6 +1495,44 @@ export class TranscribeAPI {
1485
1495
  return result;
1486
1496
  }
1487
1497
 
1498
+ async transcribeUrlDirect({
1499
+ url,
1500
+ referenceId,
1501
+ language,
1502
+ exclude,
1503
+ webhookUrl,
1504
+ showLogs = false,
1505
+ logger = console,
1506
+ } = {}) {
1507
+ const form = new FormData();
1508
+ form.set("url", String(url || "").trim());
1509
+ if (String(referenceId || "").trim()) form.set("reference_id", String(referenceId).trim());
1510
+ if (language) form.set("language", language);
1511
+ if (exclude) form.set("exclude", Array.isArray(exclude) ? exclude.join(",") : exclude);
1512
+ if (webhookUrl) form.set("webhook_url", webhookUrl);
1513
+
1514
+ const response = await fetch(`${this.baseUrl}/transcribe`, {
1515
+ method: "POST",
1516
+ headers: {
1517
+ Authorization: `Bearer ${this.apiKey}`,
1518
+ },
1519
+ body: form,
1520
+ });
1521
+ const result = await parseApiResponse(response);
1522
+ if (this.polling && result && typeof result === "object" && result.job_status && !TERMINAL_JOB_STATUSES.has(String(result.job_status))) {
1523
+ return this.waitForJobCompletion(result.job_id, {
1524
+ polling: this.polling,
1525
+ showLogs,
1526
+ logger,
1527
+ initialJob: result,
1528
+ });
1529
+ }
1530
+ if (showLogs && typeof logger?.log === "function") {
1531
+ logger.log(typeof result === "string" ? result : JSON.stringify(result, null, 2));
1532
+ }
1533
+ return result;
1534
+ }
1535
+
1488
1536
  async transcribeMany({
1489
1537
  files,
1490
1538
  webhookUrl,