vidnavigator 1.0.4 → 1.0.5

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
@@ -67,10 +67,12 @@ const vn = new VidNavigatorClient({
67
67
 
68
68
  ## Examples
69
69
 
70
- ### 1. YouTube transcript
70
+ ### 1. Get a transcript (any platform)
71
+
72
+ There is a single `getTranscript` method that auto-detects the platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, and more) from the URL.
71
73
 
72
74
  ```ts
73
- const { video_info, transcript } = await vn.getYouTubeTranscript({
75
+ const { video_info, transcript } = await vn.getTranscript({
74
76
  video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
75
77
  language: 'en',
76
78
  });
@@ -90,9 +92,11 @@ for (const seg of transcript.slice(0, 3)) {
90
92
 
91
93
  Pass `transcript_text: true` to get the full transcript as a single plain-text string instead of segments.
92
94
 
95
+ > **Deprecated:** `getYouTubeTranscript()` still works but is deprecated — it now forwards to `getTranscript()` and emits a deprecation warning. Use `getTranscript()` instead.
96
+
93
97
  ### 2. Instagram Reel / TikTok / X / Vimeo
94
98
 
95
- For most non-YouTube platforms, you can use either `getTranscript` (fast, caption-based) or `transcribeVideo` (speech-to-text). **Note:** Instagram only supports `transcribeVideo`.
99
+ For most non-Instagram platforms, you can use either `getTranscript` (fast, caption-based) or `transcribeVideo` (speech-to-text). **Note:** Instagram only supports `transcribeVideo`.
96
100
 
97
101
  ```ts
98
102
  // Instagram Reel (speech-to-text only)
@@ -311,7 +315,7 @@ console.log(transcript_analysis.query_answer?.answer);
311
315
 
312
316
  ### 7. Extract structured data
313
317
 
314
- Define a schema and get back clean, structured data extracted from any video or file transcript. Powered by LLMs with token usage tracking.
318
+ 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)).
315
319
 
316
320
  ```ts
317
321
  const { data, usage } = await vn.extractVideoData({
@@ -335,7 +339,9 @@ console.log(data);
335
339
  // key_quotes: ["Never gonna give you up", "Never gonna let you down", ...]
336
340
  // }
337
341
 
338
- console.log(usage?.total_tokens); // 847
342
+ // LLM token counts live under the analysis_request charge:
343
+ console.log(usage?.analysis_tokens?.total_tokens); // 847
344
+ console.log(usage?.total_credits); // 2
339
345
  ```
340
346
 
341
347
  Also works on uploaded files:
@@ -370,8 +376,11 @@ Search YouTube videos and uploaded files with AI-powered ranking/reranking.
370
376
 
371
377
  ```ts
372
378
  // Search YouTube videos
373
- const videoResults = await vn.searchVideos({
379
+ const videoResults = await vn.searchYouTube({
374
380
  query: 'how to deploy a Node.js app',
381
+ focus: 'relevance', // 'relevance' (default) | 'popularity' | 'brevity'
382
+ max_results: 5, // caps how many candidates are analysed (and the cost)
383
+ include_usage: true, // attach a per-call usage block
375
384
  });
376
385
 
377
386
  console.log(`Found ${videoResults.total_found} results`);
@@ -380,6 +389,11 @@ for (const r of videoResults.results) {
380
389
  console.log(` ${r.transcript_summary}`);
381
390
  }
382
391
 
392
+ // If credits run out mid-search, a partial result is returned instead of throwing:
393
+ if (videoResults.status === 'partial') {
394
+ console.log('Partial results:', videoResults.error_code); // "insufficient_credits_video_search"
395
+ }
396
+
383
397
  // Search uploaded files — optionally scoped to a namespace
384
398
  const fileResults = await vn.searchFiles({
385
399
  query: 'quarterly revenue discussion',
@@ -393,6 +407,8 @@ for (const r of fileResults.results) {
393
407
  }
394
408
  ```
395
409
 
410
+ > **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
+
396
412
  ### 9. Organize files with namespaces
397
413
 
398
414
  ```ts
@@ -425,6 +441,36 @@ console.log(`Storage: ${usage.storage.used_formatted} / ${usage.storage.limit_fo
425
441
  console.log(`Channels indexed: ${usage.channelsIndexed.used} / ${usage.channelsIndexed.limit}`);
426
442
  ```
427
443
 
444
+ ### Per-call usage
445
+
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 TikTok pollers (`getTikTokProfileScrape`, `getTikTokSearch`), pass `include_usage: true` in the options object — usage is populated once `task_status === 'completed'`.
447
+
448
+ The `usage` field is a `UsageBlock`:
449
+
450
+ ```ts
451
+ const { usage } = await vn.getTranscript({
452
+ video_url: 'https://youtube.com/watch?v=dQw4w9WgXcQ',
453
+ include_usage: true,
454
+ });
455
+
456
+ if (usage) {
457
+ console.log(usage.total_credits); // net credits deducted by this request
458
+ console.log(usage.credits_remaining_after); // balance after the request (when provided)
459
+
460
+ // Every meter that fired, consolidated to one entry per service_type:
461
+ for (const charge of usage.charges) {
462
+ console.log(charge.service_type, charge.quantity, charge.credits, charge.waived);
463
+ }
464
+
465
+ // Convenience accessors:
466
+ const residential = usage.charge_for('residential_request'); // matching charge entry or undefined
467
+ const tokens = usage.analysis_tokens; // { prompt_tokens, completion_tokens, total_tokens }
468
+ console.log(tokens?.total_tokens);
469
+ }
470
+ ```
471
+
472
+ `service_type` is one of: `standard_request`, `residential_request`, `transcription_hour`, `analysis_request`, `search_request`, `scene_analysis_hour`. LLM token counts (for `/extract/*`, `/analyze/*`, and `/youtube/search`) are nested inside the `analysis_request` charge — read them via the `analysis_tokens` accessor rather than expecting flat `total_tokens`. When a charge is waived via a cache-hit sponsorship, the entry carries `waived: true` + `credits_saved`, and the block carries a top-level `waived.credits_saved`.
473
+
428
474
  ---
429
475
 
430
476
  ## API Reference
@@ -435,20 +481,20 @@ All methods return a `Promise`. Responses are automatically parsed into typed mo
435
481
 
436
482
  | Method | Description |
437
483
  |--------|-------------|
438
- | `getYouTubeTranscript(payload)` | Get transcript for a YouTube video (fast, caption-based) |
439
- | `getTranscript(payload)` | Get transcript for non-YouTube videos (Vimeo, X/Twitter, TikTok, etc. — note: Instagram not supported) |
484
+ | `getTranscript(payload)` | Get a transcript for any supported video; auto-detects the platform from the URL (note: Instagram uses `transcribeVideo`) |
485
+ | `getYouTubeTranscript(payload)` | **Deprecated** — forwards to `getTranscript()` |
440
486
  | `transcribeVideo(payload)` | Speech-to-text transcription via AI models; supports Instagram carousel with `all_videos` |
441
487
 
442
- **Common options:** `video_url`, `language`, `metadata_only`, `fallback_to_metadata`, `transcript_text`
488
+ **Common options:** `video_url`, `language`, `metadata_only`, `fallback_to_metadata`, `transcript_text`, `include_usage`
443
489
 
444
490
  ### TikTok
445
491
 
446
492
  | Method | Description |
447
493
  |--------|-------------|
448
494
  | `submitTikTokProfileScrape(payload)` | Start an async public TikTok profile scrape. Returns a `task_id` immediately |
449
- | `getTikTokProfileScrape(task_id, query?)` | Poll task status and retrieve a page of videos. Options: `cursor`, `limit` |
495
+ | `getTikTokProfileScrape(task_id, query?)` | Poll task status and retrieve a page of videos. Options: `cursor`, `limit`, `include_usage` |
450
496
  | `submitTikTokSearch(payload)` | Start an async TikTok keyword search. Returns a `task_id` immediately |
451
- | `getTikTokSearch(task_id, query?)` | Poll search status and retrieve a page of results. Options: `cursor`, `limit` |
497
+ | `getTikTokSearch(task_id, query?)` | Poll search status and retrieve a page of results. Options: `cursor`, `limit`, `include_usage` |
452
498
 
453
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.
454
500
 
@@ -498,7 +544,7 @@ Returns `transcript_analysis` containing:
498
544
  | `extractVideoData(payload)` | Extract structured data from an online video transcript |
499
545
  | `extractFileData(payload)` | Extract structured data from an uploaded file transcript |
500
546
 
501
- **Options:** `schema` (required for JSON requests), `schemaFilePath` (JSON/YAML schema file via multipart form-data), `what_to_extract` (optional guidance), `include_usage` (token tracking)
547
+ **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`)
502
548
 
503
549
  **Schema field types:** `String`, `Number`, `Boolean`, `Integer`, `Object`, `Array`, `Enum`
504
550
 
@@ -506,10 +552,13 @@ Returns `transcript_analysis` containing:
506
552
 
507
553
  | Method | Description |
508
554
  |--------|-------------|
509
- | `searchVideos(payload)` | Search YouTube videos with AI ranking/reranking |
555
+ | `searchYouTube(payload)` | Search YouTube videos with AI ranking/reranking |
556
+ | `searchVideos(payload)` | **Deprecated** — forwards to `searchYouTube()` |
510
557
  | `searchFiles(payload)` | Semantic search across uploaded files, with optional `namespace_ids` scope |
511
558
 
512
- Results include `relevance_score`, `transcript_summary`, `people`, `places`, `key_subjects`, `query_answer`, `timestamps`, and `relevant_text`.
559
+ **`searchYouTube` options:** `query` (required), `use_enhanced_search` (default `true`), `start_year`, `end_year`, `focus` (`'relevance'` (default) \| `'popularity'` \| `'brevity'`), `duration`, `max_results` (caps candidates analysed & cost; defaults to your plan ceiling), `include_usage`.
560
+
561
+ Results include `relevance_score`, `transcript_summary`, `people`, `places`, `key_subjects`, `query_answer`, `timestamps`, and `relevant_text`. If credits run out mid-search the API returns a partial result: `searchYouTube` surfaces it as `{ status: 'partial', error_code: 'insufficient_credits_video_search', results, usage? }` instead of throwing.
513
562
 
514
563
  ### System
515
564
 
@@ -569,8 +618,10 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
569
618
  | `NamespaceRef` | Lightweight `{ id, name }` reference embedded in file and search responses |
570
619
  | `VideoSearchResult` | Extends `VideoInfo` with `relevance_score`, `transcript_summary`, search metadata |
571
620
  | `FileSearchResult` | Extends `FileInfo` with `relevance_score`, `query_answer`, timestamps, signed URL |
572
- | `UsageData` | Credits info, per-service activity counts, storage metrics, subscription details |
573
- | `ExtractionTokenUsage` | `prompt_tokens`, `completion_tokens`, `total_tokens` |
621
+ | `UsageData` | Account-level usage from `getUsage()`: credits info, per-service activity counts, storage metrics, subscription details |
622
+ | `UsageBlock` | Per-call usage returned when `include_usage: true`: `charges[]`, `total_credits`, `credits_remaining_after`, `waived`, plus `charge_for(service_type)` and `analysis_tokens` accessors |
623
+ | `UsageCharge` | A single consolidated meter charge: `service_type`, `quantity`, `credits`, `waived`, `credits_saved`, and (on `analysis_request`) `tokens` |
624
+ | `ExtractionTokenUsage` | Legacy flat token usage (`prompt_tokens`, `completion_tokens`, `total_tokens`) — extraction now returns a `UsageBlock`; prefer `usage.analysis_tokens` |
574
625
  | `CarouselInfo` | Carousel summary: total items, video/image count, transcribed count, total duration |
575
626
  | `CarouselVideoResult` | Per-video result in a carousel: index, status, video info, transcript |
576
627
  | `TikTokProfileScrapeSubmission` | Async scrape submission: `task_id`, status, profile URL, expiry |
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { AxiosRequestConfig } from 'axios';
2
- import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, ExtractionTokenUsage, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TweetStatement } from './models';
2
+ import { VideoInfo, TranscriptOutput, FileInfo, AnalysisResult, VideoSearchResult, FileSearchResult, UsageData, Namespace, NamespaceRef, ExtractionSchema, UsageBlock, CarouselInfo, CarouselVideoResult, TikTokProfileScrapeRequest, TikTokProfileScrapeSubmission, TikTokProfileTask, TikTokSearchRequest, TikTokSearchSubmission, TikTokSearchTask, TweetStatement } from './models';
3
3
  export * from './models';
4
4
  export * from './errors';
5
5
  /** SDK version (keep in sync with package.json) */
6
- export declare const SDK_VERSION = "1.0.4";
6
+ export declare const SDK_VERSION = "1.0.5";
7
7
  export interface SDKConfig {
8
8
  apiKey: string;
9
9
  baseURL?: string;
@@ -15,19 +15,28 @@ export type TranscriptRequestPayload = {
15
15
  metadata_only?: boolean;
16
16
  fallback_to_metadata?: boolean;
17
17
  transcript_text?: boolean;
18
+ include_usage?: boolean;
18
19
  };
19
20
  export type TranscribeVideoPayload = {
20
21
  video_url: string;
21
22
  transcript_text?: boolean;
22
23
  all_videos?: boolean;
24
+ include_usage?: boolean;
25
+ };
26
+ export type TranscriptResult = {
27
+ video_info: VideoInfo;
28
+ transcript: TranscriptOutput;
29
+ usage?: UsageBlock;
23
30
  };
24
31
  export type TranscribeVideoSingleResult = {
25
32
  video_info: VideoInfo;
26
33
  transcript: TranscriptOutput;
34
+ usage?: UsageBlock;
27
35
  };
28
36
  export type TranscribeVideoCarouselResult = {
29
37
  carousel_info: CarouselInfo;
30
38
  videos: CarouselVideoResult[];
39
+ usage?: UsageBlock;
31
40
  };
32
41
  export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
33
42
  export type UploadFileSuccessResult = {
@@ -52,8 +61,66 @@ export interface ExtractDataResult {
52
61
  data: Record<string, unknown>;
53
62
  video_info?: VideoInfo;
54
63
  file_info?: FileInfo;
55
- usage?: ExtractionTokenUsage;
64
+ usage?: UsageBlock;
56
65
  }
66
+ export type YouTubeSearchFocus = 'relevance' | 'popularity' | 'brevity';
67
+ export type SearchYouTubePayload = {
68
+ query: string;
69
+ use_enhanced_search?: boolean;
70
+ start_year?: number;
71
+ end_year?: number;
72
+ focus?: YouTubeSearchFocus;
73
+ duration?: number;
74
+ max_results?: number;
75
+ include_usage?: boolean;
76
+ };
77
+ export type SearchYouTubeResult = {
78
+ results: VideoSearchResult[];
79
+ query: string;
80
+ total_found: number;
81
+ explanation?: string;
82
+ usage?: UsageBlock;
83
+ /** Present when a 402 partial-results response is returned. */
84
+ status?: 'success' | 'partial';
85
+ /** Present on partial results (e.g. `insufficient_credits_video_search`). */
86
+ error_code?: string;
87
+ };
88
+ export type SearchFilesPayload = {
89
+ query: string;
90
+ namespace_ids?: string[];
91
+ include_usage?: boolean;
92
+ };
93
+ export type SearchFilesResult = {
94
+ results: FileSearchResult[];
95
+ query: string;
96
+ total_found: number;
97
+ explanation?: string;
98
+ usage?: UsageBlock;
99
+ };
100
+ export type AnalyzeVideoPayload = {
101
+ video_url: string;
102
+ query?: string;
103
+ transcript_text?: boolean;
104
+ include_usage?: boolean;
105
+ };
106
+ export type AnalyzeFilePayload = {
107
+ file_id: string;
108
+ query?: string;
109
+ transcript_text?: boolean;
110
+ include_usage?: boolean;
111
+ };
112
+ export type AnalyzeVideoResult = {
113
+ video_info: VideoInfo;
114
+ transcript: TranscriptOutput;
115
+ transcript_analysis: AnalysisResult;
116
+ usage?: UsageBlock;
117
+ };
118
+ export type AnalyzeFileResult = {
119
+ file_info: FileInfo;
120
+ transcript: TranscriptOutput;
121
+ transcript_analysis: AnalysisResult;
122
+ usage?: UsageBlock;
123
+ };
57
124
  export type ExtractVideoDataPayload = {
58
125
  video_url: string;
59
126
  schema: ExtractionSchema;
@@ -86,24 +153,30 @@ export declare class VidNavigatorClient {
86
153
  private client;
87
154
  constructor(config: SDKConfig);
88
155
  private request;
89
- getTranscript(payload: TranscriptRequestPayload): Promise<{
90
- video_info: VideoInfo;
91
- transcript: TranscriptOutput;
92
- }>;
93
- getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<{
94
- video_info: VideoInfo;
95
- transcript: TranscriptOutput;
96
- }>;
156
+ /**
157
+ * Get a transcript for any supported video. The endpoint auto-detects the
158
+ * platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
159
+ * from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
160
+ */
161
+ getTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult>;
162
+ /**
163
+ * @deprecated There is now a single `/transcript` endpoint that auto-detects the
164
+ * platform. Use {@link VidNavigatorClient.getTranscript} instead. This alias
165
+ * forwards to `getTranscript` and will be removed in a future release.
166
+ */
167
+ getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult>;
97
168
  transcribeVideo(payload: TranscribeVideoPayload): Promise<TranscribeVideoResult>;
98
169
  submitTikTokProfileScrape(payload: TikTokProfileScrapeRequest): Promise<TikTokProfileScrapeSubmission>;
99
170
  getTikTokProfileScrape(task_id: string, query?: {
100
171
  cursor?: string;
101
172
  limit?: number;
173
+ include_usage?: boolean;
102
174
  }): Promise<TikTokProfileTask>;
103
175
  submitTikTokSearch(payload: TikTokSearchRequest): Promise<TikTokSearchSubmission>;
104
176
  getTikTokSearch(task_id: string, query?: {
105
177
  cursor?: string;
106
178
  limit?: number;
179
+ include_usage?: boolean;
107
180
  }): Promise<TikTokSearchTask>;
108
181
  getFiles(query?: {
109
182
  limit?: number;
@@ -167,51 +240,29 @@ export declare class VidNavigatorClient {
167
240
  namespace_ids: string[];
168
241
  namespaces: NamespaceRef[];
169
242
  }>;
170
- analyzeVideo(payload: {
171
- video_url: string;
172
- query?: string;
173
- transcript_text?: boolean;
174
- }): Promise<{
175
- video_info: VideoInfo;
176
- transcript: TranscriptOutput;
177
- transcript_analysis: AnalysisResult;
178
- }>;
179
- analyzeFile(payload: {
180
- file_id: string;
181
- query?: string;
182
- transcript_text?: boolean;
183
- }): Promise<{
184
- file_info: FileInfo;
185
- transcript: TranscriptOutput;
186
- transcript_analysis: AnalysisResult;
187
- }>;
243
+ analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult>;
244
+ analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult>;
188
245
  getTweetStatement(payload: {
189
246
  tweet_id: string;
190
247
  }): Promise<TweetStatement>;
191
248
  extractVideoData(payload: ExtractVideoDataPayload | ExtractVideoDataMultipartPayload): Promise<ExtractDataResult>;
192
249
  extractFileData(payload: ExtractFileDataPayload | ExtractFileDataMultipartPayload): Promise<ExtractDataResult>;
193
- searchVideos(payload: {
194
- query: string;
195
- use_enhanced_search?: boolean;
196
- start_year?: number;
197
- end_year?: number;
198
- focus?: 'relevance' | 'popularity' | 'brevity';
199
- duration?: number;
200
- }): Promise<{
201
- results: VideoSearchResult[];
202
- query: string;
203
- total_found: number;
204
- explanation?: string;
205
- }>;
206
- searchFiles(payload: {
207
- query: string;
208
- namespace_ids?: string[];
209
- }): Promise<{
210
- results: FileSearchResult[];
211
- query: string;
212
- total_found: number;
213
- explanation?: string;
214
- }>;
250
+ /**
251
+ * Search YouTube for videos with AI analysis and ranking.
252
+ *
253
+ * If the account runs out of `residential_request` credits mid-search, the API
254
+ * returns HTTP 402 with `status: "partial"` and the videos analysed so far. The
255
+ * SDK surfaces that partial payload (results, `status: "partial"`, `error_code`,
256
+ * and `usage` when requested) instead of throwing.
257
+ */
258
+ searchYouTube(payload: SearchYouTubePayload): Promise<SearchYouTubeResult>;
259
+ /**
260
+ * @deprecated `/search/video` moved to `/youtube/search`. Use
261
+ * {@link VidNavigatorClient.searchYouTube} instead. This alias forwards to
262
+ * `searchYouTube` and will be removed in a future release.
263
+ */
264
+ searchVideos(payload: SearchYouTubePayload): Promise<SearchYouTubeResult>;
265
+ searchFiles(payload: SearchFilesPayload): Promise<SearchFilesResult>;
215
266
  getUsage(): Promise<UsageData>;
216
267
  healthCheck(): Promise<{
217
268
  status?: string;
package/dist/index.js CHANGED
@@ -26,7 +26,7 @@ const errors_1 = require("./errors");
26
26
  __exportStar(require("./models"), exports);
27
27
  __exportStar(require("./errors"), exports);
28
28
  /** SDK version (keep in sync with package.json) */
29
- exports.SDK_VERSION = '1.0.4';
29
+ exports.SDK_VERSION = '1.0.5';
30
30
  //endregion
31
31
  function parseApiErrorPayload(data) {
32
32
  const errorField = data?.error;
@@ -40,6 +40,28 @@ function appendOptionalFormField(form, name, value) {
40
40
  form.append(name, String(value));
41
41
  }
42
42
  }
43
+ function buildTikTokPollParams(query) {
44
+ if (!query)
45
+ return undefined;
46
+ const params = {};
47
+ if (query.cursor !== undefined)
48
+ params.cursor = query.cursor;
49
+ if (query.limit !== undefined)
50
+ params.limit = query.limit;
51
+ // The TikTok pollers expect include_usage as a query string value.
52
+ if (query.include_usage)
53
+ params.include_usage = 'true';
54
+ return params;
55
+ }
56
+ const _deprecationWarned = new Set();
57
+ function warnDeprecated(oldName, newName) {
58
+ if (_deprecationWarned.has(oldName))
59
+ return;
60
+ _deprecationWarned.add(oldName);
61
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
62
+ console.warn(`[vidnavigator] ${oldName}() is deprecated and will be removed in a future release; use ${newName}() instead.`);
63
+ }
64
+ }
43
65
  class VidNavigatorClient {
44
66
  constructor(config) {
45
67
  if (!config?.apiKey) {
@@ -100,33 +122,44 @@ class VidNavigatorClient {
100
122
  }
101
123
  }
102
124
  //region --- Transcripts ---
125
+ /**
126
+ * Get a transcript for any supported video. The endpoint auto-detects the
127
+ * platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
128
+ * from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
129
+ */
103
130
  async getTranscript(payload) {
104
131
  const response = await this.request('POST', '/transcript', payload);
105
132
  return {
106
133
  video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
107
134
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
135
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
108
136
  };
109
137
  }
138
+ /**
139
+ * @deprecated There is now a single `/transcript` endpoint that auto-detects the
140
+ * platform. Use {@link VidNavigatorClient.getTranscript} instead. This alias
141
+ * forwards to `getTranscript` and will be removed in a future release.
142
+ */
110
143
  async getYouTubeTranscript(payload) {
111
- const response = await this.request('POST', '/youtube/transcript', payload);
112
- return {
113
- video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
114
- transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
115
- };
144
+ warnDeprecated('getYouTubeTranscript', 'getTranscript');
145
+ return this.getTranscript(payload);
116
146
  }
117
147
  async transcribeVideo(payload) {
118
148
  const response = await this.request('POST', '/transcribe', payload);
119
149
  const inner = response.data;
150
+ const usage = response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined;
120
151
  if ('videos' in inner && 'carousel_info' in inner) {
121
152
  return {
122
153
  carousel_info: models_1.CarouselInfo.fromJSON(inner.carousel_info),
123
154
  videos: inner.videos.map((v) => models_1.CarouselVideoResult.fromJSON(v)),
155
+ usage,
124
156
  };
125
157
  }
126
158
  const single = inner;
127
159
  return {
128
160
  video_info: models_1.VideoInfo.fromJSON(single.video_info),
129
161
  transcript: (0, models_1.transcriptFromJSON)(single.transcript),
162
+ usage,
130
163
  };
131
164
  }
132
165
  //endregion
@@ -136,16 +169,22 @@ class VidNavigatorClient {
136
169
  return models_1.TikTokProfileScrapeSubmission.fromJSON(response.data);
137
170
  }
138
171
  async getTikTokProfileScrape(task_id, query) {
139
- const response = await this.request('GET', `/tiktok/profile/${task_id}`, undefined, query);
140
- return models_1.TikTokProfileTask.fromJSON(response.data);
172
+ const response = await this.request('GET', `/tiktok/profile/${task_id}`, undefined, buildTikTokPollParams(query));
173
+ const task = models_1.TikTokProfileTask.fromJSON(response.data);
174
+ if (response.usage)
175
+ task.usage = models_1.UsageBlock.fromJSON(response.usage);
176
+ return task;
141
177
  }
142
178
  async submitTikTokSearch(payload) {
143
179
  const response = await this.request('POST', '/tiktok/search', payload);
144
180
  return models_1.TikTokSearchSubmission.fromJSON(response.data);
145
181
  }
146
182
  async getTikTokSearch(task_id, query) {
147
- const response = await this.request('GET', `/tiktok/search/${task_id}`, undefined, query);
148
- return models_1.TikTokSearchTask.fromJSON(response.data);
183
+ const response = await this.request('GET', `/tiktok/search/${task_id}`, undefined, buildTikTokPollParams(query));
184
+ const task = models_1.TikTokSearchTask.fromJSON(response.data);
185
+ if (response.usage)
186
+ task.usage = models_1.UsageBlock.fromJSON(response.usage);
187
+ return task;
149
188
  }
150
189
  //endregion
151
190
  //region --- Files ---
@@ -275,6 +314,7 @@ class VidNavigatorClient {
275
314
  video_info: models_1.VideoInfo.fromJSON(response.data.video_info),
276
315
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
277
316
  transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
317
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
278
318
  };
279
319
  }
280
320
  async analyzeFile(payload) {
@@ -283,6 +323,7 @@ class VidNavigatorClient {
283
323
  file_info: models_1.FileInfo.fromJSON(response.data.file_info),
284
324
  transcript: (0, models_1.transcriptFromJSON)(response.data.transcript),
285
325
  transcript_analysis: models_1.AnalysisResult.fromJSON(response.data.transcript_analysis),
326
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
286
327
  };
287
328
  }
288
329
  async getTweetStatement(payload) {
@@ -303,14 +344,14 @@ class VidNavigatorClient {
303
344
  return {
304
345
  data: body.data,
305
346
  video_info: body.video_info ? models_1.VideoInfo.fromJSON(body.video_info) : undefined,
306
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
347
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
307
348
  };
308
349
  }
309
350
  const body = await this.request('POST', '/extract/video', payload);
310
351
  return {
311
352
  data: body.data,
312
353
  video_info: body.video_info ? models_1.VideoInfo.fromJSON(body.video_info) : undefined,
313
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
354
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
314
355
  };
315
356
  }
316
357
  async extractFileData(payload) {
@@ -324,27 +365,59 @@ class VidNavigatorClient {
324
365
  return {
325
366
  data: body.data,
326
367
  file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
327
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
368
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
328
369
  };
329
370
  }
330
371
  const body = await this.request('POST', '/extract/file', payload);
331
372
  return {
332
373
  data: body.data,
333
374
  file_info: body.file_info ? models_1.FileInfo.fromJSON(body.file_info) : undefined,
334
- usage: body.usage ? models_1.ExtractionTokenUsage.fromJSON(body.usage) : undefined,
375
+ usage: body.usage ? models_1.UsageBlock.fromJSON(body.usage) : undefined,
335
376
  };
336
377
  }
337
378
  //endregion
338
379
  //region --- Search ---
339
- async searchVideos(payload) {
340
- const response = await this.request('POST', '/search/video', payload);
380
+ /**
381
+ * Search YouTube for videos with AI analysis and ranking.
382
+ *
383
+ * If the account runs out of `residential_request` credits mid-search, the API
384
+ * returns HTTP 402 with `status: "partial"` and the videos analysed so far. The
385
+ * SDK surfaces that partial payload (results, `status: "partial"`, `error_code`,
386
+ * and `usage` when requested) instead of throwing.
387
+ */
388
+ async searchYouTube(payload) {
389
+ let response;
390
+ try {
391
+ response = await this.request('POST', '/youtube/search', payload);
392
+ }
393
+ catch (error) {
394
+ const body = error?.details;
395
+ if (error instanceof errors_1.PaymentRequiredError && body?.status === 'partial' && body?.data) {
396
+ response = body;
397
+ }
398
+ else {
399
+ throw error;
400
+ }
401
+ }
341
402
  return {
342
- results: response.data.results.map(models_1.VideoSearchResult.fromJSON),
403
+ results: (response.data.results ?? []).map(models_1.VideoSearchResult.fromJSON),
343
404
  query: response.data.query,
344
405
  total_found: response.data.total_found,
345
406
  explanation: response.data.explanation,
407
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
408
+ status: response.status,
409
+ error_code: response.error_code,
346
410
  };
347
411
  }
412
+ /**
413
+ * @deprecated `/search/video` moved to `/youtube/search`. Use
414
+ * {@link VidNavigatorClient.searchYouTube} instead. This alias forwards to
415
+ * `searchYouTube` and will be removed in a future release.
416
+ */
417
+ async searchVideos(payload) {
418
+ warnDeprecated('searchVideos', 'searchYouTube');
419
+ return this.searchYouTube(payload);
420
+ }
348
421
  async searchFiles(payload) {
349
422
  const response = await this.request('POST', '/search/file', payload);
350
423
  return {
@@ -352,6 +425,7 @@ class VidNavigatorClient {
352
425
  query: response.data.query,
353
426
  total_found: response.data.total_found,
354
427
  explanation: response.data.explanation,
428
+ usage: response.usage ? models_1.UsageBlock.fromJSON(response.usage) : undefined,
355
429
  };
356
430
  }
357
431
  //endregion
@@ -1,3 +1,4 @@
1
+ import { UsageBlock } from './Usage';
1
2
  export interface TikTokProfileScrapeRequest {
2
3
  profile_url: string;
3
4
  max_posts?: number;
@@ -207,6 +208,8 @@ export declare class TikTokProfileTask {
207
208
  created_at?: string | null;
208
209
  completed_at?: string | null;
209
210
  expires_at?: string | null;
211
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
212
+ usage?: UsageBlock;
210
213
  constructor(data: TikTokProfileTaskJSON);
211
214
  static fromJSON(json: TikTokProfileTaskJSON): TikTokProfileTask;
212
215
  }
@@ -239,6 +242,8 @@ export declare class TikTokSearchTask {
239
242
  created_at?: string | null;
240
243
  completed_at?: string | null;
241
244
  expires_at?: string | null;
245
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
246
+ usage?: UsageBlock;
242
247
  constructor(data: TikTokSearchTaskJSON);
243
248
  static fromJSON(json: TikTokSearchTaskJSON): TikTokSearchTask;
244
249
  }