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.
@@ -1,4 +1,75 @@
1
1
  export type UnlimitedOrNumber = number | 'unlimited';
2
+ /** Meters that can appear in a per-call {@link UsageBlock}. */
3
+ export type UsageServiceType = 'standard_request' | 'residential_request' | 'transcription_hour' | 'analysis_request' | 'search_request' | 'scene_analysis_hour';
4
+ export interface UsageTokens {
5
+ prompt_tokens?: number;
6
+ completion_tokens?: number;
7
+ total_tokens?: number;
8
+ }
9
+ export interface UsageChargeJSON {
10
+ service_type: UsageServiceType;
11
+ quantity: number;
12
+ credits: number;
13
+ waived?: boolean;
14
+ credits_saved?: number;
15
+ tokens?: UsageTokens;
16
+ }
17
+ /** A single consolidated meter charge within a per-call usage block. */
18
+ export declare class UsageCharge {
19
+ service_type: UsageServiceType;
20
+ quantity: number;
21
+ credits: number;
22
+ waived?: boolean;
23
+ credits_saved?: number;
24
+ tokens?: UsageTokens;
25
+ constructor(data: UsageChargeJSON);
26
+ static fromJSON(json: UsageChargeJSON): UsageCharge;
27
+ }
28
+ export interface UsageBlockJSON {
29
+ charges?: UsageChargeJSON[];
30
+ total_credits?: number;
31
+ credits_remaining_after?: number;
32
+ waived?: {
33
+ credits_saved: number;
34
+ };
35
+ /** Legacy flat token fields. Some /extract/* responses may still echo these. */
36
+ prompt_tokens?: number;
37
+ completion_tokens?: number;
38
+ total_tokens?: number;
39
+ }
40
+ /**
41
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
42
+ * Lists every meter charged during the request plus the credits actually deducted.
43
+ *
44
+ * LLM token counts live nested inside the `analysis_request` charge; use the
45
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
46
+ * legacy flat token fields when present).
47
+ */
48
+ export declare class UsageBlock {
49
+ charges: UsageCharge[];
50
+ total_credits?: number;
51
+ credits_remaining_after?: number;
52
+ waived?: {
53
+ credits_saved: number;
54
+ };
55
+ /** Legacy flat token fields, only present on some /extract/* responses. */
56
+ prompt_tokens?: number;
57
+ completion_tokens?: number;
58
+ total_tokens?: number;
59
+ constructor(data: UsageBlockJSON);
60
+ /** Return the consolidated charge entry for a given meter, if present. */
61
+ charge_for(service_type: UsageServiceType): UsageCharge | undefined;
62
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
63
+ chargeFor(service_type: UsageServiceType): UsageCharge | undefined;
64
+ /**
65
+ * LLM token tally for this request. Reads the `tokens` object from the
66
+ * `analysis_request` charge, falling back to legacy flat token fields.
67
+ */
68
+ get analysis_tokens(): UsageTokens | undefined;
69
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
70
+ get analysisTokens(): UsageTokens | undefined;
71
+ static fromJSON(json: UsageBlockJSON): UsageBlock;
72
+ }
2
73
  export interface CreditsInfoJSON {
3
74
  monthly_total: UnlimitedOrNumber;
4
75
  monthly_remaining: UnlimitedOrNumber;
@@ -1,6 +1,75 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UsageData = exports.StorageUsage = exports.CapacityMetric = exports.ActivityCount = exports.CreditsInfo = void 0;
3
+ exports.UsageData = exports.StorageUsage = exports.CapacityMetric = exports.ActivityCount = exports.CreditsInfo = exports.UsageBlock = exports.UsageCharge = void 0;
4
+ /** A single consolidated meter charge within a per-call usage block. */
5
+ class UsageCharge {
6
+ constructor(data) {
7
+ this.service_type = data.service_type;
8
+ this.quantity = data.quantity;
9
+ this.credits = data.credits;
10
+ this.waived = data.waived;
11
+ this.credits_saved = data.credits_saved;
12
+ this.tokens = data.tokens;
13
+ }
14
+ static fromJSON(json) {
15
+ return new UsageCharge(json);
16
+ }
17
+ }
18
+ exports.UsageCharge = UsageCharge;
19
+ /**
20
+ * Per-call usage disclosure returned when a request is made with `include_usage=true`.
21
+ * Lists every meter charged during the request plus the credits actually deducted.
22
+ *
23
+ * LLM token counts live nested inside the `analysis_request` charge; use the
24
+ * {@link UsageBlock.analysis_tokens} accessor to read them (it falls back to the
25
+ * legacy flat token fields when present).
26
+ */
27
+ class UsageBlock {
28
+ constructor(data) {
29
+ this.charges = (data.charges ?? []).map(UsageCharge.fromJSON);
30
+ this.total_credits = data.total_credits;
31
+ this.credits_remaining_after = data.credits_remaining_after;
32
+ this.waived = data.waived;
33
+ this.prompt_tokens = data.prompt_tokens;
34
+ this.completion_tokens = data.completion_tokens;
35
+ this.total_tokens = data.total_tokens;
36
+ }
37
+ /** Return the consolidated charge entry for a given meter, if present. */
38
+ charge_for(service_type) {
39
+ return this.charges.find((c) => c.service_type === service_type);
40
+ }
41
+ /** camelCase alias for {@link UsageBlock.charge_for}. */
42
+ chargeFor(service_type) {
43
+ return this.charge_for(service_type);
44
+ }
45
+ /**
46
+ * LLM token tally for this request. Reads the `tokens` object from the
47
+ * `analysis_request` charge, falling back to legacy flat token fields.
48
+ */
49
+ get analysis_tokens() {
50
+ const analysis = this.charge_for('analysis_request');
51
+ if (analysis?.tokens)
52
+ return analysis.tokens;
53
+ if (this.prompt_tokens !== undefined ||
54
+ this.completion_tokens !== undefined ||
55
+ this.total_tokens !== undefined) {
56
+ return {
57
+ prompt_tokens: this.prompt_tokens,
58
+ completion_tokens: this.completion_tokens,
59
+ total_tokens: this.total_tokens,
60
+ };
61
+ }
62
+ return undefined;
63
+ }
64
+ /** camelCase alias for {@link UsageBlock.analysis_tokens}. */
65
+ get analysisTokens() {
66
+ return this.analysis_tokens;
67
+ }
68
+ static fromJSON(json) {
69
+ return new UsageBlock(json);
70
+ }
71
+ }
72
+ exports.UsageBlock = UsageBlock;
4
73
  class CreditsInfo {
5
74
  constructor(data) {
6
75
  this.monthly_total = data.monthly_total;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vidnavigator",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "Official JavaScript SDK for the VidNavigator Developer API",
5
5
  "author": "VidNavigator",
6
6
  "license": "Apache-2.0",
package/src/index.ts CHANGED
@@ -22,8 +22,8 @@ import {
22
22
  NamespaceRef,
23
23
  NamespaceRefJSON,
24
24
  ExtractionSchema,
25
- ExtractionTokenUsage,
26
- ExtractionTokenUsageJSON,
25
+ UsageBlock,
26
+ UsageBlockJSON,
27
27
  CarouselInfo,
28
28
  CarouselInfoJSON,
29
29
  CarouselVideoResult,
@@ -59,7 +59,7 @@ export * from './models';
59
59
  export * from './errors';
60
60
 
61
61
  /** SDK version (keep in sync with package.json) */
62
- export const SDK_VERSION = '1.0.4';
62
+ export const SDK_VERSION = '1.0.5';
63
63
 
64
64
  //region --- Interfaces ---
65
65
  export interface SDKConfig {
@@ -71,6 +71,7 @@ export interface SDKConfig {
71
71
  interface ApiSuccessResponse<T> {
72
72
  status: 'success';
73
73
  data: T;
74
+ usage?: UsageBlockJSON;
74
75
  }
75
76
 
76
77
  export type TranscriptRequestPayload = {
@@ -79,22 +80,32 @@ export type TranscriptRequestPayload = {
79
80
  metadata_only?: boolean;
80
81
  fallback_to_metadata?: boolean;
81
82
  transcript_text?: boolean;
83
+ include_usage?: boolean;
82
84
  };
83
85
 
84
86
  export type TranscribeVideoPayload = {
85
87
  video_url: string;
86
88
  transcript_text?: boolean;
87
89
  all_videos?: boolean;
90
+ include_usage?: boolean;
91
+ };
92
+
93
+ export type TranscriptResult = {
94
+ video_info: VideoInfo;
95
+ transcript: TranscriptOutput;
96
+ usage?: UsageBlock;
88
97
  };
89
98
 
90
99
  export type TranscribeVideoSingleResult = {
91
100
  video_info: VideoInfo;
92
101
  transcript: TranscriptOutput;
102
+ usage?: UsageBlock;
93
103
  };
94
104
 
95
105
  export type TranscribeVideoCarouselResult = {
96
106
  carousel_info: CarouselInfo;
97
107
  videos: CarouselVideoResult[];
108
+ usage?: UsageBlock;
98
109
  };
99
110
 
100
111
  export type TranscribeVideoResult = TranscribeVideoSingleResult | TranscribeVideoCarouselResult;
@@ -124,9 +135,76 @@ export interface ExtractDataResult {
124
135
  data: Record<string, unknown>;
125
136
  video_info?: VideoInfo;
126
137
  file_info?: FileInfo;
127
- usage?: ExtractionTokenUsage;
138
+ usage?: UsageBlock;
128
139
  }
129
140
 
141
+ export type YouTubeSearchFocus = 'relevance' | 'popularity' | 'brevity';
142
+
143
+ export type SearchYouTubePayload = {
144
+ query: string;
145
+ use_enhanced_search?: boolean;
146
+ start_year?: number;
147
+ end_year?: number;
148
+ focus?: YouTubeSearchFocus;
149
+ duration?: number;
150
+ max_results?: number;
151
+ include_usage?: boolean;
152
+ };
153
+
154
+ export type SearchYouTubeResult = {
155
+ results: VideoSearchResult[];
156
+ query: string;
157
+ total_found: number;
158
+ explanation?: string;
159
+ usage?: UsageBlock;
160
+ /** Present when a 402 partial-results response is returned. */
161
+ status?: 'success' | 'partial';
162
+ /** Present on partial results (e.g. `insufficient_credits_video_search`). */
163
+ error_code?: string;
164
+ };
165
+
166
+ export type SearchFilesPayload = {
167
+ query: string;
168
+ namespace_ids?: string[];
169
+ include_usage?: boolean;
170
+ };
171
+
172
+ export type SearchFilesResult = {
173
+ results: FileSearchResult[];
174
+ query: string;
175
+ total_found: number;
176
+ explanation?: string;
177
+ usage?: UsageBlock;
178
+ };
179
+
180
+ export type AnalyzeVideoPayload = {
181
+ video_url: string;
182
+ query?: string;
183
+ transcript_text?: boolean;
184
+ include_usage?: boolean;
185
+ };
186
+
187
+ export type AnalyzeFilePayload = {
188
+ file_id: string;
189
+ query?: string;
190
+ transcript_text?: boolean;
191
+ include_usage?: boolean;
192
+ };
193
+
194
+ export type AnalyzeVideoResult = {
195
+ video_info: VideoInfo;
196
+ transcript: TranscriptOutput;
197
+ transcript_analysis: AnalysisResult;
198
+ usage?: UsageBlock;
199
+ };
200
+
201
+ export type AnalyzeFileResult = {
202
+ file_info: FileInfo;
203
+ transcript: TranscriptOutput;
204
+ transcript_analysis: AnalysisResult;
205
+ usage?: UsageBlock;
206
+ };
207
+
130
208
  export type ExtractVideoDataPayload = {
131
209
  video_url: string;
132
210
  schema: ExtractionSchema;
@@ -180,6 +258,32 @@ function appendOptionalFormField(form: FormData, name: string, value: string | n
180
258
  }
181
259
  }
182
260
 
261
+ function buildTikTokPollParams(query?: {
262
+ cursor?: string;
263
+ limit?: number;
264
+ include_usage?: boolean;
265
+ }): Record<string, string | number> | undefined {
266
+ if (!query) return undefined;
267
+ const params: Record<string, string | number> = {};
268
+ if (query.cursor !== undefined) params.cursor = query.cursor;
269
+ if (query.limit !== undefined) params.limit = query.limit;
270
+ // The TikTok pollers expect include_usage as a query string value.
271
+ if (query.include_usage) params.include_usage = 'true';
272
+ return params;
273
+ }
274
+
275
+ const _deprecationWarned = new Set<string>();
276
+
277
+ function warnDeprecated(oldName: string, newName: string): void {
278
+ if (_deprecationWarned.has(oldName)) return;
279
+ _deprecationWarned.add(oldName);
280
+ if (typeof console !== 'undefined' && typeof console.warn === 'function') {
281
+ console.warn(
282
+ `[vidnavigator] ${oldName}() is deprecated and will be removed in a future release; use ${newName}() instead.`
283
+ );
284
+ }
285
+ }
286
+
183
287
  export class VidNavigatorClient {
184
288
  private client: AxiosInstance;
185
289
 
@@ -258,10 +362,12 @@ export class VidNavigatorClient {
258
362
  }
259
363
 
260
364
  //region --- Transcripts ---
261
- async getTranscript(payload: TranscriptRequestPayload): Promise<{
262
- video_info: VideoInfo;
263
- transcript: TranscriptOutput;
264
- }> {
365
+ /**
366
+ * Get a transcript for any supported video. The endpoint auto-detects the
367
+ * platform (YouTube, Vimeo, X/Twitter, TikTok, Facebook, Dailymotion, Loom, etc.)
368
+ * from `video_url`. For Instagram, use {@link VidNavigatorClient.transcribeVideo}.
369
+ */
370
+ async getTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult> {
265
371
  const response = await this.request<
266
372
  ApiSuccessResponse<{
267
373
  video_info: VideoInfoJSON;
@@ -272,24 +378,18 @@ export class VidNavigatorClient {
272
378
  return {
273
379
  video_info: VideoInfo.fromJSON(response.data.video_info),
274
380
  transcript: transcriptFromJSON(response.data.transcript)!,
381
+ usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
275
382
  };
276
383
  }
277
384
 
278
- async getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<{
279
- video_info: VideoInfo;
280
- transcript: TranscriptOutput;
281
- }> {
282
- const response = await this.request<
283
- ApiSuccessResponse<{
284
- video_info: VideoInfoJSON;
285
- transcript: TranscriptSegmentJSON[] | string;
286
- }>
287
- >('POST', '/youtube/transcript', payload);
288
-
289
- return {
290
- video_info: VideoInfo.fromJSON(response.data.video_info),
291
- transcript: transcriptFromJSON(response.data.transcript)!,
292
- };
385
+ /**
386
+ * @deprecated There is now a single `/transcript` endpoint that auto-detects the
387
+ * platform. Use {@link VidNavigatorClient.getTranscript} instead. This alias
388
+ * forwards to `getTranscript` and will be removed in a future release.
389
+ */
390
+ async getYouTubeTranscript(payload: TranscriptRequestPayload): Promise<TranscriptResult> {
391
+ warnDeprecated('getYouTubeTranscript', 'getTranscript');
392
+ return this.getTranscript(payload);
293
393
  }
294
394
 
295
395
  async transcribeVideo(payload: TranscribeVideoPayload): Promise<TranscribeVideoResult> {
@@ -305,10 +405,12 @@ export class VidNavigatorClient {
305
405
  >('POST', '/transcribe', payload);
306
406
 
307
407
  const inner = response.data;
408
+ const usage = response.usage ? UsageBlock.fromJSON(response.usage) : undefined;
308
409
  if ('videos' in inner && 'carousel_info' in inner) {
309
410
  return {
310
411
  carousel_info: CarouselInfo.fromJSON(inner.carousel_info),
311
412
  videos: inner.videos.map((v) => CarouselVideoResult.fromJSON(v)),
413
+ usage,
312
414
  };
313
415
  }
314
416
  const single = inner as {
@@ -318,6 +420,7 @@ export class VidNavigatorClient {
318
420
  return {
319
421
  video_info: VideoInfo.fromJSON(single.video_info),
320
422
  transcript: transcriptFromJSON(single.transcript)!,
423
+ usage,
321
424
  };
322
425
  }
323
426
  //endregion
@@ -336,15 +439,17 @@ export class VidNavigatorClient {
336
439
 
337
440
  async getTikTokProfileScrape(
338
441
  task_id: string,
339
- query?: { cursor?: string; limit?: number }
442
+ query?: { cursor?: string; limit?: number; include_usage?: boolean }
340
443
  ): Promise<TikTokProfileTask> {
341
444
  const response = await this.request<ApiSuccessResponse<TikTokProfileTaskJSON>>(
342
445
  'GET',
343
446
  `/tiktok/profile/${task_id}`,
344
447
  undefined,
345
- query
448
+ buildTikTokPollParams(query)
346
449
  );
347
- return TikTokProfileTask.fromJSON(response.data);
450
+ const task = TikTokProfileTask.fromJSON(response.data);
451
+ if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
452
+ return task;
348
453
  }
349
454
 
350
455
  async submitTikTokSearch(payload: TikTokSearchRequest): Promise<TikTokSearchSubmission> {
@@ -358,15 +463,17 @@ export class VidNavigatorClient {
358
463
 
359
464
  async getTikTokSearch(
360
465
  task_id: string,
361
- query?: { cursor?: string; limit?: number }
466
+ query?: { cursor?: string; limit?: number; include_usage?: boolean }
362
467
  ): Promise<TikTokSearchTask> {
363
468
  const response = await this.request<ApiSuccessResponse<TikTokSearchTaskJSON>>(
364
469
  'GET',
365
470
  `/tiktok/search/${task_id}`,
366
471
  undefined,
367
- query
472
+ buildTikTokPollParams(query)
368
473
  );
369
- return TikTokSearchTask.fromJSON(response.data);
474
+ const task = TikTokSearchTask.fromJSON(response.data);
475
+ if (response.usage) task.usage = UsageBlock.fromJSON(response.usage);
476
+ return task;
370
477
  }
371
478
  //endregion
372
479
 
@@ -583,15 +690,7 @@ export class VidNavigatorClient {
583
690
  //endregion
584
691
 
585
692
  //region --- Analysis ---
586
- async analyzeVideo(payload: {
587
- video_url: string;
588
- query?: string;
589
- transcript_text?: boolean;
590
- }): Promise<{
591
- video_info: VideoInfo;
592
- transcript: TranscriptOutput;
593
- transcript_analysis: AnalysisResult;
594
- }> {
693
+ async analyzeVideo(payload: AnalyzeVideoPayload): Promise<AnalyzeVideoResult> {
595
694
  const response = await this.request<
596
695
  ApiSuccessResponse<{
597
696
  video_info: VideoInfoJSON;
@@ -604,18 +703,11 @@ export class VidNavigatorClient {
604
703
  video_info: VideoInfo.fromJSON(response.data.video_info),
605
704
  transcript: transcriptFromJSON(response.data.transcript)!,
606
705
  transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
706
+ usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
607
707
  };
608
708
  }
609
709
 
610
- async analyzeFile(payload: {
611
- file_id: string;
612
- query?: string;
613
- transcript_text?: boolean;
614
- }): Promise<{
615
- file_info: FileInfo;
616
- transcript: TranscriptOutput;
617
- transcript_analysis: AnalysisResult;
618
- }> {
710
+ async analyzeFile(payload: AnalyzeFilePayload): Promise<AnalyzeFileResult> {
619
711
  const response = await this.request<
620
712
  ApiSuccessResponse<{
621
713
  file_info: FileInfoJSON;
@@ -628,6 +720,7 @@ export class VidNavigatorClient {
628
720
  file_info: FileInfo.fromJSON(response.data.file_info),
629
721
  transcript: transcriptFromJSON(response.data.transcript)!,
630
722
  transcript_analysis: AnalysisResult.fromJSON(response.data.transcript_analysis),
723
+ usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
631
724
  };
632
725
  }
633
726
 
@@ -657,12 +750,12 @@ export class VidNavigatorClient {
657
750
  status: 'success';
658
751
  data: Record<string, unknown>;
659
752
  video_info?: VideoInfoJSON;
660
- usage?: ExtractionTokenUsageJSON;
753
+ usage?: UsageBlockJSON;
661
754
  }>('POST', '/extract/video', form, undefined, form.getHeaders());
662
755
  return {
663
756
  data: body.data,
664
757
  video_info: body.video_info ? VideoInfo.fromJSON(body.video_info) : undefined,
665
- usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
758
+ usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
666
759
  };
667
760
  }
668
761
 
@@ -670,12 +763,12 @@ export class VidNavigatorClient {
670
763
  status: 'success';
671
764
  data: Record<string, unknown>;
672
765
  video_info?: VideoInfoJSON;
673
- usage?: ExtractionTokenUsageJSON;
766
+ usage?: UsageBlockJSON;
674
767
  }>('POST', '/extract/video', payload);
675
768
  return {
676
769
  data: body.data,
677
770
  video_info: body.video_info ? VideoInfo.fromJSON(body.video_info) : undefined,
678
- usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
771
+ usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
679
772
  };
680
773
  }
681
774
 
@@ -693,12 +786,12 @@ export class VidNavigatorClient {
693
786
  status: 'success';
694
787
  data: Record<string, unknown>;
695
788
  file_info?: FileInfoJSON;
696
- usage?: ExtractionTokenUsageJSON;
789
+ usage?: UsageBlockJSON;
697
790
  }>('POST', '/extract/file', form, undefined, form.getHeaders());
698
791
  return {
699
792
  data: body.data,
700
793
  file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
701
- usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
794
+ usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
702
795
  };
703
796
  }
704
797
 
@@ -706,56 +799,71 @@ export class VidNavigatorClient {
706
799
  status: 'success';
707
800
  data: Record<string, unknown>;
708
801
  file_info?: FileInfoJSON;
709
- usage?: ExtractionTokenUsageJSON;
802
+ usage?: UsageBlockJSON;
710
803
  }>('POST', '/extract/file', payload);
711
804
  return {
712
805
  data: body.data,
713
806
  file_info: body.file_info ? FileInfo.fromJSON(body.file_info) : undefined,
714
- usage: body.usage ? ExtractionTokenUsage.fromJSON(body.usage) : undefined,
807
+ usage: body.usage ? UsageBlock.fromJSON(body.usage) : undefined,
715
808
  };
716
809
  }
717
810
  //endregion
718
811
 
719
812
  //region --- Search ---
720
- async searchVideos(payload: {
721
- query: string;
722
- use_enhanced_search?: boolean;
723
- start_year?: number;
724
- end_year?: number;
725
- focus?: 'relevance' | 'popularity' | 'brevity';
726
- duration?: number;
727
- }): Promise<{
728
- results: VideoSearchResult[];
729
- query: string;
730
- total_found: number;
731
- explanation?: string;
732
- }> {
733
- const response = await this.request<
734
- ApiSuccessResponse<{
813
+ /**
814
+ * Search YouTube for videos with AI analysis and ranking.
815
+ *
816
+ * If the account runs out of `residential_request` credits mid-search, the API
817
+ * returns HTTP 402 with `status: "partial"` and the videos analysed so far. The
818
+ * SDK surfaces that partial payload (results, `status: "partial"`, `error_code`,
819
+ * and `usage` when requested) instead of throwing.
820
+ */
821
+ async searchYouTube(payload: SearchYouTubePayload): Promise<SearchYouTubeResult> {
822
+ let response: {
823
+ status?: 'success' | 'partial';
824
+ error_code?: string;
825
+ data: {
735
826
  results: VideoSearchResultJSON[];
736
827
  query: string;
737
828
  total_found: number;
738
829
  explanation?: string;
739
- }>
740
- >('POST', '/search/video', payload);
830
+ };
831
+ usage?: UsageBlockJSON;
832
+ };
833
+
834
+ try {
835
+ response = await this.request('POST', '/youtube/search', payload);
836
+ } catch (error: any) {
837
+ const body = error?.details;
838
+ if (error instanceof PaymentRequiredError && body?.status === 'partial' && body?.data) {
839
+ response = body;
840
+ } else {
841
+ throw error;
842
+ }
843
+ }
741
844
 
742
845
  return {
743
- results: response.data.results.map(VideoSearchResult.fromJSON),
846
+ results: (response.data.results ?? []).map(VideoSearchResult.fromJSON),
744
847
  query: response.data.query,
745
848
  total_found: response.data.total_found,
746
849
  explanation: response.data.explanation,
850
+ usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
851
+ status: response.status,
852
+ error_code: response.error_code,
747
853
  };
748
854
  }
749
855
 
750
- async searchFiles(payload: {
751
- query: string;
752
- namespace_ids?: string[];
753
- }): Promise<{
754
- results: FileSearchResult[];
755
- query: string;
756
- total_found: number;
757
- explanation?: string;
758
- }> {
856
+ /**
857
+ * @deprecated `/search/video` moved to `/youtube/search`. Use
858
+ * {@link VidNavigatorClient.searchYouTube} instead. This alias forwards to
859
+ * `searchYouTube` and will be removed in a future release.
860
+ */
861
+ async searchVideos(payload: SearchYouTubePayload): Promise<SearchYouTubeResult> {
862
+ warnDeprecated('searchVideos', 'searchYouTube');
863
+ return this.searchYouTube(payload);
864
+ }
865
+
866
+ async searchFiles(payload: SearchFilesPayload): Promise<SearchFilesResult> {
759
867
  const response = await this.request<
760
868
  ApiSuccessResponse<{
761
869
  results: FileSearchResultJSON[];
@@ -770,6 +878,7 @@ export class VidNavigatorClient {
770
878
  query: response.data.query,
771
879
  total_found: response.data.total_found,
772
880
  explanation: response.data.explanation,
881
+ usage: response.usage ? UsageBlock.fromJSON(response.usage) : undefined,
773
882
  };
774
883
  }
775
884
  //endregion
@@ -1,3 +1,5 @@
1
+ import { UsageBlock } from './Usage';
2
+
1
3
  export interface TikTokProfileScrapeRequest {
2
4
  profile_url: string;
3
5
  max_posts?: number;
@@ -373,6 +375,8 @@ export class TikTokProfileTask {
373
375
  created_at?: string | null;
374
376
  completed_at?: string | null;
375
377
  expires_at?: string | null;
378
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
379
+ usage?: UsageBlock;
376
380
 
377
381
  constructor(data: TikTokProfileTaskJSON) {
378
382
  this.task_id = data.task_id;
@@ -425,6 +429,8 @@ export class TikTokSearchTask {
425
429
  created_at?: string | null;
426
430
  completed_at?: string | null;
427
431
  expires_at?: string | null;
432
+ /** Per-call usage, populated only when polled with `include_usage=true` and `task_status=completed`. */
433
+ usage?: UsageBlock;
428
434
 
429
435
  constructor(data: TikTokSearchTaskJSON) {
430
436
  this.task_id = data.task_id;