vidnavigator 1.0.5 → 2.1.0
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 +387 -92
- package/dist/errors.d.ts +37 -0
- package/dist/errors.js +53 -1
- package/dist/http.d.ts +11 -0
- package/dist/http.js +51 -0
- package/dist/index.d.ts +120 -9
- package/dist/index.js +151 -97
- package/dist/jobs.d.ts +92 -0
- package/dist/jobs.js +132 -0
- package/dist/models/AsyncJob.d.ts +97 -0
- package/dist/models/AsyncJob.js +47 -0
- package/dist/models/TikTok.d.ts +49 -0
- package/dist/models/TikTok.js +10 -0
- package/dist/models/TweetStatement.d.ts +4 -0
- package/dist/models/index.d.ts +1 -0
- package/dist/models/index.js +1 -0
- package/dist/webhooks.d.ts +65 -0
- package/dist/webhooks.js +98 -0
- package/package.json +39 -39
- package/src/errors.ts +59 -1
- package/src/http.ts +77 -0
- package/src/index.ts +1081 -907
- package/src/jobs.ts +215 -0
- package/src/models/AsyncJob.ts +136 -0
- package/src/models/TikTok.ts +521 -454
- package/src/models/TweetStatement.ts +89 -84
- package/src/models/index.ts +2 -1
- package/src/webhooks.ts +158 -0
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@ The official JavaScript/TypeScript SDK for the [VidNavigator Developer API](http
|
|
|
10
10
|
## Why VidNavigator?
|
|
11
11
|
|
|
12
12
|
- **Multi-platform transcription** — YouTube, Instagram Reels & carousel posts, TikTok, X/Twitter, Vimeo, Facebook, Dailymotion, Loom, and more.
|
|
13
|
-
- **
|
|
13
|
+
- **Any video length** — transcription, extraction, and tweet analysis run as background jobs, so there is no duration limit. Get the result with one `await`, or submit many jobs and collect them as they finish.
|
|
14
|
+
- **Async TikTok profile scraping and keyword search** — collect public TikTok videos in the background, then read results via cursor pagination or a signed `download_url`, optionally notified by webhook.
|
|
14
15
|
- **Instagram carousel support** — select a specific video by index, or transcribe every video in a carousel post with one call.
|
|
15
16
|
- **AI-powered analysis** — get summaries, people mentioned, places, key subjects, and direct answers to questions about any video or audio.
|
|
16
17
|
- **Structured data extraction** — define a JSON schema and receive typed, structured fields extracted from any transcript (powered by LLMs).
|
|
@@ -51,7 +52,9 @@ yarn add vidnavigator
|
|
|
51
52
|
pnpm add vidnavigator
|
|
52
53
|
```
|
|
53
54
|
|
|
54
|
-
**Requirements:** Node.js 16+ and a [VidNavigator API key](https://vidnavigator.com).
|
|
55
|
+
**Requirements:** Node.js 16+ (18+ for the examples that use the global `fetch`) and a [VidNavigator API key](https://vidnavigator.com).
|
|
56
|
+
|
|
57
|
+
The SDK is for server-side use: it reads local files for uploads and schema files, and your API key should never be shipped to a browser.
|
|
55
58
|
|
|
56
59
|
## Quick Start
|
|
57
60
|
|
|
@@ -63,6 +66,36 @@ const vn = new VidNavigatorClient({
|
|
|
63
66
|
});
|
|
64
67
|
```
|
|
65
68
|
|
|
69
|
+
CommonJS works too: `const { VidNavigatorClient } = require('vidnavigator');`
|
|
70
|
+
|
|
71
|
+
### Configuration
|
|
72
|
+
|
|
73
|
+
| Option | Default | |
|
|
74
|
+
|---|---|---|
|
|
75
|
+
| `apiKey` | (required) | Your VidNavigator API key |
|
|
76
|
+
| `baseURL` | `https://api.vidnavigator.com/v1` | API base URL |
|
|
77
|
+
| `axiosConfig` | | Passed to the underlying [axios](https://axios-http.com/docs/req_config) instance: HTTP timeout, proxy, extra headers, ... |
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
const vn = new VidNavigatorClient({
|
|
81
|
+
apiKey: process.env.VIDNAVIGATOR_API_KEY!,
|
|
82
|
+
axiosConfig: {
|
|
83
|
+
timeout: 120_000, // per HTTP request, in ms (separate from how long background jobs may run)
|
|
84
|
+
proxy: { protocol: 'http', host: 'proxy.internal', port: 3128 },
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
`axiosConfig.timeout` limits each HTTP request. How long the SDK waits for a background job to finish is set per call with `timeoutMs` (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)).
|
|
90
|
+
|
|
91
|
+
### Upgrading from 1.x
|
|
92
|
+
|
|
93
|
+
Transcription, structured extraction, and tweet analysis now always run as background jobs, so they work on videos of any length. Your existing calls keep working with the same arguments, with one difference:
|
|
94
|
+
|
|
95
|
+
- `getTweetStatement()` no longer returns `statement_query`, which was never part of the documented API.
|
|
96
|
+
|
|
97
|
+
New in 2.0: `vn.transcribe`, `vn.extractVideo`, `vn.tweetStatement`, `vn.tiktokProfile`, and `vn.tiktokSearch`, each with `.submit()` for running many jobs at once (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)), plus webhook signature helpers.
|
|
98
|
+
|
|
66
99
|
---
|
|
67
100
|
|
|
68
101
|
## Examples
|
|
@@ -81,9 +114,11 @@ console.log(video_info.title); // "Rick Astley - Never Gonna Give You Up"
|
|
|
81
114
|
console.log(video_info.channel); // "Rick Astley"
|
|
82
115
|
console.log(video_info.duration); // 212
|
|
83
116
|
|
|
84
|
-
// Timed segments by default
|
|
85
|
-
|
|
86
|
-
|
|
117
|
+
// Timed segments by default (a single string when transcript_text: true)
|
|
118
|
+
if (Array.isArray(transcript)) {
|
|
119
|
+
for (const seg of transcript.slice(0, 3)) {
|
|
120
|
+
console.log(`[${seg.start.toFixed(1)}s] ${seg.text}`);
|
|
121
|
+
}
|
|
87
122
|
}
|
|
88
123
|
// [0.0s] We're no strangers to love
|
|
89
124
|
// [3.4s] You know the rules and so do I
|
|
@@ -96,17 +131,15 @@ Pass `transcript_text: true` to get the full transcript as a single plain-text s
|
|
|
96
131
|
|
|
97
132
|
### 2. Instagram Reel / TikTok / X / Vimeo
|
|
98
133
|
|
|
99
|
-
For most non-Instagram platforms, you can use either `getTranscript` (fast, caption-based) or `
|
|
134
|
+
For most non-Instagram platforms, you can use either `getTranscript` (fast, caption-based) or `transcribe` (speech-to-text, any length). **Note:** Instagram only supports `transcribe`.
|
|
100
135
|
|
|
101
136
|
```ts
|
|
102
137
|
// Instagram Reel (speech-to-text only)
|
|
103
|
-
const { video_info, transcript } = await vn.
|
|
104
|
-
video_url: 'https://www.instagram.com/reel/C86ZvEaqRmo/',
|
|
105
|
-
});
|
|
138
|
+
const { video_info, transcript } = await vn.transcribe('https://www.instagram.com/reel/C86ZvEaqRmo/');
|
|
106
139
|
console.log(video_info.title);
|
|
107
|
-
console.log(transcript
|
|
140
|
+
console.log(transcript);
|
|
108
141
|
|
|
109
|
-
// TikTok (can use getTranscript or
|
|
142
|
+
// TikTok (can use getTranscript or transcribe)
|
|
110
143
|
const tiktok = await vn.getTranscript({
|
|
111
144
|
video_url: 'https://www.tiktok.com/@user/video/1234567890',
|
|
112
145
|
});
|
|
@@ -117,64 +150,255 @@ const tweet = await vn.getTranscript({
|
|
|
117
150
|
});
|
|
118
151
|
```
|
|
119
152
|
|
|
120
|
-
### 3.
|
|
153
|
+
### 3. Background jobs: one call, or many at once
|
|
154
|
+
|
|
155
|
+
Transcription, structured extraction, tweet analysis, and TikTok scraping run as background jobs on VidNavigator. The SDK always uses the async API endpoints, so **video length is never a problem**. You never deal with the request-response limits of long transcriptions.
|
|
156
|
+
|
|
157
|
+
Each of these operations comes in two shapes:
|
|
158
|
+
|
|
159
|
+
| Operation | Wait for the result | Start it and come back later |
|
|
160
|
+
|---|---|---|
|
|
161
|
+
| Transcription | `await vn.transcribe(url)` | `await vn.transcribe.submit(url)` |
|
|
162
|
+
| Structured extraction | `await vn.extractVideo({ video_url, schema })` | `await vn.extractVideo.submit({ ... })` |
|
|
163
|
+
| Tweet claim analysis | `await vn.tweetStatement(tweetId)` | `await vn.tweetStatement.submit(tweetId)` |
|
|
164
|
+
| TikTok profile scrape | `await vn.tiktokProfile(profileUrl)` | `await vn.tiktokProfile.submit(profileUrl)` |
|
|
165
|
+
| TikTok keyword search | `await vn.tiktokSearch(query)` | `await vn.tiktokSearch.submit(query)` |
|
|
121
166
|
|
|
122
|
-
|
|
167
|
+
**Wait for the result.** The one-liner submits the job, checks on it until it finishes, and returns the result:
|
|
123
168
|
|
|
124
169
|
```ts
|
|
125
|
-
const
|
|
170
|
+
const { video_info, transcript, usage } = await vn.transcribe(
|
|
171
|
+
'https://www.tiktok.com/@user/video/1234567890',
|
|
172
|
+
{ include_usage: true }
|
|
173
|
+
);
|
|
174
|
+
console.log(video_info.title, transcript, usage?.total_credits);
|
|
175
|
+
```
|
|
126
176
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
177
|
+
Pass an object instead of a URL for more options, e.g. `vn.transcribe({ video_url, transcript_text: true, all_videos: true })`.
|
|
178
|
+
|
|
179
|
+
**Start many at once.** `.submit()` returns a `Job` right away. Each job has a `task_id`, `status()` (checks once), `result()` (waits, then returns the result), and `wait()` (waits, then returns the final task without throwing on failure):
|
|
180
|
+
|
|
181
|
+
```ts
|
|
182
|
+
const urls = ['https://www.instagram.com/reel/A/', 'https://www.instagram.com/reel/B/', 'https://vimeo.com/123'];
|
|
183
|
+
|
|
184
|
+
const jobs = await Promise.all(urls.map((url) => vn.transcribe.submit(url)));
|
|
185
|
+
console.log(jobs.map((job) => job.task_id)); // store these if you may need to come back later
|
|
186
|
+
|
|
187
|
+
const results = await Promise.allSettled(jobs.map((job) => job.result()));
|
|
188
|
+
results.forEach((r, i) => console.log(urls[i], r.status === 'fulfilled' ? r.value : r.reason.message));
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
const job = await vn.extractVideo.submit({
|
|
193
|
+
video_url: 'https://www.facebook.com/watch/?v=1234567890',
|
|
194
|
+
schema: {
|
|
195
|
+
speakers: { type: 'Array', description: 'Names of everyone who speaks', items: { type: 'String', description: 'A speaker name' } },
|
|
196
|
+
verdict: { type: 'String', description: 'The final conclusion of the video' },
|
|
197
|
+
},
|
|
131
198
|
});
|
|
132
199
|
|
|
133
|
-
|
|
200
|
+
console.log(await job.status()); // 'processing' | 'completed' | 'failed'
|
|
201
|
+
const { data } = await job.result();
|
|
202
|
+
console.log(data); // { speakers: [...], verdict: "..." }, shaped like your schema
|
|
203
|
+
```
|
|
134
204
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
205
|
+
**Come back later.** A job keeps running on VidNavigator even if your process stops waiting, and its result stays available for **1 hour after it finishes**. Keep the `task_id` and reattach with `.resume()`:
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
const job = vn.transcribe.resume(savedTaskId);
|
|
209
|
+
const result = await job.result();
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
**Timeouts.** The one-liners and `result()` wait up to 30 minutes by default. If that runs out, they throw a `TaskTimeoutError` that **carries the `task_id`**. The job is not lost, so resume it:
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import { TaskTimeoutError } from 'vidnavigator';
|
|
216
|
+
|
|
217
|
+
try {
|
|
218
|
+
const result = await vn.transcribe(url, { timeoutMs: 5 * 60 * 1000 });
|
|
219
|
+
} catch (err) {
|
|
220
|
+
if (err instanceof TaskTimeoutError) {
|
|
221
|
+
saveForLater(err.task_id); // later: await vn.transcribe.resume(err.task_id).result()
|
|
222
|
+
} else {
|
|
223
|
+
throw err;
|
|
224
|
+
}
|
|
138
225
|
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**Waiting options.** Pass these to the one-liner or to `result()` / `wait()`:
|
|
229
|
+
|
|
230
|
+
| Option | Default | |
|
|
231
|
+
|---|---|---|
|
|
232
|
+
| `timeoutMs` | 30 minutes | Stop waiting and throw `TaskTimeoutError` (with `task_id`). `0` waits forever |
|
|
233
|
+
| `intervalMs` | `3000` | Time between checks. Checking costs no credits and is not rate-limited |
|
|
234
|
+
| `fastStart` | `true` | Check every second for the first 10 seconds, so short clips return quickly |
|
|
235
|
+
| `signal` | | An `AbortSignal` to stop waiting early (the job keeps running) |
|
|
236
|
+
| `onPoll` | | Called with each task snapshot, e.g. for progress logs |
|
|
237
|
+
| `include_usage` | `false` | Attach a `usage` block to the result (one-liner, `.submit()` and `.resume()` options) |
|
|
238
|
+
|
|
239
|
+
**When a job fails**, `result()` and the one-liners throw an error built from the job's `error` details (`error`, `message`, `http_status`), using the same error class as any other API error, for example `NotFoundError` for a missing video. The error also carries the `task_id`. `wait()` returns the failed task instead, with `task.error` set.
|
|
240
|
+
|
|
241
|
+
**When a job can't start**, submitting throws right away and no job is created:
|
|
242
|
+
- `InsufficientCreditsError` (402): not enough credits (for transcription, less than 60 seconds left). A job can also be accepted and then run out of credits while it runs; `result()` then throws the same `InsufficientCreditsError`, so handle it in both places.
|
|
243
|
+
- `TooManyActiveJobsError` (429): too many of your jobs are already running. Wait for some to finish and retry.
|
|
139
244
|
|
|
140
|
-
|
|
141
|
-
|
|
245
|
+
**Large batches.** Your account can only have a limited number of jobs running at once, so `Promise.all` over hundreds of URLs will hit `TooManyActiveJobsError`. Keep a fixed number in flight and retry when the limit is reached:
|
|
246
|
+
|
|
247
|
+
```ts
|
|
248
|
+
import { TooManyActiveJobsError } from 'vidnavigator';
|
|
249
|
+
|
|
250
|
+
async function transcribeAll(urls: string[], concurrency = 10) {
|
|
251
|
+
const results = new Map<string, unknown>();
|
|
252
|
+
const queue = [...urls];
|
|
253
|
+
|
|
254
|
+
async function worker() {
|
|
255
|
+
for (let url = queue.shift(); url; url = queue.shift()) {
|
|
256
|
+
for (;;) {
|
|
257
|
+
try {
|
|
258
|
+
results.set(url, await vn.transcribe(url));
|
|
259
|
+
break;
|
|
260
|
+
} catch (err) {
|
|
261
|
+
if (err instanceof TooManyActiveJobsError) {
|
|
262
|
+
await new Promise((r) => setTimeout(r, 10_000)); // wait for running jobs to finish
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
results.set(url, err); // record the failure and move on
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
await Promise.all(Array.from({ length: concurrency }, worker));
|
|
273
|
+
return results;
|
|
142
274
|
}
|
|
275
|
+
```
|
|
143
276
|
|
|
144
|
-
|
|
277
|
+
**Progress.** `onPoll` receives every task snapshot while you wait:
|
|
278
|
+
|
|
279
|
+
```ts
|
|
280
|
+
const started = Date.now();
|
|
281
|
+
const result = await vn.transcribe(url, {
|
|
282
|
+
onPoll: (task) => console.log(`${task.task_id}: ${task.task_status} after ${Math.round((Date.now() - started) / 1000)}s`),
|
|
283
|
+
});
|
|
145
284
|
```
|
|
146
285
|
|
|
147
|
-
|
|
286
|
+
**Surviving restarts.** Save each `task_id` as soon as you submit, so a crash or deploy doesn't lose the work. Results stay available for 1 hour after a job finishes:
|
|
148
287
|
|
|
149
288
|
```ts
|
|
150
|
-
|
|
151
|
-
let cursor: string | undefined;
|
|
289
|
+
import { writeFileSync, readFileSync, existsSync } from 'fs';
|
|
152
290
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
cursor,
|
|
157
|
-
});
|
|
291
|
+
// Submit and persist
|
|
292
|
+
const job = await vn.transcribe.submit(url);
|
|
293
|
+
writeFileSync('pending-jobs.json', JSON.stringify([...pending(), job.task_id]));
|
|
158
294
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
295
|
+
// After a restart: pick every job back up
|
|
296
|
+
for (const taskId of pending()) {
|
|
297
|
+
const result = await vn.transcribe.resume(taskId).result();
|
|
298
|
+
// ... store the result, then drop taskId from pending-jobs.json
|
|
299
|
+
}
|
|
162
300
|
|
|
163
|
-
|
|
301
|
+
function pending(): string[] {
|
|
302
|
+
return existsSync('pending-jobs.json') ? JSON.parse(readFileSync('pending-jobs.json', 'utf8')) : [];
|
|
303
|
+
}
|
|
164
304
|
```
|
|
165
305
|
|
|
166
|
-
|
|
306
|
+
> The older methods `transcribeVideo()`, `extractVideoData()`, and `getTweetStatement()` still work with the same arguments. They now run as background jobs too, so they handle videos of any length.
|
|
307
|
+
|
|
308
|
+
### 4. Webhooks
|
|
309
|
+
|
|
310
|
+
You can also have VidNavigator call your server when a job finishes. Pass `webhook_url` to any of the operations above (transcription, extraction, tweet analysis, TikTok profile and search), or set an account-wide default in **Studio → API**. A per-job `webhook_url` overrides the default, and `webhook_url: ''` turns the default off for that one job. The URL must be a public `https` endpoint; private and loopback hosts are rejected with a `BadRequestError`.
|
|
311
|
+
|
|
312
|
+
Webhooks are optional. Waiting with `result()` or the one-liners works exactly the same whether or not a webhook is set, and it remains the source of truth.
|
|
167
313
|
|
|
168
314
|
```ts
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
315
|
+
const job = await vn.transcribe.submit({
|
|
316
|
+
video_url: 'https://www.instagram.com/reel/C86ZvEaqRmo/',
|
|
317
|
+
webhook_url: 'https://example.com/hooks/vidnavigator',
|
|
318
|
+
});
|
|
319
|
+
console.log(job.webhook_url); // where the notification will be sent, or null
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Each delivery is signed with your signing secret (from Studio → API). Verify it with `constructWebhookEvent()`, passing the **raw** request body:
|
|
323
|
+
|
|
324
|
+
```ts
|
|
325
|
+
import express from 'express';
|
|
326
|
+
import { VidNavigatorClient, constructWebhookEvent, WebhookSignatureError, WEBHOOK_HEADERS } from 'vidnavigator';
|
|
327
|
+
|
|
328
|
+
const vn = new VidNavigatorClient({ apiKey: process.env.VIDNAVIGATOR_API_KEY! });
|
|
329
|
+
const app = express();
|
|
330
|
+
|
|
331
|
+
app.post('/hooks/vidnavigator', express.raw({ type: 'application/json' }), async (req, res) => {
|
|
332
|
+
let event;
|
|
333
|
+
try {
|
|
334
|
+
event = constructWebhookEvent(
|
|
335
|
+
req.body, // raw Buffer, not parsed JSON
|
|
336
|
+
req.headers[WEBHOOK_HEADERS.signature], // "t=<unix_ts>,v1=<hex>"
|
|
337
|
+
process.env.VIDNAVIGATOR_WEBHOOK_SECRET!
|
|
338
|
+
);
|
|
339
|
+
} catch (err) {
|
|
340
|
+
if (err instanceof WebhookSignatureError) return res.status(400).send('Invalid signature');
|
|
341
|
+
throw err;
|
|
342
|
+
}
|
|
343
|
+
res.sendStatus(200); // acknowledge quickly; any 2xx counts
|
|
344
|
+
|
|
345
|
+
// Deliveries can repeat: dedupe on req.headers[WEBHOOK_HEADERS.delivery].
|
|
346
|
+
// The simplest handler reattaches to the job and reads the parsed result:
|
|
347
|
+
if (event.type === 'transcribe.completed') {
|
|
348
|
+
const result = await vn.transcribe.resume(event.data.task_id).result();
|
|
349
|
+
console.log(result);
|
|
350
|
+
} else if (event.type === 'tiktok_profile.completed') {
|
|
351
|
+
const task = await vn.tiktokProfile.resume(event.data.task_id).result(); // every video, all pages
|
|
352
|
+
console.log(task.videos.length);
|
|
353
|
+
} else if (event.type.endsWith('.failed')) {
|
|
354
|
+
console.error(event.data.task_id, event.data.error); // { error, message, http_status }
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
- `event.data.result` holds the raw result for transcription, extraction, and tweet events, unless it was over 256 KB (`result_truncated: true`). For TikTok events it is only a summary, `{ stats, download_url_available }`, since a scrape can hold thousands of videos. In every case, `resume(task_id).result()` gets the full parsed result.
|
|
360
|
+
- `verifyWebhookSignature(rawBody, signatureHeader, secret)` returns `true` or `false` instead of throwing.
|
|
361
|
+
- Deliveries older than 5 minutes are rejected by default. Change this with `{ toleranceSeconds }`; `0` turns the check off.
|
|
362
|
+
- Failed deliveries (5xx, 429, network errors) are retried 5 times over about 13 minutes. Other 4xx responses are not retried.
|
|
363
|
+
- To see a job's delivery status, check it: `(await job.refresh()).webhook` → `{ status: 'pending' | 'delivered' | 'failed', attempts, response_status, last_error, delivered_at }`.
|
|
364
|
+
|
|
365
|
+
### 5. TikTok profile scraping (async)
|
|
366
|
+
|
|
367
|
+
`vn.tiktokProfile()` scrapes a public profile in the background and returns the finished task with **every** matching video (the SDK fetches all result pages for you):
|
|
172
368
|
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
|
|
369
|
+
```ts
|
|
370
|
+
const task = await vn.tiktokProfile({
|
|
371
|
+
profile_url: 'https://www.tiktok.com/@tiktok',
|
|
372
|
+
max_posts: 250,
|
|
373
|
+
after_datetime: '2024-01-01',
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
console.log(`Matched ${task.videos.length} videos`, task.stats);
|
|
377
|
+
const videos = task.videos; // TikTokVideo[], published_at parsed as Date
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
Pass just the URL for the defaults: `await vn.tiktokProfile('https://www.tiktok.com/@tiktok')`. As with every operation, `vn.tiktokProfile.submit(...)` returns a `Job` instead, and `webhook_url` is accepted.
|
|
381
|
+
|
|
382
|
+
If you'd rather read the results one page at a time, or grab them as a single JSON file, submit the job and use the page-level method with its `task_id`:
|
|
383
|
+
|
|
384
|
+
```ts
|
|
385
|
+
const job = await vn.tiktokProfile.submit('https://www.tiktok.com/@tiktok');
|
|
386
|
+
await job.wait();
|
|
387
|
+
|
|
388
|
+
// Page by page
|
|
389
|
+
let cursor: string | undefined;
|
|
390
|
+
do {
|
|
391
|
+
const page = await vn.getTikTokProfileScrape(job.task_id, { limit: 100, cursor });
|
|
392
|
+
handle(page.videos);
|
|
393
|
+
cursor = page.pagination?.next_cursor ?? undefined;
|
|
394
|
+
} while (cursor);
|
|
176
395
|
|
|
177
|
-
|
|
396
|
+
// Or the whole result as one JSON file (short-lived signed URL, any HTTP client works)
|
|
397
|
+
const { download_url } = await vn.getTikTokProfileScrape(job.task_id, { limit: 1 });
|
|
398
|
+
if (download_url) {
|
|
399
|
+
const fullProfile = await (await fetch(download_url)).json();
|
|
400
|
+
console.log(fullProfile.videos.length);
|
|
401
|
+
}
|
|
178
402
|
```
|
|
179
403
|
|
|
180
404
|
After you have the final video list, loop through each TikTok video URL and use the normal transcript or extraction APIs:
|
|
@@ -203,7 +427,7 @@ for (const video of videos) {
|
|
|
203
427
|
video_url: video.url,
|
|
204
428
|
schema: {
|
|
205
429
|
hook: { type: 'String', description: 'The opening hook or premise' },
|
|
206
|
-
products: { type: 'Array', description: 'Products or brands mentioned' },
|
|
430
|
+
products: { type: 'Array', description: 'Products or brands mentioned', items: { type: 'String', description: 'A product or brand' } },
|
|
207
431
|
sentiment: {
|
|
208
432
|
type: 'Enum',
|
|
209
433
|
description: 'Overall sentiment',
|
|
@@ -220,47 +444,41 @@ for (const video of videos) {
|
|
|
220
444
|
|
|
221
445
|
For large profiles, process videos sequentially or with a small concurrency limit so you do not exhaust credits or hit rate limits.
|
|
222
446
|
|
|
223
|
-
###
|
|
447
|
+
### 6. TikTok keyword search (async)
|
|
224
448
|
|
|
225
|
-
|
|
449
|
+
`vn.tiktokSearch()` works the same way and returns the finished task with every result:
|
|
226
450
|
|
|
227
451
|
```ts
|
|
228
|
-
const
|
|
452
|
+
const task = await vn.tiktokSearch({
|
|
229
453
|
query: 'ai tools',
|
|
230
454
|
max_results: 100,
|
|
231
|
-
|
|
232
|
-
|
|
455
|
+
sort_by: 'most_liked', // 'relevance' | 'most_liked' | 'newest'
|
|
456
|
+
published_within: 'this_month', // 'all' | 'past_24_hours' | 'this_week' | 'this_month' | 'last_3_months' | 'last_6_months'
|
|
457
|
+
min_views: 10000,
|
|
233
458
|
});
|
|
234
459
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
while (task.task_status === 'processing') {
|
|
238
|
-
await sleep(5000);
|
|
239
|
-
task = await vn.getTikTokSearch(submitted.task_id, { limit: 50 });
|
|
240
|
-
}
|
|
241
|
-
|
|
460
|
+
console.log(task.stats?.sort_by, task.stats?.published_within); // what the search actually ran with
|
|
242
461
|
for (const result of task.results) {
|
|
243
462
|
console.log(result.published_at?.toISOString(), result.url, result.stats?.views);
|
|
244
463
|
}
|
|
245
464
|
```
|
|
246
465
|
|
|
247
|
-
|
|
466
|
+
- `sort_by` and `published_within` are applied by TikTok itself. If you leave out `sort_by`, results come back newest first. If you leave out `published_within` and set an `after_datetime` more than 24 hours ago, the smallest window that covers it is picked for you.
|
|
467
|
+
- `parallel_search_slices` (`2` to `4`) runs several search chains in parallel to collect more results than TikTok's single-chain limit (about 115 to 140 items). Billing grows with the number of slices, so keep it at `1` unless you need the extra results, and especially when `published_within` is set, since every slice searches the same window.
|
|
248
468
|
|
|
249
|
-
###
|
|
469
|
+
### 7. Instagram carousel posts (multiple videos)
|
|
250
470
|
|
|
251
471
|
Instagram carousel posts can contain multiple videos. You can select a specific video by index, or transcribe them all at once:
|
|
252
472
|
|
|
253
473
|
```ts
|
|
254
474
|
// Transcribe the 2nd video in a carousel
|
|
255
|
-
const single = await vn.
|
|
256
|
-
video_url: 'https://www.instagram.com/p/ABC123/?img_index=2',
|
|
257
|
-
});
|
|
475
|
+
const single = await vn.transcribe('https://www.instagram.com/p/ABC123/?img_index=2');
|
|
258
476
|
console.log(single.video_info.title);
|
|
259
477
|
console.log(single.video_info.carousel_info);
|
|
260
478
|
// { total_items: 5, video_count: 3, image_count: 2, selected_index: 2 }
|
|
261
479
|
|
|
262
480
|
// Transcribe ALL videos in a carousel at once
|
|
263
|
-
const all = await vn.
|
|
481
|
+
const all = await vn.transcribe({
|
|
264
482
|
video_url: 'https://www.instagram.com/p/ABC123/',
|
|
265
483
|
all_videos: true,
|
|
266
484
|
});
|
|
@@ -270,8 +488,8 @@ if ('carousel_info' in all) {
|
|
|
270
488
|
|
|
271
489
|
for (const video of all.videos) {
|
|
272
490
|
if (video.status === 'success') {
|
|
273
|
-
console.log(`Video #${video.index}: ${video.video_info
|
|
274
|
-
console.log(
|
|
491
|
+
console.log(`Video #${video.index}: ${video.video_info?.title}`);
|
|
492
|
+
console.log(' Transcript:', video.transcript);
|
|
275
493
|
} else {
|
|
276
494
|
console.log(`Video #${video.index}: failed — ${video.message}`);
|
|
277
495
|
}
|
|
@@ -279,7 +497,7 @@ if ('carousel_info' in all) {
|
|
|
279
497
|
}
|
|
280
498
|
```
|
|
281
499
|
|
|
282
|
-
###
|
|
500
|
+
### 8. Upload and analyze a local file
|
|
283
501
|
|
|
284
502
|
Upload audio or video files for transcription, analysis, and search. Supported formats: mp4, webm, mov, avi, wmv, flv, mkv, m4a, mp3, mpeg, mpga, wav.
|
|
285
503
|
|
|
@@ -292,11 +510,11 @@ const upload = await vn.uploadFile({
|
|
|
292
510
|
|
|
293
511
|
console.log(upload.file_id); // "64a1b2c3d4e5f6789..."
|
|
294
512
|
console.log(upload.file_name); // "meeting-recording.mp4"
|
|
295
|
-
console.log(upload.file_info
|
|
513
|
+
console.log(upload.file_info?.namespace_ids); // ["ns_meetings"]
|
|
296
514
|
|
|
297
515
|
// Analyze with a question
|
|
298
516
|
const { transcript_analysis } = await vn.analyzeFile({
|
|
299
|
-
file_id: upload.
|
|
517
|
+
file_id: upload.file_id,
|
|
300
518
|
query: 'What action items were discussed?',
|
|
301
519
|
});
|
|
302
520
|
|
|
@@ -313,7 +531,42 @@ console.log(transcript_analysis.query_answer?.answer);
|
|
|
313
531
|
// "Three action items were discussed: 1) Finalize the hiring..."
|
|
314
532
|
```
|
|
315
533
|
|
|
316
|
-
|
|
534
|
+
Without `wait_for_completion`, the upload returns right away (`status: 'accepted'`) while the file is processed. Check on it with `getFile()`, then work with it:
|
|
535
|
+
|
|
536
|
+
```ts
|
|
537
|
+
const { file_id } = await vn.uploadFile({ filePath: './interview.mp3' });
|
|
538
|
+
|
|
539
|
+
let { file_info } = await vn.getFile(file_id);
|
|
540
|
+
while (file_info.status === 'processing') {
|
|
541
|
+
await new Promise((r) => setTimeout(r, 5000));
|
|
542
|
+
({ file_info } = await vn.getFile(file_id));
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
if (file_info.status === 'failed') {
|
|
546
|
+
await vn.retryFileProcessing(file_id); // or: await vn.cancelFileUpload(file_id) while it is still processing
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const { transcript } = await vn.getFile(file_id, { transcript_text: true }); // full text
|
|
550
|
+
const { file_url } = await vn.getFileUrl(file_id); // signed download URL
|
|
551
|
+
const { files, has_more } = await vn.getFiles({ status: 'completed', limit: 20, offset: 0 });
|
|
552
|
+
await vn.deleteFile(file_id);
|
|
553
|
+
```
|
|
554
|
+
|
|
555
|
+
### Analyze an online video
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
const { video_info, transcript_analysis } = await vn.analyzeVideo({
|
|
559
|
+
video_url: 'https://www.youtube.com/watch?v=4czjS9h4Fpg',
|
|
560
|
+
query: 'Where did the rover land?',
|
|
561
|
+
include_usage: true,
|
|
562
|
+
});
|
|
563
|
+
|
|
564
|
+
console.log(transcript_analysis.summary);
|
|
565
|
+
console.log(transcript_analysis.query_answer?.answer); // direct answer to your question
|
|
566
|
+
console.log(transcript_analysis.query_answer?.relevant_segments); // supporting transcript excerpts
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
### 9. Extract structured data
|
|
317
570
|
|
|
318
571
|
Define a schema and get back clean, structured data extracted from any video or file transcript. Powered by LLMs with per-call usage tracking (see [Per-call usage](#per-call-usage)).
|
|
319
572
|
|
|
@@ -325,7 +578,7 @@ const { data, usage } = await vn.extractVideoData({
|
|
|
325
578
|
language: { type: 'String', description: 'Primary spoken language (ISO 639-1)' },
|
|
326
579
|
tone: { type: 'Enum', description: 'Overall tone',
|
|
327
580
|
enum: ['positive', 'negative', 'neutral', 'mixed'] },
|
|
328
|
-
key_quotes: { type: 'Array', description: 'Top 3 memorable quotes' },
|
|
581
|
+
key_quotes: { type: 'Array', description: 'Top 3 memorable quotes', items: { type: 'String', description: 'A quote' } },
|
|
329
582
|
},
|
|
330
583
|
what_to_extract: 'Determine the topic, language, tone, and notable quotes.',
|
|
331
584
|
include_usage: true,
|
|
@@ -350,7 +603,7 @@ Also works on uploaded files:
|
|
|
350
603
|
const { data } = await vn.extractFileData({
|
|
351
604
|
file_id: 'your-file-id',
|
|
352
605
|
schema: {
|
|
353
|
-
action_items: { type: 'Array', description: 'List of action items from the meeting' },
|
|
606
|
+
action_items: { type: 'Array', description: 'List of action items from the meeting', items: { type: 'String', description: 'An action item' } },
|
|
354
607
|
next_meeting: { type: 'String', description: 'When is the next meeting scheduled?' },
|
|
355
608
|
sentiment: { type: 'Enum', description: 'Overall meeting mood',
|
|
356
609
|
enum: ['productive', 'tense', 'casual', 'urgent'] },
|
|
@@ -370,7 +623,11 @@ const { data } = await vn.extractVideoData({
|
|
|
370
623
|
|
|
371
624
|
**Supported schema types:** `String`, `Number`, `Boolean`, `Integer`, `Object`, `Array`, `Enum`
|
|
372
625
|
|
|
373
|
-
|
|
626
|
+
**Schema rules:** every field needs `type` and `description`. `Array` fields also need `items` (the schema of one element). `Object` fields list their sub-fields in `properties` (up to 10), and `Enum` fields list the allowed values in `enum`. At most 10 top-level fields and 3 levels of nesting. An invalid schema is rejected with a `BadRequestError` before anything runs.
|
|
627
|
+
|
|
628
|
+
> `extractVideoData()` runs as a background job, so videos of any length work. For many extractions at once, use `vn.extractVideo.submit()` (see [Background jobs](#3-background-jobs-one-call-or-many-at-once)). The result has `data` (the extracted fields), `video_info` (the video's metadata), and `usage` when requested.
|
|
629
|
+
|
|
630
|
+
### 10. Semantic search
|
|
374
631
|
|
|
375
632
|
Search YouTube videos and uploaded files with AI-powered ranking/reranking.
|
|
376
633
|
|
|
@@ -409,7 +666,7 @@ for (const r of fileResults.results) {
|
|
|
409
666
|
|
|
410
667
|
> **Deprecated:** `searchVideos()` still works but is deprecated — it now forwards to `searchYouTube()` (the `/search/video` endpoint moved to `/youtube/search`) and emits a deprecation warning. Use `searchYouTube()` instead.
|
|
411
668
|
|
|
412
|
-
###
|
|
669
|
+
### 11. Organize files with namespaces
|
|
413
670
|
|
|
414
671
|
```ts
|
|
415
672
|
// Create a namespace
|
|
@@ -417,33 +674,33 @@ const ns = await vn.createNamespace({ name: 'Client Calls' });
|
|
|
417
674
|
|
|
418
675
|
// Assign a file to namespaces
|
|
419
676
|
const updated = await vn.updateFileNamespaces(fileId, {
|
|
420
|
-
namespace_ids: [ns.id],
|
|
677
|
+
namespace_ids: [ns.id!],
|
|
421
678
|
});
|
|
422
679
|
console.log(updated.namespaces);
|
|
423
680
|
// [{ id: "...", name: "Client Calls" }]
|
|
424
681
|
|
|
425
682
|
// List files filtered by namespace
|
|
426
|
-
const files = await vn.getFiles({ namespace_id: ns.id });
|
|
683
|
+
const files = await vn.getFiles({ namespace_id: ns.id! });
|
|
427
684
|
|
|
428
685
|
// List all namespaces
|
|
429
686
|
const all = await vn.getNamespaces();
|
|
430
687
|
```
|
|
431
688
|
|
|
432
|
-
###
|
|
689
|
+
### 12. Usage and credits
|
|
433
690
|
|
|
434
691
|
```ts
|
|
435
692
|
const usage = await vn.getUsage();
|
|
436
693
|
|
|
437
694
|
console.log(`Credits remaining: ${usage.credits.monthly_remaining}`);
|
|
438
|
-
console.log(`
|
|
439
|
-
console.log(`
|
|
440
|
-
console.log(`Storage: ${usage.storage.
|
|
695
|
+
console.log(`Transcription hours used: ${usage.usage.transcriptionHour?.used}`);
|
|
696
|
+
console.log(`Standard requests used: ${usage.usage.standardRequest?.used}`);
|
|
697
|
+
console.log(`Storage: ${usage.storage.usedFormatted} / ${usage.storage.limitFormatted}`);
|
|
441
698
|
console.log(`Channels indexed: ${usage.channelsIndexed.used} / ${usage.channelsIndexed.limit}`);
|
|
442
699
|
```
|
|
443
700
|
|
|
444
701
|
### Per-call usage
|
|
445
702
|
|
|
446
|
-
Pass `include_usage: true` to most endpoints (`getTranscript`, `transcribeVideo`, `analyzeVideo`, `analyzeFile`, `extractVideoData`, `extractFileData`, `searchYouTube`, `searchFiles`) to receive a `usage` block describing exactly what the request cost. For the
|
|
703
|
+
Pass `include_usage: true` to most endpoints (`getTranscript`, `transcribeVideo`, `analyzeVideo`, `analyzeFile`, `extractVideoData`, `extractFileData`, `searchYouTube`, `searchFiles`) to receive a `usage` block describing exactly what the request cost. For background jobs, pass it in the options: `vn.transcribe(url, { include_usage: true })`, `vn.transcribe.submit(url, { include_usage: true })`, or `vn.transcribe.resume(taskId, { include_usage: true })`. The result's `usage` is filled in once the job completes. A failed job has all its charges reverted, so it has no usage.
|
|
447
704
|
|
|
448
705
|
The `usage` field is a `UsageBlock`:
|
|
449
706
|
|
|
@@ -483,20 +740,48 @@ All methods return a `Promise`. Responses are automatically parsed into typed mo
|
|
|
483
740
|
|--------|-------------|
|
|
484
741
|
| `getTranscript(payload)` | Get a transcript for any supported video; auto-detects the platform from the URL (note: Instagram uses `transcribeVideo`) |
|
|
485
742
|
| `getYouTubeTranscript(payload)` | **Deprecated** — forwards to `getTranscript()` |
|
|
486
|
-
| `
|
|
743
|
+
| `transcribe(urlOrInput, options?)` | Speech-to-text of any length. Input: `video_url`, `transcript_text`, `all_videos` (Instagram carousels), `webhook_url`. See [Background jobs](#background-jobs) |
|
|
744
|
+
| `transcribeVideo(payload, options?)` | Same as `transcribe()`, with the original payload shape (`include_usage` in the payload) |
|
|
487
745
|
|
|
488
746
|
**Common options:** `video_url`, `language`, `metadata_only`, `fallback_to_metadata`, `transcript_text`, `include_usage`
|
|
489
747
|
|
|
748
|
+
### Background jobs
|
|
749
|
+
|
|
750
|
+
| Member | Description |
|
|
751
|
+
|--------|-------------|
|
|
752
|
+
| `vn.transcribe`, `vn.extractVideo`, `vn.tweetStatement`, `vn.tiktokProfile`, `vn.tiktokSearch` | Call directly to submit and wait for the result. Options: `include_usage`, `timeoutMs`, `intervalMs`, `fastStart`, `signal`, `onPoll` |
|
|
753
|
+
| `.submit(input, { include_usage? })` | Start the job and return a `Job` immediately |
|
|
754
|
+
| `.resume(task_id, { include_usage? })` | Get a `Job` for a job you already started (no request is made) |
|
|
755
|
+
| `job.task_id`, `job.job_type`, `job.check_status_url`, `job.webhook_url` | Job details from the submit response |
|
|
756
|
+
| `job.status()` | Check once; returns `'processing'`, `'completed'` or `'failed'` |
|
|
757
|
+
| `job.refresh()` | Check once; returns the full task (`error`, `webhook`, timestamps, ...) |
|
|
758
|
+
| `job.result(options?)` | Wait until finished and return the result. Throws on failure or timeout; every error carries `task_id` |
|
|
759
|
+
| `job.wait(options?)` | Wait until finished and return the final task, without throwing on failure |
|
|
760
|
+
|
|
761
|
+
Results: `transcribe` → same shape as `transcribeVideo()`; `extractVideo` → `{ data, video_info, usage? }`; `tweetStatement` → `TweetStatement`; `tiktokProfile` / `tiktokSearch` → the completed task with every page of `videos` / `results`.
|
|
762
|
+
|
|
763
|
+
### Webhooks
|
|
764
|
+
|
|
765
|
+
| Function | Description |
|
|
766
|
+
|----------|-------------|
|
|
767
|
+
| `constructWebhookEvent(rawBody, signatureHeader, secret, options?)` | Verify a delivery and return the parsed `WebhookEvent`. Throws `WebhookSignatureError` if the signature is invalid |
|
|
768
|
+
| `verifyWebhookSignature(rawBody, signatureHeader, secret, options?)` | Same check, returning `true` / `false` |
|
|
769
|
+
| `WEBHOOK_HEADERS` | Header names: `signature`, `delivery`, `event`, `taskId` |
|
|
770
|
+
|
|
771
|
+
`options`: `toleranceSeconds` (default `300`, `0` turns the check off). Event types: `transcribe.*`, `extract_video.*`, `tweet_statement.*`, `tiktok_profile.*`, `tiktok_search.*`, each with `.completed` or `.failed`.
|
|
772
|
+
|
|
490
773
|
### TikTok
|
|
491
774
|
|
|
492
775
|
| Method | Description |
|
|
493
776
|
|--------|-------------|
|
|
494
|
-
| `
|
|
777
|
+
| `tiktokProfile(urlOrInput, options?)` | Scrape a public profile and return the completed task with every video. See [Background jobs](#background-jobs) |
|
|
778
|
+
| `tiktokSearch(queryOrInput, options?)` | Keyword search returning the completed task with every result |
|
|
779
|
+
| `submitTikTokProfileScrape(payload)` | Lower-level: start a public TikTok profile scrape. Returns a `task_id` immediately. Options: `max_posts`, `after_datetime`, `before_datetime`, `min_likes`, `max_likes`, `webhook_url` |
|
|
495
780
|
| `getTikTokProfileScrape(task_id, query?)` | Poll task status and retrieve a page of videos. Options: `cursor`, `limit`, `include_usage` |
|
|
496
|
-
| `submitTikTokSearch(payload)` | Start an async TikTok keyword search. Returns a `task_id` immediately |
|
|
781
|
+
| `submitTikTokSearch(payload)` | Start an async TikTok keyword search. Returns a `task_id` immediately. Options: `max_results`, `parallel_search_slices`, `sort_by`, `published_within`, `after_datetime`, `before_datetime`, `min_likes`, `max_likes`, `min_views`, `max_views`, `webhook_url` |
|
|
497
782
|
| `getTikTokSearch(task_id, query?)` | Poll search status and retrieve a page of results. Options: `cursor`, `limit`, `include_usage` |
|
|
498
783
|
|
|
499
|
-
Completed profile tasks include `videos`; completed search tasks include `results`. Both include `pagination`, optional `stats`, and an optional short-lived `download_url` for retrieving the whole result as JSON. Datetime filters use `after_datetime` and `before_datetime`, each accepting either `YYYY-MM-DD` or full ISO datetime strings with timezone; TikTok `published_at` values are parsed into JavaScript `Date` objects, and numeric counters such as `views` and `likes` are normalized to integers.
|
|
784
|
+
Completed profile tasks include `videos`; completed search tasks include `results`. Both include `pagination`, optional `stats`, and an optional short-lived `download_url` for retrieving the whole result as JSON. Failed tasks include `error` (`{ error, message, http_status }`); the older `error_message` string still works but is deprecated. Datetime filters use `after_datetime` and `before_datetime`, each accepting either `YYYY-MM-DD` or full ISO datetime strings with timezone; TikTok `published_at` values are parsed into JavaScript `Date` objects, and numeric counters such as `views` and `likes` are normalized to integers.
|
|
500
785
|
|
|
501
786
|
### Files
|
|
502
787
|
|
|
@@ -528,7 +813,8 @@ Completed profile tasks include `videos`; completed search tasks include `result
|
|
|
528
813
|
|--------|-------------|
|
|
529
814
|
| `analyzeVideo(payload)` | Analyze an online video with an optional natural language query |
|
|
530
815
|
| `analyzeFile(payload)` | Analyze an uploaded file with an optional natural language query |
|
|
531
|
-
| `
|
|
816
|
+
| `tweetStatement(tweetIdOrInput, options?)` | Structured claim analysis of an X/Twitter tweet, including attached media of any length. Input: `tweet_id`, `webhook_url`. Returns a `TweetStatement` |
|
|
817
|
+
| `getTweetStatement(payload, options?)` | Same as `tweetStatement()`, with the original payload shape |
|
|
532
818
|
|
|
533
819
|
Returns `transcript_analysis` containing:
|
|
534
820
|
- `summary` — content overview
|
|
@@ -541,7 +827,8 @@ Returns `transcript_analysis` containing:
|
|
|
541
827
|
|
|
542
828
|
| Method | Description |
|
|
543
829
|
|--------|-------------|
|
|
544
|
-
| `
|
|
830
|
+
| `extractVideo(input, options?)` | Structured data from an online video of any length. Input: `video_url`, `schema` or `schemaFilePath`, `what_to_extract`, `transcribe`, `webhook_url`. Returns `{ data, video_info, usage? }` |
|
|
831
|
+
| `extractVideoData(payload, options?)` | Same as `extractVideo()`, with the original payload shape (`include_usage` in the payload) |
|
|
545
832
|
| `extractFileData(payload)` | Extract structured data from an uploaded file transcript |
|
|
546
833
|
|
|
547
834
|
**Options:** `schema` (required for JSON requests), `schemaFilePath` (JSON/YAML schema file via multipart form-data), `what_to_extract` (optional guidance), `include_usage` (attach a per-call `UsageBlock`; read LLM tokens via `usage.analysis_tokens`)
|
|
@@ -596,13 +883,19 @@ try {
|
|
|
596
883
|
| `BadRequestError` | 400 | Invalid parameters |
|
|
597
884
|
| `AuthenticationError` | 401 | Invalid or missing API key |
|
|
598
885
|
| `PaymentRequiredError` | 402 | Credit limit reached |
|
|
886
|
+
| `InsufficientCreditsError` | 402 | A job could not start: not enough credits (`limit_exceeded`). Extends `PaymentRequiredError` |
|
|
599
887
|
| `AccessDeniedError` | 403 | Insufficient permissions |
|
|
600
|
-
| `NotFoundError` | 404 | Resource does not exist |
|
|
888
|
+
| `NotFoundError` | 404 | Resource does not exist, or a job's `task_id` is unknown or expired (`task_not_found`) |
|
|
601
889
|
| `StorageQuotaExceededError` | 413 | Storage quota exceeded |
|
|
602
890
|
| `RateLimitExceededError` | 429 | Too many requests |
|
|
891
|
+
| `TooManyActiveJobsError` | 429 | A job could not start: too many of your jobs are already running (`too_many_active_jobs`). Extends `RateLimitExceededError` |
|
|
603
892
|
| `GeoRestrictedError` | 451 | Content unavailable in your region |
|
|
604
893
|
| `ServerError` | 5xx | Unexpected server error |
|
|
605
894
|
| `SystemOverloadError` | 503 | Temporary overload (has `retry_after_seconds`) |
|
|
895
|
+
| `TaskTimeoutError` | - | Waiting for a job took longer than `timeoutMs`. Has `task_id`; the job keeps running, so `resume(task_id)` it |
|
|
896
|
+
| `WebhookSignatureError` | - | `constructWebhookEvent()` got a missing, invalid, or expired signature |
|
|
897
|
+
|
|
898
|
+
A failed job throws the class matching its `error.http_status`, with `error_code` and `error_message` taken from its `error` details. Every error raised while waiting for a job has a `task_id` property.
|
|
606
899
|
|
|
607
900
|
## TypeScript Models
|
|
608
901
|
|
|
@@ -624,11 +917,13 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
|
|
|
624
917
|
| `ExtractionTokenUsage` | Legacy flat token usage (`prompt_tokens`, `completion_tokens`, `total_tokens`) — extraction now returns a `UsageBlock`; prefer `usage.analysis_tokens` |
|
|
625
918
|
| `CarouselInfo` | Carousel summary: total items, video/image count, transcribed count, total duration |
|
|
626
919
|
| `CarouselVideoResult` | Per-video result in a carousel: index, status, video info, transcript |
|
|
627
|
-
| `
|
|
628
|
-
| `
|
|
920
|
+
| `Job` | Handle returned by `.submit()` / `.resume()`: `task_id`, `status()`, `refresh()`, `result()`, `wait()` |
|
|
921
|
+
| `AsyncJob<T>` | Task snapshot of a transcription, extraction, or tweet job (from `job.refresh()` / `job.wait()`): `task_status`, `result`, `error`, `webhook`, `request`, timestamps |
|
|
922
|
+
| `TikTokProfileScrapeSubmission` | Async scrape submission: `task_id`, status, profile URL, expiry, `webhook_url` |
|
|
923
|
+
| `TikTokProfileTask` | TikTok profile scrape task with status, profile metadata, videos, pagination, `download_url`, `error`, `webhook` |
|
|
629
924
|
| `TikTokVideo` | Public TikTok video metadata returned by profile scraping, including `published_at` as a `Date` and integer counters |
|
|
630
|
-
| `TikTokSearchSubmission` | Async TikTok keyword search submission: `task_id`, query, slice count, expiry |
|
|
631
|
-
| `TikTokSearchTask` | TikTok keyword search task with status, results, pagination, `download_url` |
|
|
925
|
+
| `TikTokSearchSubmission` | Async TikTok keyword search submission: `task_id`, query, slice count, expiry, `webhook_url` |
|
|
926
|
+
| `TikTokSearchTask` | TikTok keyword search task with status, results, pagination, `download_url`, `error`, `webhook`; `stats` shows the `sort_by` / `published_within` the search ran with |
|
|
632
927
|
| `TikTokSearchResult` | Normalized TikTok keyword result, including `published_at` as a `Date` and integer counters |
|
|
633
928
|
| `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text |
|
|
634
929
|
|