vidnavigator 3.0.1 → 3.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 +26 -9
- package/dist/errors.d.ts +10 -7
- package/dist/errors.js +10 -7
- package/dist/http.js +6 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/models/TikTok.d.ts +2 -1
- package/dist/models/Usage.d.ts +36 -8
- package/dist/models/Usage.js +11 -5
- package/package.json +1 -1
- package/src/errors.ts +10 -7
- package/src/http.ts +7 -1
- package/src/index.ts +1 -1
- package/src/models/TikTok.ts +2 -1
- package/src/models/Usage.ts +48 -13
package/README.md
CHANGED
|
@@ -310,7 +310,7 @@ try {
|
|
|
310
310
|
**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.
|
|
311
311
|
|
|
312
312
|
**When a job can't start**, submitting throws right away and no job is created:
|
|
313
|
-
- `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.
|
|
313
|
+
- `InsufficientCreditsError` (402, `insufficient_credits`): 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.
|
|
314
314
|
- `TooManyActiveJobsError` (429): too many of your jobs are already running. Wait for some to finish and retry.
|
|
315
315
|
|
|
316
316
|
**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:
|
|
@@ -563,7 +563,7 @@ for (const room of task.results) {
|
|
|
563
563
|
- Each room has the same `id`, `url`, `author` and `stats` fields as a keyword search result, plus `started_at` (a `Date`), `stats.viewers` / `stats.total_viewers`, `hashtags` (the `#tags` of the title), `category` (the LIVE's category on TikTok, e.g. `'Gaming'`) and `game_tags`.
|
|
564
564
|
- `stream_urls` holds `flv` and `hls` URLs keyed by quality (`origin`, `uhd`, `hd`, `sd`, `ld`), `default_quality`, an `audio_only` stream and `expires_at`. The URLs play while the LIVE is on. They are returned by default; pass `include_stream_urls: false` to leave them out. Not every LIVE offers HLS, so `hls` can be empty.
|
|
565
565
|
- `country` defaults to `'us'`. Results keep TikTok's ranking; a keyword with no LIVE room in that country at that moment completes with zero results.
|
|
566
|
-
- Billing: 1 `residential_request` per 30 rooms returned (`task.stats.results_count`), minimum 1 per search.
|
|
566
|
+
- Billing: 1 `residential_request` per 30 rooms returned (`task.stats.results_count`), minimum 1 per search and 1 per 5 TikTok pages read (`task.stats.pages_fetched`).
|
|
567
567
|
|
|
568
568
|
### 6c. TikTok LIVE room (sync)
|
|
569
569
|
|
|
@@ -907,10 +907,15 @@ const usage = await vn.getUsage();
|
|
|
907
907
|
console.log(`Credits remaining: ${usage.credits.monthly_remaining}`);
|
|
908
908
|
console.log(`Transcription hours used: ${usage.usage.transcriptionHour?.used}`);
|
|
909
909
|
console.log(`Standard requests used: ${usage.usage.standardRequest?.used}`);
|
|
910
|
+
console.log(`Frames analyzed: ${usage.usage.frameAnalysis?.used}`);
|
|
911
|
+
console.log(`Scene analysis hours: ${usage.usage.sceneAnalysisHour?.used}`);
|
|
910
912
|
console.log(`Storage: ${usage.storage.usedFormatted} / ${usage.storage.limitFormatted}`);
|
|
911
913
|
console.log(`Channels indexed: ${usage.channelsIndexed.used} / ${usage.channelsIndexed.limit}`);
|
|
914
|
+
console.log(`Period ends: ${usage.billingPeriod.end?.toISOString() ?? 'no subscription period'}`);
|
|
912
915
|
```
|
|
913
916
|
|
|
917
|
+
`usage.usage` has one counter per meter: `standardRequest`, `residentialRequest`, `searchRequest`, `analysisRequest`, `sceneAnalysisHour`, `transcriptionHour` and `frameAnalysis`. The older `videoTranscripts`, `youtubeTranscripts`, `videoSearches`, `videoAnalyses`, `videoSceneAnalyses` and `videoUploads` are deprecated: the API no longer sends them. `usagePeriod` and `billingPeriod` have `start` and `end` as `Date`s, or `undefined` when the account has no subscription period.
|
|
918
|
+
|
|
914
919
|
### Per-call usage
|
|
915
920
|
|
|
916
921
|
Pass `include_usage: true` to most endpoints (`getTranscript`, `transcribeVideo`, `watchVideo`, `extractVideoData`, `extractFileData`, `searchYouTube`, `searchFiles`) to receive a `usage` block describing exactly what the request cost. For background jobs (`vn.transcribe`, `vn.watch`, `vn.extractVideo`, ...), 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.
|
|
@@ -925,7 +930,7 @@ const { usage } = await vn.getTranscript({
|
|
|
925
930
|
|
|
926
931
|
if (usage) {
|
|
927
932
|
console.log(usage.total_credits); // net credits deducted by this request
|
|
928
|
-
console.log(usage.credits_remaining_after); //
|
|
933
|
+
console.log(usage.credits_remaining_after); // credits left after the request (undefined without a credit limit)
|
|
929
934
|
|
|
930
935
|
// Every meter that fired, consolidated to one entry per service_type:
|
|
931
936
|
for (const charge of usage.charges) {
|
|
@@ -939,6 +944,8 @@ if (usage) {
|
|
|
939
944
|
}
|
|
940
945
|
```
|
|
941
946
|
|
|
947
|
+
`credits_remaining_after` is the number of credits left on the account (monthly + purchased) after this request's charges. It is `undefined` on plans without a credit limit, where the API leaves it out.
|
|
948
|
+
|
|
942
949
|
`service_type` is one of: `standard_request`, `residential_request`, `transcription_hour`, `frame_analysis`, `analysis_request`, `search_request`, `scene_analysis_hour`. LLM token counts (for `/extract/*` 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, the entry carries `waived: true` + `credits_saved`, and the block carries a top-level `waived.credits_saved`.
|
|
943
950
|
|
|
944
951
|
---
|
|
@@ -1061,7 +1068,7 @@ With `include_scenes: true`, the `TweetStatement` also has `frames_analyzed`, an
|
|
|
1061
1068
|
| `searchVideos(payload)` | **Deprecated** — forwards to `searchYouTube()` |
|
|
1062
1069
|
| `searchFiles(payload)` | Semantic search across uploaded files, with optional `namespace_ids` scope |
|
|
1063
1070
|
|
|
1064
|
-
**`searchYouTube` options:** `query` (required), `use_enhanced_search` (default `true`), `start_year` / `end_year` (only videos published in or after / in or before that year), `focus` (what comes first among the matches: `'relevance'` (default) \| `'recency'` \| `'popularity'` \| `'brevity'`), `duration` (maximum length in seconds; longer videos are left out), `max_results` (caps candidates analysed & cost; defaults to your plan ceiling), `include_usage`.
|
|
1071
|
+
**`searchYouTube` options:** `query` (required), `use_enhanced_search` (default `false`: the slower enhanced search runs only when you pass `true`), `start_year` / `end_year` (only videos published in or after / in or before that year), `focus` (what comes first among the matches: `'relevance'` (default) \| `'recency'` \| `'popularity'` \| `'brevity'`), `duration` (maximum length in seconds; longer videos are left out), `max_results` (caps candidates analysed & cost; defaults to your plan ceiling), `include_usage`.
|
|
1065
1072
|
|
|
1066
1073
|
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.
|
|
1067
1074
|
|
|
@@ -1100,13 +1107,13 @@ try {
|
|
|
1100
1107
|
|-------------|:----:|------|
|
|
1101
1108
|
| `BadRequestError` | 400 | Invalid parameters |
|
|
1102
1109
|
| `AuthenticationError` | 401 | Invalid or missing API key |
|
|
1103
|
-
| `PaymentRequiredError` | 402 |
|
|
1104
|
-
| `InsufficientCreditsError` | 402 |
|
|
1110
|
+
| `PaymentRequiredError` | 402 | Any 402. Its two subclasses, `InsufficientCreditsError` and `StorageQuotaExceededError`, say which one |
|
|
1111
|
+
| `InsufficientCreditsError` | 402 | Not enough credits (`insufficient_credits`), at job submit or while a job runs. Extends `PaymentRequiredError` |
|
|
1105
1112
|
| `AccessDeniedError` | 403 | Insufficient permissions |
|
|
1106
1113
|
| `NotFoundError` | 404 | Resource does not exist, or a job's `task_id` is unknown or expired (`task_not_found`) |
|
|
1107
1114
|
| `ScenesNotAvailableError` | 409 | `include_scenes` was asked on an uploaded file that has no scenes to read (`scenes_not_available`). Has `scenes_status` (`'none'`, `'processing'` or `'failed'`) and, when failed, `scenes_error` |
|
|
1108
|
-
| `StorageQuotaExceededError` |
|
|
1109
|
-
| `RateLimitExceededError` | 429 | Too many requests |
|
|
1115
|
+
| `StorageQuotaExceededError` | 402 | The storage of the plan is full (`storage_quota_exceeded`, on upload). A `PaymentRequiredError`, from 3.0.2 |
|
|
1116
|
+
| `RateLimitExceededError` | 429 | Too many requests (`rate_limit_exceeded`); wait `Retry-After` seconds |
|
|
1110
1117
|
| `TooManyActiveJobsError` | 429 | A job could not start: too many of your jobs are already running (`too_many_active_jobs`). Extends `RateLimitExceededError` |
|
|
1111
1118
|
| `GeoRestrictedError` | 451 | Content unavailable in your region |
|
|
1112
1119
|
| `ServerError` | 5xx | Unexpected server error |
|
|
@@ -1146,11 +1153,21 @@ All API responses are parsed into typed classes with static `fromJSON()` constru
|
|
|
1146
1153
|
| `TikTokSearchTask` | TikTok keyword search task with status, results, pagination, `download_url`, `error`, `webhook`; `stats` shows the `sort_by` / `published_within` the search ran with |
|
|
1147
1154
|
| `TikTokSearchResult` | Normalized TikTok keyword result, including `published_at` as a `Date` and integer counters |
|
|
1148
1155
|
| `TikTokLiveSearchSubmission` | Async TikTok LIVE search submission: `task_id`, query, country, `include_stream_urls`, expiry, `webhook_url` |
|
|
1149
|
-
| `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; `stats.
|
|
1156
|
+
| `TikTokLiveSearchTask` | TikTok LIVE search task with status, rooms, pagination, `download_url`, `error`, `webhook`; billing follows `stats.results_count` and `stats.pages_fetched` |
|
|
1150
1157
|
| `TikTokLiveRoom` | A LIVE room: author, `stats.viewers`, `hashtags`, `category`, `game_tags`, `started_at` as a `Date`, and `stream_urls` (FLV / HLS by quality, audio only) |
|
|
1151
1158
|
| `TikTokLiveRoomDetail` | A `TikTokLiveRoom` from `getTikTokLiveRoom`: `status` / `isLive`, `ended_at`, `stats.new_followers`, `author.bio`, `share_url`, `chat_enabled`, `subscribers_only`, `products` |
|
|
1152
1159
|
| `TweetStatement` | Structured X/Twitter claim analysis, topics, entities, tone, intent, and source text; with `include_scenes`, `frames_analyzed` and `scenes_error` |
|
|
1153
1160
|
|
|
1161
|
+
## What's new in 3.1.0
|
|
1162
|
+
|
|
1163
|
+
- **The API's code for "not enough credits" is now `insufficient_credits`** (it was `limit_exceeded`). Both codes throw `InsufficientCreditsError`, a `PaymentRequiredError`; `error_code` carries the code the API sent.
|
|
1164
|
+
- **The same error classes as the Python SDK** (3.1.0): `PaymentRequiredError`, `InsufficientCreditsError`, `StorageQuotaExceededError`, `RateLimitExceededError`, `TooManyActiveJobsError`, `TaskTimeoutError`.
|
|
1165
|
+
|
|
1166
|
+
## What's new in 3.0.2
|
|
1167
|
+
|
|
1168
|
+
- **`getUsage()` keeps every counter:** `usage.frameAnalysis` and `usage.sceneAnalysisHour` were dropped; they are now there with the other counters. The legacy `videoTranscripts`, `youtubeTranscripts`, `videoSearches`, `videoAnalyses`, `videoSceneAnalyses` and `videoUploads` counters, which the API no longer sends, are marked deprecated.
|
|
1169
|
+
- **`getUsage()` on an account without a subscription period:** the API sends `null` dates then, which became January 1, 1970. `usagePeriod.start`, `usagePeriod.end`, `billingPeriod.start` and `billingPeriod.end` are now `undefined` instead.
|
|
1170
|
+
|
|
1154
1171
|
## What's new in 3.0.1
|
|
1155
1172
|
|
|
1156
1173
|
- **`people`, `places` and `key_subjects` of search results can be read with `.name`.** The API sends them as lists of names (`["Sam Altman"]`), while the types promised objects, so `result.people[0].name` was `undefined`. `VideoSearchResult` and `FileSearchResult` now turn each name into `{ name }`, as the Python SDK does.
|
package/dist/errors.d.ts
CHANGED
|
@@ -44,13 +44,14 @@ export declare class NotFoundError extends VidNavigatorError {
|
|
|
44
44
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
|
45
45
|
}
|
|
46
46
|
/**
|
|
47
|
-
* Raised
|
|
47
|
+
* Raised on HTTP 429: too many requests (`rate_limit_exceeded`). Wait `Retry-After` seconds.
|
|
48
48
|
*/
|
|
49
49
|
export declare class RateLimitExceededError extends VidNavigatorError {
|
|
50
50
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
|
51
51
|
}
|
|
52
52
|
/**
|
|
53
|
-
* Raised
|
|
53
|
+
* Raised on HTTP 402. Catch it for any 402, or one of its subclasses to know which:
|
|
54
|
+
* `InsufficientCreditsError` (not enough credits) or `StorageQuotaExceededError` (the storage of the plan is full).
|
|
54
55
|
*/
|
|
55
56
|
export declare class PaymentRequiredError extends VidNavigatorError {
|
|
56
57
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
|
@@ -62,9 +63,11 @@ export declare class ServerError extends VidNavigatorError {
|
|
|
62
63
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
|
63
64
|
}
|
|
64
65
|
/**
|
|
65
|
-
* Raised when storage
|
|
66
|
+
* Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
|
|
67
|
+
* on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
|
|
68
|
+
* code that catches that one keeps working.
|
|
66
69
|
*/
|
|
67
|
-
export declare class StorageQuotaExceededError extends
|
|
70
|
+
export declare class StorageQuotaExceededError extends PaymentRequiredError {
|
|
68
71
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
|
69
72
|
}
|
|
70
73
|
/**
|
|
@@ -81,9 +84,9 @@ export declare class SystemOverloadError extends VidNavigatorError {
|
|
|
81
84
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any, retry_after_seconds?: number);
|
|
82
85
|
}
|
|
83
86
|
/**
|
|
84
|
-
* Raised when
|
|
85
|
-
* (
|
|
86
|
-
*
|
|
87
|
+
* Raised when the account does not have enough credits: HTTP 402 `insufficient_credits`.
|
|
88
|
+
* Thrown at job submit time (no task is created; e.g. less than 60 seconds of transcription
|
|
89
|
+
* credit left) and by `result()` when a job runs out of credits. Extends `PaymentRequiredError`.
|
|
87
90
|
*/
|
|
88
91
|
export declare class InsufficientCreditsError extends PaymentRequiredError {
|
|
89
92
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any);
|
package/dist/errors.js
CHANGED
|
@@ -62,7 +62,7 @@ class NotFoundError extends VidNavigatorError {
|
|
|
62
62
|
}
|
|
63
63
|
exports.NotFoundError = NotFoundError;
|
|
64
64
|
/**
|
|
65
|
-
* Raised
|
|
65
|
+
* Raised on HTTP 429: too many requests (`rate_limit_exceeded`). Wait `Retry-After` seconds.
|
|
66
66
|
*/
|
|
67
67
|
class RateLimitExceededError extends VidNavigatorError {
|
|
68
68
|
constructor(message, status_code, error_code, error_message, details) {
|
|
@@ -73,7 +73,8 @@ class RateLimitExceededError extends VidNavigatorError {
|
|
|
73
73
|
}
|
|
74
74
|
exports.RateLimitExceededError = RateLimitExceededError;
|
|
75
75
|
/**
|
|
76
|
-
* Raised
|
|
76
|
+
* Raised on HTTP 402. Catch it for any 402, or one of its subclasses to know which:
|
|
77
|
+
* `InsufficientCreditsError` (not enough credits) or `StorageQuotaExceededError` (the storage of the plan is full).
|
|
77
78
|
*/
|
|
78
79
|
class PaymentRequiredError extends VidNavigatorError {
|
|
79
80
|
constructor(message, status_code, error_code, error_message, details) {
|
|
@@ -95,9 +96,11 @@ class ServerError extends VidNavigatorError {
|
|
|
95
96
|
}
|
|
96
97
|
exports.ServerError = ServerError;
|
|
97
98
|
/**
|
|
98
|
-
* Raised when storage
|
|
99
|
+
* Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
|
|
100
|
+
* on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
|
|
101
|
+
* code that catches that one keeps working.
|
|
99
102
|
*/
|
|
100
|
-
class StorageQuotaExceededError extends
|
|
103
|
+
class StorageQuotaExceededError extends PaymentRequiredError {
|
|
101
104
|
constructor(message, status_code, error_code, error_message, details) {
|
|
102
105
|
super(message, status_code, error_code, error_message, details);
|
|
103
106
|
this.name = 'StorageQuotaExceededError';
|
|
@@ -129,9 +132,9 @@ class SystemOverloadError extends VidNavigatorError {
|
|
|
129
132
|
}
|
|
130
133
|
exports.SystemOverloadError = SystemOverloadError;
|
|
131
134
|
/**
|
|
132
|
-
* Raised when
|
|
133
|
-
* (
|
|
134
|
-
*
|
|
135
|
+
* Raised when the account does not have enough credits: HTTP 402 `insufficient_credits`.
|
|
136
|
+
* Thrown at job submit time (no task is created; e.g. less than 60 seconds of transcription
|
|
137
|
+
* credit left) and by `result()` when a job runs out of credits. Extends `PaymentRequiredError`.
|
|
135
138
|
*/
|
|
136
139
|
class InsufficientCreditsError extends PaymentRequiredError {
|
|
137
140
|
constructor(message, status_code, error_code, error_message, details) {
|
package/dist/http.js
CHANGED
|
@@ -6,6 +6,8 @@ exports.buildApiError = buildApiError;
|
|
|
6
6
|
* Internal: maps API error responses to SDK error classes. Not re-exported from the package.
|
|
7
7
|
*/
|
|
8
8
|
const errors_1 = require("./errors");
|
|
9
|
+
/** The codes of a 402 for "not enough credits"; `limit_exceeded` is the API's code for it before November 2026. */
|
|
10
|
+
const INSUFFICIENT_CREDITS_CODES = new Set(['insufficient_credits', 'insufficient_credits_video_search', 'limit_exceeded']);
|
|
9
11
|
function parseApiErrorPayload(data) {
|
|
10
12
|
const errorField = data?.error;
|
|
11
13
|
const errorCode = (typeof errorField === 'string' ? errorField : errorField?.code) ?? data?.error_code;
|
|
@@ -23,7 +25,10 @@ function buildApiError(status, data, fallbackMessage) {
|
|
|
23
25
|
case 401:
|
|
24
26
|
return new errors_1.AuthenticationError(message, status, errorCode, errorMessage, details);
|
|
25
27
|
case 402:
|
|
26
|
-
if (errorCode === '
|
|
28
|
+
if (errorCode === 'storage_quota_exceeded') {
|
|
29
|
+
return new errors_1.StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
|
|
30
|
+
}
|
|
31
|
+
if (errorCode && INSUFFICIENT_CREDITS_CODES.has(errorCode)) {
|
|
27
32
|
return new errors_1.InsufficientCreditsError(message, status, errorCode, errorMessage, details);
|
|
28
33
|
}
|
|
29
34
|
return new errors_1.PaymentRequiredError(message, status, errorCode, errorMessage, details);
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export * from './webhooks';
|
|
|
7
7
|
export { Job } from './jobs';
|
|
8
8
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
9
9
|
/** SDK version (keep in sync with package.json) */
|
|
10
|
-
export declare const SDK_VERSION = "3.0
|
|
10
|
+
export declare const SDK_VERSION = "3.1.0";
|
|
11
11
|
export interface SDKConfig {
|
|
12
12
|
apiKey: string;
|
|
13
13
|
baseURL?: string;
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ __exportStar(require("./webhooks"), exports);
|
|
|
31
31
|
var jobs_2 = require("./jobs");
|
|
32
32
|
Object.defineProperty(exports, "Job", { enumerable: true, get: function () { return jobs_2.Job; } });
|
|
33
33
|
/** SDK version (keep in sync with package.json) */
|
|
34
|
-
exports.SDK_VERSION = '3.0
|
|
34
|
+
exports.SDK_VERSION = '3.1.0';
|
|
35
35
|
/**
|
|
36
36
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
|
37
37
|
* minutes at worst. A shorter configured axios timeout is raised to this for that call only.
|
package/dist/models/TikTok.d.ts
CHANGED
|
@@ -563,7 +563,8 @@ export interface TikTokLiveSearchStats {
|
|
|
563
563
|
pages_fetched?: number;
|
|
564
564
|
/**
|
|
565
565
|
* Distinct rooms TikTok returned, including any past `max_results`. For information:
|
|
566
|
-
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
|
|
566
|
+
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
|
|
567
|
+
* and `pages_fetched` (at least 1 per 5).
|
|
567
568
|
*/
|
|
568
569
|
rooms_fetched?: number;
|
|
569
570
|
results_count?: number;
|
package/dist/models/Usage.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ export declare class UsageCharge {
|
|
|
28
28
|
export interface UsageBlockJSON {
|
|
29
29
|
charges?: UsageChargeJSON[];
|
|
30
30
|
total_credits?: number;
|
|
31
|
+
/** Credits left on the account (monthly + purchased) after this request's charges. Absent on plans without a credit limit. */
|
|
31
32
|
credits_remaining_after?: number;
|
|
32
33
|
waived?: {
|
|
33
34
|
credits_saved: number;
|
|
@@ -48,6 +49,10 @@ export interface UsageBlockJSON {
|
|
|
48
49
|
export declare class UsageBlock {
|
|
49
50
|
charges: UsageCharge[];
|
|
50
51
|
total_credits?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Credits left on the account (monthly + purchased) after this request's charges.
|
|
54
|
+
* `undefined` on plans without a credit limit, where the API leaves it out.
|
|
55
|
+
*/
|
|
51
56
|
credits_remaining_after?: number;
|
|
52
57
|
waived?: {
|
|
53
58
|
credits_saved: number;
|
|
@@ -128,13 +133,14 @@ export declare class StorageUsage {
|
|
|
128
133
|
}
|
|
129
134
|
export type PlanInterval = 'month' | 'year';
|
|
130
135
|
export interface UsageDataJSON {
|
|
136
|
+
/** `start` and `end` are null when the account has no subscription period. */
|
|
131
137
|
usage_period: {
|
|
132
|
-
start: string;
|
|
133
|
-
end: string;
|
|
138
|
+
start: string | null;
|
|
139
|
+
end: string | null;
|
|
134
140
|
};
|
|
135
141
|
billing_period: {
|
|
136
|
-
start: string;
|
|
137
|
-
end: string;
|
|
142
|
+
start: string | null;
|
|
143
|
+
end: string | null;
|
|
138
144
|
interval: PlanInterval;
|
|
139
145
|
};
|
|
140
146
|
subscription: {
|
|
@@ -150,12 +156,22 @@ export interface UsageDataJSON {
|
|
|
150
156
|
residential_request?: ActivityCountJSON;
|
|
151
157
|
search_request?: ActivityCountJSON;
|
|
152
158
|
analysis_request?: ActivityCountJSON;
|
|
159
|
+
/** Hours of video whose scenes were analyzed (`unit: 'hours'`). */
|
|
160
|
+
scene_analysis_hour?: ActivityCountJSON;
|
|
153
161
|
transcription_hour?: ActivityCountJSON;
|
|
162
|
+
/** Frames analyzed by `watch` and by `include_scenes` (`unit: 'frames'`). */
|
|
163
|
+
frame_analysis?: ActivityCountJSON;
|
|
164
|
+
/** @deprecated Legacy counters below: the API no longer sends them. */
|
|
154
165
|
video_scene_analyses?: ActivityCountJSON;
|
|
166
|
+
/** @deprecated */
|
|
155
167
|
video_transcripts?: ActivityCountJSON;
|
|
168
|
+
/** @deprecated */
|
|
156
169
|
youtube_transcripts?: ActivityCountJSON;
|
|
170
|
+
/** @deprecated */
|
|
157
171
|
video_searches?: ActivityCountJSON;
|
|
172
|
+
/** @deprecated */
|
|
158
173
|
video_analyses?: ActivityCountJSON;
|
|
174
|
+
/** @deprecated */
|
|
159
175
|
video_uploads?: ActivityCountJSON;
|
|
160
176
|
};
|
|
161
177
|
channels_indexed: CapacityMetricJSON;
|
|
@@ -163,13 +179,15 @@ export interface UsageDataJSON {
|
|
|
163
179
|
generated_at: string;
|
|
164
180
|
}
|
|
165
181
|
export declare class UsageData {
|
|
182
|
+
/** `start` and `end` are `undefined` when the account has no subscription period. */
|
|
166
183
|
usagePeriod: {
|
|
167
|
-
start: Date;
|
|
168
|
-
end: Date;
|
|
184
|
+
start: Date | undefined;
|
|
185
|
+
end: Date | undefined;
|
|
169
186
|
};
|
|
187
|
+
/** `start` and `end` are `undefined` when the account has no subscription period. */
|
|
170
188
|
billingPeriod: {
|
|
171
|
-
start: Date;
|
|
172
|
-
end: Date;
|
|
189
|
+
start: Date | undefined;
|
|
190
|
+
end: Date | undefined;
|
|
173
191
|
interval: PlanInterval;
|
|
174
192
|
};
|
|
175
193
|
subscription: {
|
|
@@ -185,12 +203,22 @@ export declare class UsageData {
|
|
|
185
203
|
residentialRequest?: ActivityCount;
|
|
186
204
|
searchRequest?: ActivityCount;
|
|
187
205
|
analysisRequest?: ActivityCount;
|
|
206
|
+
/** Hours of video whose scenes were analyzed. */
|
|
207
|
+
sceneAnalysisHour?: ActivityCount;
|
|
188
208
|
transcriptionHour?: ActivityCount;
|
|
209
|
+
/** Frames analyzed by `watch` and by `include_scenes`. */
|
|
210
|
+
frameAnalysis?: ActivityCount;
|
|
211
|
+
/** @deprecated Legacy counters below: the API no longer sends them, so they stay undefined. */
|
|
189
212
|
videoSceneAnalyses?: ActivityCount;
|
|
213
|
+
/** @deprecated */
|
|
190
214
|
videoTranscripts?: ActivityCount;
|
|
215
|
+
/** @deprecated */
|
|
191
216
|
youtubeTranscripts?: ActivityCount;
|
|
217
|
+
/** @deprecated */
|
|
192
218
|
videoSearches?: ActivityCount;
|
|
219
|
+
/** @deprecated */
|
|
193
220
|
videoAnalyses?: ActivityCount;
|
|
221
|
+
/** @deprecated */
|
|
194
222
|
videoUploads?: ActivityCount;
|
|
195
223
|
};
|
|
196
224
|
channelsIndexed: CapacityMetric;
|
package/dist/models/Usage.js
CHANGED
|
@@ -118,16 +118,20 @@ class StorageUsage {
|
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
120
|
exports.StorageUsage = StorageUsage;
|
|
121
|
+
/** A date of the API, or `undefined` when it sent null (never `new Date(null)`, which is 1970). */
|
|
122
|
+
function optionalDate(value) {
|
|
123
|
+
return value ? new Date(value) : undefined;
|
|
124
|
+
}
|
|
121
125
|
class UsageData {
|
|
122
126
|
constructor(data) {
|
|
123
127
|
this.usagePeriod = {
|
|
124
|
-
start:
|
|
125
|
-
end:
|
|
128
|
+
start: optionalDate(data.usage_period?.start),
|
|
129
|
+
end: optionalDate(data.usage_period?.end),
|
|
126
130
|
};
|
|
127
131
|
this.billingPeriod = {
|
|
128
|
-
start:
|
|
129
|
-
end:
|
|
130
|
-
interval: data.billing_period
|
|
132
|
+
start: optionalDate(data.billing_period?.start),
|
|
133
|
+
end: optionalDate(data.billing_period?.end),
|
|
134
|
+
interval: data.billing_period?.interval,
|
|
131
135
|
};
|
|
132
136
|
this.subscription = {
|
|
133
137
|
planId: data.subscription.plan_id,
|
|
@@ -142,7 +146,9 @@ class UsageData {
|
|
|
142
146
|
residentialRequest: data.usage.residential_request ? ActivityCount.fromJSON(data.usage.residential_request) : undefined,
|
|
143
147
|
searchRequest: data.usage.search_request ? ActivityCount.fromJSON(data.usage.search_request) : undefined,
|
|
144
148
|
analysisRequest: data.usage.analysis_request ? ActivityCount.fromJSON(data.usage.analysis_request) : undefined,
|
|
149
|
+
sceneAnalysisHour: data.usage.scene_analysis_hour ? ActivityCount.fromJSON(data.usage.scene_analysis_hour) : undefined,
|
|
145
150
|
transcriptionHour: data.usage.transcription_hour ? ActivityCount.fromJSON(data.usage.transcription_hour) : undefined,
|
|
151
|
+
frameAnalysis: data.usage.frame_analysis ? ActivityCount.fromJSON(data.usage.frame_analysis) : undefined,
|
|
146
152
|
videoSceneAnalyses: data.usage.video_scene_analyses ? ActivityCount.fromJSON(data.usage.video_scene_analyses) : undefined,
|
|
147
153
|
videoTranscripts: data.usage.video_transcripts ? ActivityCount.fromJSON(data.usage.video_transcripts) : undefined,
|
|
148
154
|
youtubeTranscripts: data.usage.youtube_transcripts ? ActivityCount.fromJSON(data.usage.youtube_transcripts) : undefined,
|
package/package.json
CHANGED
package/src/errors.ts
CHANGED
|
@@ -81,7 +81,7 @@ export class NotFoundError extends VidNavigatorError {
|
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
/**
|
|
84
|
-
* Raised
|
|
84
|
+
* Raised on HTTP 429: too many requests (`rate_limit_exceeded`). Wait `Retry-After` seconds.
|
|
85
85
|
*/
|
|
86
86
|
export class RateLimitExceededError extends VidNavigatorError {
|
|
87
87
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any) {
|
|
@@ -92,7 +92,8 @@ export class RateLimitExceededError extends VidNavigatorError {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
* Raised
|
|
95
|
+
* Raised on HTTP 402. Catch it for any 402, or one of its subclasses to know which:
|
|
96
|
+
* `InsufficientCreditsError` (not enough credits) or `StorageQuotaExceededError` (the storage of the plan is full).
|
|
96
97
|
*/
|
|
97
98
|
export class PaymentRequiredError extends VidNavigatorError {
|
|
98
99
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any) {
|
|
@@ -114,9 +115,11 @@ export class ServerError extends VidNavigatorError {
|
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
/**
|
|
117
|
-
* Raised when storage
|
|
118
|
+
* Raised when the storage of the plan is full: HTTP 402 `storage_quota_exceeded`
|
|
119
|
+
* on `uploadFile` (413 is still mapped here too). A `PaymentRequiredError`, so
|
|
120
|
+
* code that catches that one keeps working.
|
|
118
121
|
*/
|
|
119
|
-
export class StorageQuotaExceededError extends
|
|
122
|
+
export class StorageQuotaExceededError extends PaymentRequiredError {
|
|
120
123
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any) {
|
|
121
124
|
super(message, status_code, error_code, error_message, details);
|
|
122
125
|
this.name = 'StorageQuotaExceededError';
|
|
@@ -157,9 +160,9 @@ export class SystemOverloadError extends VidNavigatorError {
|
|
|
157
160
|
}
|
|
158
161
|
|
|
159
162
|
/**
|
|
160
|
-
* Raised when
|
|
161
|
-
* (
|
|
162
|
-
*
|
|
163
|
+
* Raised when the account does not have enough credits: HTTP 402 `insufficient_credits`.
|
|
164
|
+
* Thrown at job submit time (no task is created; e.g. less than 60 seconds of transcription
|
|
165
|
+
* credit left) and by `result()` when a job runs out of credits. Extends `PaymentRequiredError`.
|
|
163
166
|
*/
|
|
164
167
|
export class InsufficientCreditsError extends PaymentRequiredError {
|
|
165
168
|
constructor(message: string, status_code?: number, error_code?: string, error_message?: string, details?: any) {
|
package/src/http.ts
CHANGED
|
@@ -18,6 +18,9 @@ import {
|
|
|
18
18
|
ScenesNotAvailableError,
|
|
19
19
|
} from './errors';
|
|
20
20
|
|
|
21
|
+
/** The codes of a 402 for "not enough credits"; `limit_exceeded` is the API's code for it before November 2026. */
|
|
22
|
+
const INSUFFICIENT_CREDITS_CODES = new Set(['insufficient_credits', 'insufficient_credits_video_search', 'limit_exceeded']);
|
|
23
|
+
|
|
21
24
|
export function parseApiErrorPayload(data: any): {
|
|
22
25
|
errorCode?: string;
|
|
23
26
|
errorMessage?: string;
|
|
@@ -43,7 +46,10 @@ export function buildApiError(status: number, data: any, fallbackMessage?: strin
|
|
|
43
46
|
case 401:
|
|
44
47
|
return new AuthenticationError(message, status, errorCode, errorMessage, details);
|
|
45
48
|
case 402:
|
|
46
|
-
if (errorCode === '
|
|
49
|
+
if (errorCode === 'storage_quota_exceeded') {
|
|
50
|
+
return new StorageQuotaExceededError(message, status, errorCode, errorMessage, details);
|
|
51
|
+
}
|
|
52
|
+
if (errorCode && INSUFFICIENT_CREDITS_CODES.has(errorCode)) {
|
|
47
53
|
return new InsufficientCreditsError(message, status, errorCode, errorMessage, details);
|
|
48
54
|
}
|
|
49
55
|
return new PaymentRequiredError(message, status, errorCode, errorMessage, details);
|
package/src/index.ts
CHANGED
|
@@ -71,7 +71,7 @@ export { Job } from './jobs';
|
|
|
71
71
|
export type { TaskStatus, PollableTask, PollOptions, JobOperation, SubmitOptions, RunOptions, JobInfo } from './jobs';
|
|
72
72
|
|
|
73
73
|
/** SDK version (keep in sync with package.json) */
|
|
74
|
-
export const SDK_VERSION = '3.0
|
|
74
|
+
export const SDK_VERSION = '3.1.0';
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* A LIVE room usually answers in 1-5 s, up to ~30 s when the API has to open a TikTok page, and two
|
package/src/models/TikTok.ts
CHANGED
|
@@ -923,7 +923,8 @@ export interface TikTokLiveSearchStats {
|
|
|
923
923
|
pages_fetched?: number;
|
|
924
924
|
/**
|
|
925
925
|
* Distinct rooms TikTok returned, including any past `max_results`. For information:
|
|
926
|
-
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
|
|
926
|
+
* billing follows `results_count` (1 `residential_request` per 30, minimum 1 per search)
|
|
927
|
+
* and `pages_fetched` (at least 1 per 5).
|
|
927
928
|
*/
|
|
928
929
|
rooms_fetched?: number;
|
|
929
930
|
results_count?: number;
|
package/src/models/Usage.ts
CHANGED
|
@@ -51,6 +51,7 @@ export class UsageCharge {
|
|
|
51
51
|
export interface UsageBlockJSON {
|
|
52
52
|
charges?: UsageChargeJSON[];
|
|
53
53
|
total_credits?: number;
|
|
54
|
+
/** Credits left on the account (monthly + purchased) after this request's charges. Absent on plans without a credit limit. */
|
|
54
55
|
credits_remaining_after?: number;
|
|
55
56
|
waived?: { credits_saved: number };
|
|
56
57
|
/** Legacy flat token fields. Some /extract/* responses may still echo these. */
|
|
@@ -70,6 +71,10 @@ export interface UsageBlockJSON {
|
|
|
70
71
|
export class UsageBlock {
|
|
71
72
|
charges: UsageCharge[];
|
|
72
73
|
total_credits?: number;
|
|
74
|
+
/**
|
|
75
|
+
* Credits left on the account (monthly + purchased) after this request's charges.
|
|
76
|
+
* `undefined` on plans without a credit limit, where the API leaves it out.
|
|
77
|
+
*/
|
|
73
78
|
credits_remaining_after?: number;
|
|
74
79
|
waived?: { credits_saved: number };
|
|
75
80
|
/** Legacy flat token fields, only present on some /extract/* responses. */
|
|
@@ -231,13 +236,14 @@ export class StorageUsage {
|
|
|
231
236
|
export type PlanInterval = 'month' | 'year';
|
|
232
237
|
|
|
233
238
|
export interface UsageDataJSON {
|
|
239
|
+
/** `start` and `end` are null when the account has no subscription period. */
|
|
234
240
|
usage_period: {
|
|
235
|
-
start: string;
|
|
236
|
-
end: string;
|
|
241
|
+
start: string | null;
|
|
242
|
+
end: string | null;
|
|
237
243
|
};
|
|
238
244
|
billing_period: {
|
|
239
|
-
start: string;
|
|
240
|
-
end: string;
|
|
245
|
+
start: string | null;
|
|
246
|
+
end: string | null;
|
|
241
247
|
interval: PlanInterval;
|
|
242
248
|
};
|
|
243
249
|
subscription: {
|
|
@@ -253,12 +259,22 @@ export interface UsageDataJSON {
|
|
|
253
259
|
residential_request?: ActivityCountJSON;
|
|
254
260
|
search_request?: ActivityCountJSON;
|
|
255
261
|
analysis_request?: ActivityCountJSON;
|
|
262
|
+
/** Hours of video whose scenes were analyzed (`unit: 'hours'`). */
|
|
263
|
+
scene_analysis_hour?: ActivityCountJSON;
|
|
256
264
|
transcription_hour?: ActivityCountJSON;
|
|
265
|
+
/** Frames analyzed by `watch` and by `include_scenes` (`unit: 'frames'`). */
|
|
266
|
+
frame_analysis?: ActivityCountJSON;
|
|
267
|
+
/** @deprecated Legacy counters below: the API no longer sends them. */
|
|
257
268
|
video_scene_analyses?: ActivityCountJSON;
|
|
269
|
+
/** @deprecated */
|
|
258
270
|
video_transcripts?: ActivityCountJSON;
|
|
271
|
+
/** @deprecated */
|
|
259
272
|
youtube_transcripts?: ActivityCountJSON;
|
|
273
|
+
/** @deprecated */
|
|
260
274
|
video_searches?: ActivityCountJSON;
|
|
275
|
+
/** @deprecated */
|
|
261
276
|
video_analyses?: ActivityCountJSON;
|
|
277
|
+
/** @deprecated */
|
|
262
278
|
video_uploads?: ActivityCountJSON;
|
|
263
279
|
};
|
|
264
280
|
channels_indexed: CapacityMetricJSON;
|
|
@@ -266,14 +282,21 @@ export interface UsageDataJSON {
|
|
|
266
282
|
generated_at: string;
|
|
267
283
|
}
|
|
268
284
|
|
|
285
|
+
/** A date of the API, or `undefined` when it sent null (never `new Date(null)`, which is 1970). */
|
|
286
|
+
function optionalDate(value: string | null | undefined): Date | undefined {
|
|
287
|
+
return value ? new Date(value) : undefined;
|
|
288
|
+
}
|
|
289
|
+
|
|
269
290
|
export class UsageData {
|
|
291
|
+
/** `start` and `end` are `undefined` when the account has no subscription period. */
|
|
270
292
|
public usagePeriod: {
|
|
271
|
-
start: Date;
|
|
272
|
-
end: Date;
|
|
293
|
+
start: Date | undefined;
|
|
294
|
+
end: Date | undefined;
|
|
273
295
|
};
|
|
296
|
+
/** `start` and `end` are `undefined` when the account has no subscription period. */
|
|
274
297
|
public billingPeriod: {
|
|
275
|
-
start: Date;
|
|
276
|
-
end: Date;
|
|
298
|
+
start: Date | undefined;
|
|
299
|
+
end: Date | undefined;
|
|
277
300
|
interval: PlanInterval;
|
|
278
301
|
};
|
|
279
302
|
public subscription: {
|
|
@@ -289,12 +312,22 @@ export class UsageData {
|
|
|
289
312
|
residentialRequest?: ActivityCount;
|
|
290
313
|
searchRequest?: ActivityCount;
|
|
291
314
|
analysisRequest?: ActivityCount;
|
|
315
|
+
/** Hours of video whose scenes were analyzed. */
|
|
316
|
+
sceneAnalysisHour?: ActivityCount;
|
|
292
317
|
transcriptionHour?: ActivityCount;
|
|
318
|
+
/** Frames analyzed by `watch` and by `include_scenes`. */
|
|
319
|
+
frameAnalysis?: ActivityCount;
|
|
320
|
+
/** @deprecated Legacy counters below: the API no longer sends them, so they stay undefined. */
|
|
293
321
|
videoSceneAnalyses?: ActivityCount;
|
|
322
|
+
/** @deprecated */
|
|
294
323
|
videoTranscripts?: ActivityCount;
|
|
324
|
+
/** @deprecated */
|
|
295
325
|
youtubeTranscripts?: ActivityCount;
|
|
326
|
+
/** @deprecated */
|
|
296
327
|
videoSearches?: ActivityCount;
|
|
328
|
+
/** @deprecated */
|
|
297
329
|
videoAnalyses?: ActivityCount;
|
|
330
|
+
/** @deprecated */
|
|
298
331
|
videoUploads?: ActivityCount;
|
|
299
332
|
};
|
|
300
333
|
public channelsIndexed: CapacityMetric;
|
|
@@ -303,13 +336,13 @@ export class UsageData {
|
|
|
303
336
|
|
|
304
337
|
constructor(data: UsageDataJSON) {
|
|
305
338
|
this.usagePeriod = {
|
|
306
|
-
start:
|
|
307
|
-
end:
|
|
339
|
+
start: optionalDate(data.usage_period?.start),
|
|
340
|
+
end: optionalDate(data.usage_period?.end),
|
|
308
341
|
};
|
|
309
342
|
this.billingPeriod = {
|
|
310
|
-
start:
|
|
311
|
-
end:
|
|
312
|
-
interval: data.billing_period
|
|
343
|
+
start: optionalDate(data.billing_period?.start),
|
|
344
|
+
end: optionalDate(data.billing_period?.end),
|
|
345
|
+
interval: data.billing_period?.interval,
|
|
313
346
|
};
|
|
314
347
|
this.subscription = {
|
|
315
348
|
planId: data.subscription.plan_id,
|
|
@@ -324,7 +357,9 @@ export class UsageData {
|
|
|
324
357
|
residentialRequest: data.usage.residential_request ? ActivityCount.fromJSON(data.usage.residential_request) : undefined,
|
|
325
358
|
searchRequest: data.usage.search_request ? ActivityCount.fromJSON(data.usage.search_request) : undefined,
|
|
326
359
|
analysisRequest: data.usage.analysis_request ? ActivityCount.fromJSON(data.usage.analysis_request) : undefined,
|
|
360
|
+
sceneAnalysisHour: data.usage.scene_analysis_hour ? ActivityCount.fromJSON(data.usage.scene_analysis_hour) : undefined,
|
|
327
361
|
transcriptionHour: data.usage.transcription_hour ? ActivityCount.fromJSON(data.usage.transcription_hour) : undefined,
|
|
362
|
+
frameAnalysis: data.usage.frame_analysis ? ActivityCount.fromJSON(data.usage.frame_analysis) : undefined,
|
|
328
363
|
videoSceneAnalyses: data.usage.video_scene_analyses ? ActivityCount.fromJSON(data.usage.video_scene_analyses) : undefined,
|
|
329
364
|
videoTranscripts: data.usage.video_transcripts ? ActivityCount.fromJSON(data.usage.video_transcripts) : undefined,
|
|
330
365
|
youtubeTranscripts: data.usage.youtube_transcripts ? ActivityCount.fromJSON(data.usage.youtube_transcripts) : undefined,
|