firecrawl 4.1.0 → 4.3.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/dist/{chunk-EX7LNARR.js → chunk-KCQFB5LN.js} +1 -1
- package/dist/index.cjs +175 -3
- package/dist/index.d.cts +115 -2
- package/dist/index.d.ts +115 -2
- package/dist/index.js +176 -4
- package/dist/{package-MVCQF4ZJ.js → package-QFGMHRQZ.js} +1 -1
- package/package.json +1 -1
- package/src/__tests__/e2e/v2/usage.test.ts +8 -0
- package/src/v1/index.ts +182 -1
- package/src/v2/client.ts +16 -1
- package/src/v2/methods/usage.ts +50 -5
- package/src/v2/types.ts +38 -0
|
@@ -8,7 +8,7 @@ var require_package = __commonJS({
|
|
|
8
8
|
"package.json"(exports, module) {
|
|
9
9
|
module.exports = {
|
|
10
10
|
name: "@mendable/firecrawl-js",
|
|
11
|
-
version: "4.
|
|
11
|
+
version: "4.3.0",
|
|
12
12
|
description: "JavaScript SDK for Firecrawl API",
|
|
13
13
|
main: "dist/index.js",
|
|
14
14
|
types: "dist/index.d.ts",
|
package/dist/index.cjs
CHANGED
|
@@ -35,7 +35,7 @@ var require_package = __commonJS({
|
|
|
35
35
|
"package.json"(exports2, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "@mendable/firecrawl-js",
|
|
38
|
-
version: "4.
|
|
38
|
+
version: "4.3.0",
|
|
39
39
|
description: "JavaScript SDK for Firecrawl API",
|
|
40
40
|
main: "dist/index.js",
|
|
41
41
|
types: "dist/index.d.ts",
|
|
@@ -740,7 +740,12 @@ async function getCreditUsage(http) {
|
|
|
740
740
|
const res = await http.get("/v2/team/credit-usage");
|
|
741
741
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage");
|
|
742
742
|
const d = res.data.data || res.data;
|
|
743
|
-
return {
|
|
743
|
+
return {
|
|
744
|
+
remainingCredits: d.remainingCredits ?? d.remaining_credits ?? 0,
|
|
745
|
+
planCredits: d.planCredits ?? d.plan_credits,
|
|
746
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
747
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null
|
|
748
|
+
};
|
|
744
749
|
} catch (err) {
|
|
745
750
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage");
|
|
746
751
|
throw err;
|
|
@@ -750,12 +755,50 @@ async function getTokenUsage(http) {
|
|
|
750
755
|
try {
|
|
751
756
|
const res = await http.get("/v2/team/token-usage");
|
|
752
757
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage");
|
|
753
|
-
|
|
758
|
+
const d = res.data.data || res.data;
|
|
759
|
+
return {
|
|
760
|
+
remainingTokens: d.remainingTokens ?? d.remaining_tokens ?? 0,
|
|
761
|
+
planTokens: d.planTokens ?? d.plan_tokens,
|
|
762
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
763
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null
|
|
764
|
+
};
|
|
754
765
|
} catch (err) {
|
|
755
766
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage");
|
|
756
767
|
throw err;
|
|
757
768
|
}
|
|
758
769
|
}
|
|
770
|
+
async function getQueueStatus(http) {
|
|
771
|
+
try {
|
|
772
|
+
const res = await http.get("/v2/team/queue-status");
|
|
773
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
774
|
+
return res.data;
|
|
775
|
+
} catch (err) {
|
|
776
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
777
|
+
throw err;
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
async function getCreditUsageHistorical(http, byApiKey) {
|
|
781
|
+
try {
|
|
782
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
783
|
+
const res = await http.get(`/v2/team/credit-usage/historical${query}`);
|
|
784
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage historical");
|
|
785
|
+
return res.data;
|
|
786
|
+
} catch (err) {
|
|
787
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage historical");
|
|
788
|
+
throw err;
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
async function getTokenUsageHistorical(http, byApiKey) {
|
|
792
|
+
try {
|
|
793
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
794
|
+
const res = await http.get(`/v2/team/token-usage/historical${query}`);
|
|
795
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage historical");
|
|
796
|
+
return res.data;
|
|
797
|
+
} catch (err) {
|
|
798
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage historical");
|
|
799
|
+
throw err;
|
|
800
|
+
}
|
|
801
|
+
}
|
|
759
802
|
|
|
760
803
|
// src/v2/watcher.ts
|
|
761
804
|
var import_events = require("events");
|
|
@@ -1063,6 +1106,18 @@ var FirecrawlClient = class {
|
|
|
1063
1106
|
async getTokenUsage() {
|
|
1064
1107
|
return getTokenUsage(this.http);
|
|
1065
1108
|
}
|
|
1109
|
+
/** Historical credit usage by month; set byApiKey to true to break down by API key. */
|
|
1110
|
+
async getCreditUsageHistorical(byApiKey) {
|
|
1111
|
+
return getCreditUsageHistorical(this.http, byApiKey);
|
|
1112
|
+
}
|
|
1113
|
+
/** Historical token usage by month; set byApiKey to true to break down by API key. */
|
|
1114
|
+
async getTokenUsageHistorical(byApiKey) {
|
|
1115
|
+
return getTokenUsageHistorical(this.http, byApiKey);
|
|
1116
|
+
}
|
|
1117
|
+
/** Metrics about the team's scrape queue. */
|
|
1118
|
+
async getQueueStatus() {
|
|
1119
|
+
return getQueueStatus(this.http);
|
|
1120
|
+
}
|
|
1066
1121
|
// Watcher
|
|
1067
1122
|
/**
|
|
1068
1123
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
@@ -2309,6 +2364,123 @@ var FirecrawlApp = class {
|
|
|
2309
2364
|
}
|
|
2310
2365
|
return { success: false, error: "Internal server error." };
|
|
2311
2366
|
}
|
|
2367
|
+
/**
|
|
2368
|
+
* Gets metrics about the team's scrape queue.
|
|
2369
|
+
* @returns The current queue status.
|
|
2370
|
+
*/
|
|
2371
|
+
async getQueueStatus() {
|
|
2372
|
+
const headers = this.prepareHeaders();
|
|
2373
|
+
try {
|
|
2374
|
+
const response = await this.getRequest(
|
|
2375
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2376
|
+
headers
|
|
2377
|
+
);
|
|
2378
|
+
if (response.status === 200) {
|
|
2379
|
+
return response.data;
|
|
2380
|
+
} else {
|
|
2381
|
+
this.handleError(response, "get queue status");
|
|
2382
|
+
}
|
|
2383
|
+
} catch (error) {
|
|
2384
|
+
if (error.response?.data?.error) {
|
|
2385
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2386
|
+
} else {
|
|
2387
|
+
throw new FirecrawlError(error.message, 500);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
return { success: false, error: "Internal server error." };
|
|
2391
|
+
}
|
|
2392
|
+
/**
|
|
2393
|
+
* Gets current credit usage and billing period for the team (v1).
|
|
2394
|
+
*/
|
|
2395
|
+
async getCreditUsage() {
|
|
2396
|
+
const headers = this.prepareHeaders();
|
|
2397
|
+
try {
|
|
2398
|
+
const response = await this.getRequest(
|
|
2399
|
+
`${this.apiUrl}/v1/team/credit-usage`,
|
|
2400
|
+
headers
|
|
2401
|
+
);
|
|
2402
|
+
if (response.status === 200) {
|
|
2403
|
+
return response.data;
|
|
2404
|
+
} else {
|
|
2405
|
+
this.handleError(response, "get credit usage");
|
|
2406
|
+
}
|
|
2407
|
+
} catch (error) {
|
|
2408
|
+
if (error.response?.data?.error) {
|
|
2409
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2410
|
+
} else {
|
|
2411
|
+
throw new FirecrawlError(error.message, 500);
|
|
2412
|
+
}
|
|
2413
|
+
}
|
|
2414
|
+
return { success: false, error: "Internal server error." };
|
|
2415
|
+
}
|
|
2416
|
+
/**
|
|
2417
|
+
* Gets current token usage and billing period for the team (v1).
|
|
2418
|
+
*/
|
|
2419
|
+
async getTokenUsage() {
|
|
2420
|
+
const headers = this.prepareHeaders();
|
|
2421
|
+
try {
|
|
2422
|
+
const response = await this.getRequest(
|
|
2423
|
+
`${this.apiUrl}/v1/team/token-usage`,
|
|
2424
|
+
headers
|
|
2425
|
+
);
|
|
2426
|
+
if (response.status === 200) {
|
|
2427
|
+
return response.data;
|
|
2428
|
+
} else {
|
|
2429
|
+
this.handleError(response, "get token usage");
|
|
2430
|
+
}
|
|
2431
|
+
} catch (error) {
|
|
2432
|
+
if (error.response?.data?.error) {
|
|
2433
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2434
|
+
} else {
|
|
2435
|
+
throw new FirecrawlError(error.message, 500);
|
|
2436
|
+
}
|
|
2437
|
+
}
|
|
2438
|
+
return { success: false, error: "Internal server error." };
|
|
2439
|
+
}
|
|
2440
|
+
/**
|
|
2441
|
+
* Gets historical credit usage. Pass byApiKey=true to break down by API key.
|
|
2442
|
+
*/
|
|
2443
|
+
async getCreditUsageHistorical(byApiKey) {
|
|
2444
|
+
const headers = this.prepareHeaders();
|
|
2445
|
+
try {
|
|
2446
|
+
const url = `${this.apiUrl}/v1/team/credit-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2447
|
+
const response = await this.getRequest(url, headers);
|
|
2448
|
+
if (response.status === 200) {
|
|
2449
|
+
return response.data;
|
|
2450
|
+
} else {
|
|
2451
|
+
this.handleError(response, "get credit usage historical");
|
|
2452
|
+
}
|
|
2453
|
+
} catch (error) {
|
|
2454
|
+
if (error.response?.data?.error) {
|
|
2455
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2456
|
+
} else {
|
|
2457
|
+
throw new FirecrawlError(error.message, 500);
|
|
2458
|
+
}
|
|
2459
|
+
}
|
|
2460
|
+
return { success: false, error: "Internal server error." };
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Gets historical token usage. Pass byApiKey=true to break down by API key.
|
|
2464
|
+
*/
|
|
2465
|
+
async getTokenUsageHistorical(byApiKey) {
|
|
2466
|
+
const headers = this.prepareHeaders();
|
|
2467
|
+
try {
|
|
2468
|
+
const url = `${this.apiUrl}/v1/team/token-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2469
|
+
const response = await this.getRequest(url, headers);
|
|
2470
|
+
if (response.status === 200) {
|
|
2471
|
+
return response.data;
|
|
2472
|
+
} else {
|
|
2473
|
+
this.handleError(response, "get token usage historical");
|
|
2474
|
+
}
|
|
2475
|
+
} catch (error) {
|
|
2476
|
+
if (error.response?.data?.error) {
|
|
2477
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2478
|
+
} else {
|
|
2479
|
+
throw new FirecrawlError(error.message, 500);
|
|
2480
|
+
}
|
|
2481
|
+
}
|
|
2482
|
+
return { success: false, error: "Internal server error." };
|
|
2483
|
+
}
|
|
2312
2484
|
};
|
|
2313
2485
|
var CrawlWatcher = class extends e {
|
|
2314
2486
|
ws;
|
package/dist/index.d.cts
CHANGED
|
@@ -288,9 +288,35 @@ interface ConcurrencyCheck {
|
|
|
288
288
|
}
|
|
289
289
|
interface CreditUsage {
|
|
290
290
|
remainingCredits: number;
|
|
291
|
+
planCredits?: number;
|
|
292
|
+
billingPeriodStart?: string | null;
|
|
293
|
+
billingPeriodEnd?: string | null;
|
|
291
294
|
}
|
|
292
295
|
interface TokenUsage {
|
|
293
296
|
remainingTokens: number;
|
|
297
|
+
planTokens?: number;
|
|
298
|
+
billingPeriodStart?: string | null;
|
|
299
|
+
billingPeriodEnd?: string | null;
|
|
300
|
+
}
|
|
301
|
+
interface CreditUsageHistoricalPeriod {
|
|
302
|
+
startDate: string | null;
|
|
303
|
+
endDate: string | null;
|
|
304
|
+
apiKey?: string;
|
|
305
|
+
creditsUsed: number;
|
|
306
|
+
}
|
|
307
|
+
interface CreditUsageHistoricalResponse {
|
|
308
|
+
success: boolean;
|
|
309
|
+
periods: CreditUsageHistoricalPeriod[];
|
|
310
|
+
}
|
|
311
|
+
interface TokenUsageHistoricalPeriod {
|
|
312
|
+
startDate: string | null;
|
|
313
|
+
endDate: string | null;
|
|
314
|
+
apiKey?: string;
|
|
315
|
+
tokensUsed: number;
|
|
316
|
+
}
|
|
317
|
+
interface TokenUsageHistoricalResponse {
|
|
318
|
+
success: boolean;
|
|
319
|
+
periods: TokenUsageHistoricalPeriod[];
|
|
294
320
|
}
|
|
295
321
|
interface CrawlErrorsResponse$1 {
|
|
296
322
|
errors: {
|
|
@@ -324,6 +350,14 @@ declare class SdkError extends Error {
|
|
|
324
350
|
details?: unknown;
|
|
325
351
|
constructor(message: string, status?: number, code?: string, details?: unknown);
|
|
326
352
|
}
|
|
353
|
+
interface QueueStatusResponse$1 {
|
|
354
|
+
success: boolean;
|
|
355
|
+
jobsInQueue: number;
|
|
356
|
+
activeJobsInQueue: number;
|
|
357
|
+
waitingJobsInQueue: number;
|
|
358
|
+
maxConcurrency: number;
|
|
359
|
+
mostRecentSuccess: string | null;
|
|
360
|
+
}
|
|
327
361
|
|
|
328
362
|
interface HttpClientOptions {
|
|
329
363
|
apiKey: string;
|
|
@@ -544,6 +578,12 @@ declare class FirecrawlClient {
|
|
|
544
578
|
getCreditUsage(): Promise<CreditUsage>;
|
|
545
579
|
/** Recent token usage. */
|
|
546
580
|
getTokenUsage(): Promise<TokenUsage>;
|
|
581
|
+
/** Historical credit usage by month; set byApiKey to true to break down by API key. */
|
|
582
|
+
getCreditUsageHistorical(byApiKey?: boolean): Promise<CreditUsageHistoricalResponse>;
|
|
583
|
+
/** Historical token usage by month; set byApiKey to true to break down by API key. */
|
|
584
|
+
getTokenUsageHistorical(byApiKey?: boolean): Promise<TokenUsageHistoricalResponse>;
|
|
585
|
+
/** Metrics about the team's scrape queue. */
|
|
586
|
+
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
547
587
|
/**
|
|
548
588
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
549
589
|
* @param jobId Job id.
|
|
@@ -1068,6 +1108,58 @@ interface GenerateLLMsTextStatusResponse {
|
|
|
1068
1108
|
error?: string;
|
|
1069
1109
|
expiresAt: string;
|
|
1070
1110
|
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Response interface for queue status operations.
|
|
1113
|
+
*/
|
|
1114
|
+
interface QueueStatusResponse {
|
|
1115
|
+
success: boolean;
|
|
1116
|
+
jobsInQueue: number;
|
|
1117
|
+
activeJobsInQueue: number;
|
|
1118
|
+
waitingJobsInQueue: number;
|
|
1119
|
+
maxConcurrency: number;
|
|
1120
|
+
/**
|
|
1121
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
1122
|
+
*/
|
|
1123
|
+
mostRecentSuccess: string | null;
|
|
1124
|
+
}
|
|
1125
|
+
/** Credit usage for v1 API (snake_case fields as returned by API). */
|
|
1126
|
+
interface CreditUsageResponseV1 {
|
|
1127
|
+
success: boolean;
|
|
1128
|
+
data: {
|
|
1129
|
+
remaining_credits: number;
|
|
1130
|
+
plan_credits: number;
|
|
1131
|
+
billing_period_start: string | null;
|
|
1132
|
+
billing_period_end: string | null;
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
/** Token usage for v1 API (snake_case fields as returned by API). */
|
|
1136
|
+
interface TokenUsageResponseV1 {
|
|
1137
|
+
success: boolean;
|
|
1138
|
+
data: {
|
|
1139
|
+
remaining_tokens: number;
|
|
1140
|
+
plan_tokens: number;
|
|
1141
|
+
billing_period_start: string | null;
|
|
1142
|
+
billing_period_end: string | null;
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
interface CreditUsageHistoricalResponseV1 {
|
|
1146
|
+
success: boolean;
|
|
1147
|
+
periods: {
|
|
1148
|
+
startDate: string | null;
|
|
1149
|
+
endDate: string | null;
|
|
1150
|
+
apiKey?: string;
|
|
1151
|
+
creditsUsed: number;
|
|
1152
|
+
}[];
|
|
1153
|
+
}
|
|
1154
|
+
interface TokenUsageHistoricalResponseV1 {
|
|
1155
|
+
success: boolean;
|
|
1156
|
+
periods: {
|
|
1157
|
+
startDate: string | null;
|
|
1158
|
+
endDate: string | null;
|
|
1159
|
+
apiKey?: string;
|
|
1160
|
+
tokensUsed: number;
|
|
1161
|
+
}[];
|
|
1162
|
+
}
|
|
1071
1163
|
/**
|
|
1072
1164
|
* Main class for interacting with the Firecrawl API.
|
|
1073
1165
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1251,7 +1343,7 @@ declare class FirecrawlApp {
|
|
|
1251
1343
|
* @param {AxiosResponse} response - The response from the API.
|
|
1252
1344
|
* @param {string} action - The action being performed when the error occurred.
|
|
1253
1345
|
*/
|
|
1254
|
-
handleError(response: AxiosResponse, action: string):
|
|
1346
|
+
handleError(response: AxiosResponse, action: string): never;
|
|
1255
1347
|
/**
|
|
1256
1348
|
* Initiates a deep research operation on a given query and polls until completion.
|
|
1257
1349
|
* @param query - The query to research.
|
|
@@ -1333,6 +1425,27 @@ declare class FirecrawlApp {
|
|
|
1333
1425
|
* @returns The current status and results of the generation operation.
|
|
1334
1426
|
*/
|
|
1335
1427
|
checkGenerateLLMsTextStatus(id: string): Promise<GenerateLLMsTextStatusResponse | ErrorResponse>;
|
|
1428
|
+
/**
|
|
1429
|
+
* Gets metrics about the team's scrape queue.
|
|
1430
|
+
* @returns The current queue status.
|
|
1431
|
+
*/
|
|
1432
|
+
getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse>;
|
|
1433
|
+
/**
|
|
1434
|
+
* Gets current credit usage and billing period for the team (v1).
|
|
1435
|
+
*/
|
|
1436
|
+
getCreditUsage(): Promise<CreditUsageResponseV1 | ErrorResponse>;
|
|
1437
|
+
/**
|
|
1438
|
+
* Gets current token usage and billing period for the team (v1).
|
|
1439
|
+
*/
|
|
1440
|
+
getTokenUsage(): Promise<TokenUsageResponseV1 | ErrorResponse>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Gets historical credit usage. Pass byApiKey=true to break down by API key.
|
|
1443
|
+
*/
|
|
1444
|
+
getCreditUsageHistorical(byApiKey?: boolean): Promise<CreditUsageHistoricalResponseV1 | ErrorResponse>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Gets historical token usage. Pass byApiKey=true to break down by API key.
|
|
1447
|
+
*/
|
|
1448
|
+
getTokenUsageHistorical(byApiKey?: boolean): Promise<TokenUsageHistoricalResponseV1 | ErrorResponse>;
|
|
1336
1449
|
}
|
|
1337
1450
|
interface CrawlWatcherEvents {
|
|
1338
1451
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1374,4 +1487,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1374
1487
|
get v1(): FirecrawlApp;
|
|
1375
1488
|
}
|
|
1376
1489
|
|
|
1377
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1490
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -288,9 +288,35 @@ interface ConcurrencyCheck {
|
|
|
288
288
|
}
|
|
289
289
|
interface CreditUsage {
|
|
290
290
|
remainingCredits: number;
|
|
291
|
+
planCredits?: number;
|
|
292
|
+
billingPeriodStart?: string | null;
|
|
293
|
+
billingPeriodEnd?: string | null;
|
|
291
294
|
}
|
|
292
295
|
interface TokenUsage {
|
|
293
296
|
remainingTokens: number;
|
|
297
|
+
planTokens?: number;
|
|
298
|
+
billingPeriodStart?: string | null;
|
|
299
|
+
billingPeriodEnd?: string | null;
|
|
300
|
+
}
|
|
301
|
+
interface CreditUsageHistoricalPeriod {
|
|
302
|
+
startDate: string | null;
|
|
303
|
+
endDate: string | null;
|
|
304
|
+
apiKey?: string;
|
|
305
|
+
creditsUsed: number;
|
|
306
|
+
}
|
|
307
|
+
interface CreditUsageHistoricalResponse {
|
|
308
|
+
success: boolean;
|
|
309
|
+
periods: CreditUsageHistoricalPeriod[];
|
|
310
|
+
}
|
|
311
|
+
interface TokenUsageHistoricalPeriod {
|
|
312
|
+
startDate: string | null;
|
|
313
|
+
endDate: string | null;
|
|
314
|
+
apiKey?: string;
|
|
315
|
+
tokensUsed: number;
|
|
316
|
+
}
|
|
317
|
+
interface TokenUsageHistoricalResponse {
|
|
318
|
+
success: boolean;
|
|
319
|
+
periods: TokenUsageHistoricalPeriod[];
|
|
294
320
|
}
|
|
295
321
|
interface CrawlErrorsResponse$1 {
|
|
296
322
|
errors: {
|
|
@@ -324,6 +350,14 @@ declare class SdkError extends Error {
|
|
|
324
350
|
details?: unknown;
|
|
325
351
|
constructor(message: string, status?: number, code?: string, details?: unknown);
|
|
326
352
|
}
|
|
353
|
+
interface QueueStatusResponse$1 {
|
|
354
|
+
success: boolean;
|
|
355
|
+
jobsInQueue: number;
|
|
356
|
+
activeJobsInQueue: number;
|
|
357
|
+
waitingJobsInQueue: number;
|
|
358
|
+
maxConcurrency: number;
|
|
359
|
+
mostRecentSuccess: string | null;
|
|
360
|
+
}
|
|
327
361
|
|
|
328
362
|
interface HttpClientOptions {
|
|
329
363
|
apiKey: string;
|
|
@@ -544,6 +578,12 @@ declare class FirecrawlClient {
|
|
|
544
578
|
getCreditUsage(): Promise<CreditUsage>;
|
|
545
579
|
/** Recent token usage. */
|
|
546
580
|
getTokenUsage(): Promise<TokenUsage>;
|
|
581
|
+
/** Historical credit usage by month; set byApiKey to true to break down by API key. */
|
|
582
|
+
getCreditUsageHistorical(byApiKey?: boolean): Promise<CreditUsageHistoricalResponse>;
|
|
583
|
+
/** Historical token usage by month; set byApiKey to true to break down by API key. */
|
|
584
|
+
getTokenUsageHistorical(byApiKey?: boolean): Promise<TokenUsageHistoricalResponse>;
|
|
585
|
+
/** Metrics about the team's scrape queue. */
|
|
586
|
+
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
547
587
|
/**
|
|
548
588
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
549
589
|
* @param jobId Job id.
|
|
@@ -1068,6 +1108,58 @@ interface GenerateLLMsTextStatusResponse {
|
|
|
1068
1108
|
error?: string;
|
|
1069
1109
|
expiresAt: string;
|
|
1070
1110
|
}
|
|
1111
|
+
/**
|
|
1112
|
+
* Response interface for queue status operations.
|
|
1113
|
+
*/
|
|
1114
|
+
interface QueueStatusResponse {
|
|
1115
|
+
success: boolean;
|
|
1116
|
+
jobsInQueue: number;
|
|
1117
|
+
activeJobsInQueue: number;
|
|
1118
|
+
waitingJobsInQueue: number;
|
|
1119
|
+
maxConcurrency: number;
|
|
1120
|
+
/**
|
|
1121
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
1122
|
+
*/
|
|
1123
|
+
mostRecentSuccess: string | null;
|
|
1124
|
+
}
|
|
1125
|
+
/** Credit usage for v1 API (snake_case fields as returned by API). */
|
|
1126
|
+
interface CreditUsageResponseV1 {
|
|
1127
|
+
success: boolean;
|
|
1128
|
+
data: {
|
|
1129
|
+
remaining_credits: number;
|
|
1130
|
+
plan_credits: number;
|
|
1131
|
+
billing_period_start: string | null;
|
|
1132
|
+
billing_period_end: string | null;
|
|
1133
|
+
};
|
|
1134
|
+
}
|
|
1135
|
+
/** Token usage for v1 API (snake_case fields as returned by API). */
|
|
1136
|
+
interface TokenUsageResponseV1 {
|
|
1137
|
+
success: boolean;
|
|
1138
|
+
data: {
|
|
1139
|
+
remaining_tokens: number;
|
|
1140
|
+
plan_tokens: number;
|
|
1141
|
+
billing_period_start: string | null;
|
|
1142
|
+
billing_period_end: string | null;
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
interface CreditUsageHistoricalResponseV1 {
|
|
1146
|
+
success: boolean;
|
|
1147
|
+
periods: {
|
|
1148
|
+
startDate: string | null;
|
|
1149
|
+
endDate: string | null;
|
|
1150
|
+
apiKey?: string;
|
|
1151
|
+
creditsUsed: number;
|
|
1152
|
+
}[];
|
|
1153
|
+
}
|
|
1154
|
+
interface TokenUsageHistoricalResponseV1 {
|
|
1155
|
+
success: boolean;
|
|
1156
|
+
periods: {
|
|
1157
|
+
startDate: string | null;
|
|
1158
|
+
endDate: string | null;
|
|
1159
|
+
apiKey?: string;
|
|
1160
|
+
tokensUsed: number;
|
|
1161
|
+
}[];
|
|
1162
|
+
}
|
|
1071
1163
|
/**
|
|
1072
1164
|
* Main class for interacting with the Firecrawl API.
|
|
1073
1165
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1251,7 +1343,7 @@ declare class FirecrawlApp {
|
|
|
1251
1343
|
* @param {AxiosResponse} response - The response from the API.
|
|
1252
1344
|
* @param {string} action - The action being performed when the error occurred.
|
|
1253
1345
|
*/
|
|
1254
|
-
handleError(response: AxiosResponse, action: string):
|
|
1346
|
+
handleError(response: AxiosResponse, action: string): never;
|
|
1255
1347
|
/**
|
|
1256
1348
|
* Initiates a deep research operation on a given query and polls until completion.
|
|
1257
1349
|
* @param query - The query to research.
|
|
@@ -1333,6 +1425,27 @@ declare class FirecrawlApp {
|
|
|
1333
1425
|
* @returns The current status and results of the generation operation.
|
|
1334
1426
|
*/
|
|
1335
1427
|
checkGenerateLLMsTextStatus(id: string): Promise<GenerateLLMsTextStatusResponse | ErrorResponse>;
|
|
1428
|
+
/**
|
|
1429
|
+
* Gets metrics about the team's scrape queue.
|
|
1430
|
+
* @returns The current queue status.
|
|
1431
|
+
*/
|
|
1432
|
+
getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse>;
|
|
1433
|
+
/**
|
|
1434
|
+
* Gets current credit usage and billing period for the team (v1).
|
|
1435
|
+
*/
|
|
1436
|
+
getCreditUsage(): Promise<CreditUsageResponseV1 | ErrorResponse>;
|
|
1437
|
+
/**
|
|
1438
|
+
* Gets current token usage and billing period for the team (v1).
|
|
1439
|
+
*/
|
|
1440
|
+
getTokenUsage(): Promise<TokenUsageResponseV1 | ErrorResponse>;
|
|
1441
|
+
/**
|
|
1442
|
+
* Gets historical credit usage. Pass byApiKey=true to break down by API key.
|
|
1443
|
+
*/
|
|
1444
|
+
getCreditUsageHistorical(byApiKey?: boolean): Promise<CreditUsageHistoricalResponseV1 | ErrorResponse>;
|
|
1445
|
+
/**
|
|
1446
|
+
* Gets historical token usage. Pass byApiKey=true to break down by API key.
|
|
1447
|
+
*/
|
|
1448
|
+
getTokenUsageHistorical(byApiKey?: boolean): Promise<TokenUsageHistoricalResponseV1 | ErrorResponse>;
|
|
1336
1449
|
}
|
|
1337
1450
|
interface CrawlWatcherEvents {
|
|
1338
1451
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1374,4 +1487,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1374
1487
|
get v1(): FirecrawlApp;
|
|
1375
1488
|
}
|
|
1376
1489
|
|
|
1377
|
-
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
|
1490
|
+
export { type ActionOption, type ActiveCrawl, type ActiveCrawlsResponse, type AttributesFormat, type BatchScrapeJob, type BatchScrapeOptions, type BatchScrapeResponse$1 as BatchScrapeResponse, type CategoryOption, type ChangeTrackingFormat, type ClickAction, type ConcurrencyCheck, type CrawlErrorsResponse$1 as CrawlErrorsResponse, type CrawlJob, type CrawlOptions, type CrawlResponse$1 as CrawlResponse, type CreditUsage, type CreditUsageHistoricalPeriod, type CreditUsageHistoricalResponse, type Document, type DocumentMetadata, type ErrorDetails, type ExecuteJavascriptAction, type ExtractResponse$1 as ExtractResponse, Firecrawl, FirecrawlApp as FirecrawlAppV1, FirecrawlClient, type FirecrawlClientOptions, type Format, type FormatOption, type FormatString, type JsonFormat, type LocationConfig, type MapData, type MapOptions, type PDFAction, type PaginationConfig, type PressAction, type QueueStatusResponse$1 as QueueStatusResponse, type ScrapeAction, type ScrapeOptions, type ScreenshotAction, type ScreenshotFormat, type ScrollAction, SdkError, type SearchData, type SearchRequest, type SearchResultImages, type SearchResultNews, type SearchResultWeb, type TokenUsage, type TokenUsageHistoricalPeriod, type TokenUsageHistoricalResponse, type Viewport, type WaitAction, type WebhookConfig, type WriteAction, Firecrawl as default };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
require_package
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-KCQFB5LN.js";
|
|
4
4
|
|
|
5
5
|
// src/v2/utils/httpClient.ts
|
|
6
6
|
import axios from "axios";
|
|
@@ -624,7 +624,12 @@ async function getCreditUsage(http) {
|
|
|
624
624
|
const res = await http.get("/v2/team/credit-usage");
|
|
625
625
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage");
|
|
626
626
|
const d = res.data.data || res.data;
|
|
627
|
-
return {
|
|
627
|
+
return {
|
|
628
|
+
remainingCredits: d.remainingCredits ?? d.remaining_credits ?? 0,
|
|
629
|
+
planCredits: d.planCredits ?? d.plan_credits,
|
|
630
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
631
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null
|
|
632
|
+
};
|
|
628
633
|
} catch (err) {
|
|
629
634
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage");
|
|
630
635
|
throw err;
|
|
@@ -634,12 +639,50 @@ async function getTokenUsage(http) {
|
|
|
634
639
|
try {
|
|
635
640
|
const res = await http.get("/v2/team/token-usage");
|
|
636
641
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage");
|
|
637
|
-
|
|
642
|
+
const d = res.data.data || res.data;
|
|
643
|
+
return {
|
|
644
|
+
remainingTokens: d.remainingTokens ?? d.remaining_tokens ?? 0,
|
|
645
|
+
planTokens: d.planTokens ?? d.plan_tokens,
|
|
646
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
647
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null
|
|
648
|
+
};
|
|
638
649
|
} catch (err) {
|
|
639
650
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage");
|
|
640
651
|
throw err;
|
|
641
652
|
}
|
|
642
653
|
}
|
|
654
|
+
async function getQueueStatus(http) {
|
|
655
|
+
try {
|
|
656
|
+
const res = await http.get("/v2/team/queue-status");
|
|
657
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
658
|
+
return res.data;
|
|
659
|
+
} catch (err) {
|
|
660
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
661
|
+
throw err;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
async function getCreditUsageHistorical(http, byApiKey) {
|
|
665
|
+
try {
|
|
666
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
667
|
+
const res = await http.get(`/v2/team/credit-usage/historical${query}`);
|
|
668
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage historical");
|
|
669
|
+
return res.data;
|
|
670
|
+
} catch (err) {
|
|
671
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage historical");
|
|
672
|
+
throw err;
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
async function getTokenUsageHistorical(http, byApiKey) {
|
|
676
|
+
try {
|
|
677
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
678
|
+
const res = await http.get(`/v2/team/token-usage/historical${query}`);
|
|
679
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage historical");
|
|
680
|
+
return res.data;
|
|
681
|
+
} catch (err) {
|
|
682
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage historical");
|
|
683
|
+
throw err;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
643
686
|
|
|
644
687
|
// src/v2/watcher.ts
|
|
645
688
|
import { EventEmitter } from "events";
|
|
@@ -947,6 +990,18 @@ var FirecrawlClient = class {
|
|
|
947
990
|
async getTokenUsage() {
|
|
948
991
|
return getTokenUsage(this.http);
|
|
949
992
|
}
|
|
993
|
+
/** Historical credit usage by month; set byApiKey to true to break down by API key. */
|
|
994
|
+
async getCreditUsageHistorical(byApiKey) {
|
|
995
|
+
return getCreditUsageHistorical(this.http, byApiKey);
|
|
996
|
+
}
|
|
997
|
+
/** Historical token usage by month; set byApiKey to true to break down by API key. */
|
|
998
|
+
async getTokenUsageHistorical(byApiKey) {
|
|
999
|
+
return getTokenUsageHistorical(this.http, byApiKey);
|
|
1000
|
+
}
|
|
1001
|
+
/** Metrics about the team's scrape queue. */
|
|
1002
|
+
async getQueueStatus() {
|
|
1003
|
+
return getQueueStatus(this.http);
|
|
1004
|
+
}
|
|
950
1005
|
// Watcher
|
|
951
1006
|
/**
|
|
952
1007
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
|
@@ -992,7 +1047,7 @@ var FirecrawlApp = class {
|
|
|
992
1047
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
993
1048
|
return process.env.npm_package_version;
|
|
994
1049
|
}
|
|
995
|
-
const packageJson = await import("./package-
|
|
1050
|
+
const packageJson = await import("./package-QFGMHRQZ.js");
|
|
996
1051
|
return packageJson.default.version;
|
|
997
1052
|
} catch (error) {
|
|
998
1053
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -2193,6 +2248,123 @@ var FirecrawlApp = class {
|
|
|
2193
2248
|
}
|
|
2194
2249
|
return { success: false, error: "Internal server error." };
|
|
2195
2250
|
}
|
|
2251
|
+
/**
|
|
2252
|
+
* Gets metrics about the team's scrape queue.
|
|
2253
|
+
* @returns The current queue status.
|
|
2254
|
+
*/
|
|
2255
|
+
async getQueueStatus() {
|
|
2256
|
+
const headers = this.prepareHeaders();
|
|
2257
|
+
try {
|
|
2258
|
+
const response = await this.getRequest(
|
|
2259
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2260
|
+
headers
|
|
2261
|
+
);
|
|
2262
|
+
if (response.status === 200) {
|
|
2263
|
+
return response.data;
|
|
2264
|
+
} else {
|
|
2265
|
+
this.handleError(response, "get queue status");
|
|
2266
|
+
}
|
|
2267
|
+
} catch (error) {
|
|
2268
|
+
if (error.response?.data?.error) {
|
|
2269
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2270
|
+
} else {
|
|
2271
|
+
throw new FirecrawlError(error.message, 500);
|
|
2272
|
+
}
|
|
2273
|
+
}
|
|
2274
|
+
return { success: false, error: "Internal server error." };
|
|
2275
|
+
}
|
|
2276
|
+
/**
|
|
2277
|
+
* Gets current credit usage and billing period for the team (v1).
|
|
2278
|
+
*/
|
|
2279
|
+
async getCreditUsage() {
|
|
2280
|
+
const headers = this.prepareHeaders();
|
|
2281
|
+
try {
|
|
2282
|
+
const response = await this.getRequest(
|
|
2283
|
+
`${this.apiUrl}/v1/team/credit-usage`,
|
|
2284
|
+
headers
|
|
2285
|
+
);
|
|
2286
|
+
if (response.status === 200) {
|
|
2287
|
+
return response.data;
|
|
2288
|
+
} else {
|
|
2289
|
+
this.handleError(response, "get credit usage");
|
|
2290
|
+
}
|
|
2291
|
+
} catch (error) {
|
|
2292
|
+
if (error.response?.data?.error) {
|
|
2293
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2294
|
+
} else {
|
|
2295
|
+
throw new FirecrawlError(error.message, 500);
|
|
2296
|
+
}
|
|
2297
|
+
}
|
|
2298
|
+
return { success: false, error: "Internal server error." };
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Gets current token usage and billing period for the team (v1).
|
|
2302
|
+
*/
|
|
2303
|
+
async getTokenUsage() {
|
|
2304
|
+
const headers = this.prepareHeaders();
|
|
2305
|
+
try {
|
|
2306
|
+
const response = await this.getRequest(
|
|
2307
|
+
`${this.apiUrl}/v1/team/token-usage`,
|
|
2308
|
+
headers
|
|
2309
|
+
);
|
|
2310
|
+
if (response.status === 200) {
|
|
2311
|
+
return response.data;
|
|
2312
|
+
} else {
|
|
2313
|
+
this.handleError(response, "get token usage");
|
|
2314
|
+
}
|
|
2315
|
+
} catch (error) {
|
|
2316
|
+
if (error.response?.data?.error) {
|
|
2317
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2318
|
+
} else {
|
|
2319
|
+
throw new FirecrawlError(error.message, 500);
|
|
2320
|
+
}
|
|
2321
|
+
}
|
|
2322
|
+
return { success: false, error: "Internal server error." };
|
|
2323
|
+
}
|
|
2324
|
+
/**
|
|
2325
|
+
* Gets historical credit usage. Pass byApiKey=true to break down by API key.
|
|
2326
|
+
*/
|
|
2327
|
+
async getCreditUsageHistorical(byApiKey) {
|
|
2328
|
+
const headers = this.prepareHeaders();
|
|
2329
|
+
try {
|
|
2330
|
+
const url = `${this.apiUrl}/v1/team/credit-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2331
|
+
const response = await this.getRequest(url, headers);
|
|
2332
|
+
if (response.status === 200) {
|
|
2333
|
+
return response.data;
|
|
2334
|
+
} else {
|
|
2335
|
+
this.handleError(response, "get credit usage historical");
|
|
2336
|
+
}
|
|
2337
|
+
} catch (error) {
|
|
2338
|
+
if (error.response?.data?.error) {
|
|
2339
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2340
|
+
} else {
|
|
2341
|
+
throw new FirecrawlError(error.message, 500);
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
return { success: false, error: "Internal server error." };
|
|
2345
|
+
}
|
|
2346
|
+
/**
|
|
2347
|
+
* Gets historical token usage. Pass byApiKey=true to break down by API key.
|
|
2348
|
+
*/
|
|
2349
|
+
async getTokenUsageHistorical(byApiKey) {
|
|
2350
|
+
const headers = this.prepareHeaders();
|
|
2351
|
+
try {
|
|
2352
|
+
const url = `${this.apiUrl}/v1/team/token-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2353
|
+
const response = await this.getRequest(url, headers);
|
|
2354
|
+
if (response.status === 200) {
|
|
2355
|
+
return response.data;
|
|
2356
|
+
} else {
|
|
2357
|
+
this.handleError(response, "get token usage historical");
|
|
2358
|
+
}
|
|
2359
|
+
} catch (error) {
|
|
2360
|
+
if (error.response?.data?.error) {
|
|
2361
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ""}`, error.response.status);
|
|
2362
|
+
} else {
|
|
2363
|
+
throw new FirecrawlError(error.message, 500);
|
|
2364
|
+
}
|
|
2365
|
+
}
|
|
2366
|
+
return { success: false, error: "Internal server error." };
|
|
2367
|
+
}
|
|
2196
2368
|
};
|
|
2197
2369
|
var CrawlWatcher = class extends e {
|
|
2198
2370
|
ws;
|
package/package.json
CHANGED
|
@@ -32,5 +32,13 @@ describe("v2.usage e2e", () => {
|
|
|
32
32
|
const resp = await client.getTokenUsage();
|
|
33
33
|
expect(typeof resp.remainingTokens).toBe("number");
|
|
34
34
|
}, 60_000);
|
|
35
|
+
|
|
36
|
+
test("get_queue_status", async () => {
|
|
37
|
+
const resp = await client.getQueueStatus();
|
|
38
|
+
expect(typeof resp.jobsInQueue).toBe("number");
|
|
39
|
+
expect(typeof resp.activeJobsInQueue).toBe("number");
|
|
40
|
+
expect(typeof resp.waitingJobsInQueue).toBe("number");
|
|
41
|
+
expect(typeof resp.maxConcurrency).toBe("number");
|
|
42
|
+
}, 60_000);
|
|
35
43
|
});
|
|
36
44
|
|
package/src/v1/index.ts
CHANGED
|
@@ -568,6 +568,64 @@ export interface GenerateLLMsTextStatusResponse {
|
|
|
568
568
|
expiresAt: string;
|
|
569
569
|
}
|
|
570
570
|
|
|
571
|
+
/**
|
|
572
|
+
* Response interface for queue status operations.
|
|
573
|
+
*/
|
|
574
|
+
export interface QueueStatusResponse {
|
|
575
|
+
success: boolean;
|
|
576
|
+
jobsInQueue: number;
|
|
577
|
+
activeJobsInQueue: number;
|
|
578
|
+
waitingJobsInQueue: number;
|
|
579
|
+
maxConcurrency: number;
|
|
580
|
+
|
|
581
|
+
/**
|
|
582
|
+
* ISO timestamp of the most recent successful scrape in the past 24 hours. Will be null if no successful scrape has occurred in the past 24 hours.
|
|
583
|
+
*/
|
|
584
|
+
mostRecentSuccess: string | null;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
/** Credit usage for v1 API (snake_case fields as returned by API). */
|
|
588
|
+
export interface CreditUsageResponseV1 {
|
|
589
|
+
success: boolean;
|
|
590
|
+
data: {
|
|
591
|
+
remaining_credits: number;
|
|
592
|
+
plan_credits: number;
|
|
593
|
+
billing_period_start: string | null;
|
|
594
|
+
billing_period_end: string | null;
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
/** Token usage for v1 API (snake_case fields as returned by API). */
|
|
599
|
+
export interface TokenUsageResponseV1 {
|
|
600
|
+
success: boolean;
|
|
601
|
+
data: {
|
|
602
|
+
remaining_tokens: number;
|
|
603
|
+
plan_tokens: number;
|
|
604
|
+
billing_period_start: string | null;
|
|
605
|
+
billing_period_end: string | null;
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
export interface CreditUsageHistoricalResponseV1 {
|
|
610
|
+
success: boolean;
|
|
611
|
+
periods: {
|
|
612
|
+
startDate: string | null;
|
|
613
|
+
endDate: string | null;
|
|
614
|
+
apiKey?: string;
|
|
615
|
+
creditsUsed: number;
|
|
616
|
+
}[];
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export interface TokenUsageHistoricalResponseV1 {
|
|
620
|
+
success: boolean;
|
|
621
|
+
periods: {
|
|
622
|
+
startDate: string | null;
|
|
623
|
+
endDate: string | null;
|
|
624
|
+
apiKey?: string;
|
|
625
|
+
tokensUsed: number;
|
|
626
|
+
}[];
|
|
627
|
+
}
|
|
628
|
+
|
|
571
629
|
/**
|
|
572
630
|
* Main class for interacting with the Firecrawl API.
|
|
573
631
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1586,7 +1644,7 @@ export default class FirecrawlApp {
|
|
|
1586
1644
|
* @param {AxiosResponse} response - The response from the API.
|
|
1587
1645
|
* @param {string} action - The action being performed when the error occurred.
|
|
1588
1646
|
*/
|
|
1589
|
-
handleError(response: AxiosResponse, action: string):
|
|
1647
|
+
handleError(response: AxiosResponse, action: string): never {
|
|
1590
1648
|
if (!response) {
|
|
1591
1649
|
throw new FirecrawlError(
|
|
1592
1650
|
`No response received while trying to ${action}. This may be a network error or the server is unreachable.`,
|
|
@@ -2027,6 +2085,129 @@ export default class FirecrawlApp {
|
|
|
2027
2085
|
}
|
|
2028
2086
|
return { success: false, error: "Internal server error." };
|
|
2029
2087
|
}
|
|
2088
|
+
|
|
2089
|
+
/**
|
|
2090
|
+
* Gets metrics about the team's scrape queue.
|
|
2091
|
+
* @returns The current queue status.
|
|
2092
|
+
*/
|
|
2093
|
+
async getQueueStatus(): Promise<QueueStatusResponse | ErrorResponse> {
|
|
2094
|
+
const headers = this.prepareHeaders();
|
|
2095
|
+
try {
|
|
2096
|
+
const response: AxiosResponse = await this.getRequest(
|
|
2097
|
+
`${this.apiUrl}/v1/team/queue-status`,
|
|
2098
|
+
headers
|
|
2099
|
+
);
|
|
2100
|
+
|
|
2101
|
+
if (response.status === 200) {
|
|
2102
|
+
return response.data;
|
|
2103
|
+
} else {
|
|
2104
|
+
this.handleError(response, "get queue status");
|
|
2105
|
+
}
|
|
2106
|
+
} catch (error: any) {
|
|
2107
|
+
if (error.response?.data?.error) {
|
|
2108
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2109
|
+
} else {
|
|
2110
|
+
throw new FirecrawlError(error.message, 500);
|
|
2111
|
+
}
|
|
2112
|
+
}
|
|
2113
|
+
return { success: false, error: "Internal server error." };
|
|
2114
|
+
}
|
|
2115
|
+
|
|
2116
|
+
/**
|
|
2117
|
+
* Gets current credit usage and billing period for the team (v1).
|
|
2118
|
+
*/
|
|
2119
|
+
async getCreditUsage(): Promise<CreditUsageResponseV1 | ErrorResponse> {
|
|
2120
|
+
const headers = this.prepareHeaders();
|
|
2121
|
+
try {
|
|
2122
|
+
const response: AxiosResponse = await this.getRequest(
|
|
2123
|
+
`${this.apiUrl}/v1/team/credit-usage`,
|
|
2124
|
+
headers
|
|
2125
|
+
);
|
|
2126
|
+
if (response.status === 200) {
|
|
2127
|
+
return response.data as CreditUsageResponseV1;
|
|
2128
|
+
} else {
|
|
2129
|
+
this.handleError(response, "get credit usage");
|
|
2130
|
+
}
|
|
2131
|
+
} catch (error: any) {
|
|
2132
|
+
if (error.response?.data?.error) {
|
|
2133
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2134
|
+
} else {
|
|
2135
|
+
throw new FirecrawlError(error.message, 500);
|
|
2136
|
+
}
|
|
2137
|
+
}
|
|
2138
|
+
return { success: false, error: "Internal server error." };
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
/**
|
|
2142
|
+
* Gets current token usage and billing period for the team (v1).
|
|
2143
|
+
*/
|
|
2144
|
+
async getTokenUsage(): Promise<TokenUsageResponseV1 | ErrorResponse> {
|
|
2145
|
+
const headers = this.prepareHeaders();
|
|
2146
|
+
try {
|
|
2147
|
+
const response: AxiosResponse = await this.getRequest(
|
|
2148
|
+
`${this.apiUrl}/v1/team/token-usage`,
|
|
2149
|
+
headers
|
|
2150
|
+
);
|
|
2151
|
+
if (response.status === 200) {
|
|
2152
|
+
return response.data as TokenUsageResponseV1;
|
|
2153
|
+
} else {
|
|
2154
|
+
this.handleError(response, "get token usage");
|
|
2155
|
+
}
|
|
2156
|
+
} catch (error: any) {
|
|
2157
|
+
if (error.response?.data?.error) {
|
|
2158
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2159
|
+
} else {
|
|
2160
|
+
throw new FirecrawlError(error.message, 500);
|
|
2161
|
+
}
|
|
2162
|
+
}
|
|
2163
|
+
return { success: false, error: "Internal server error." };
|
|
2164
|
+
}
|
|
2165
|
+
|
|
2166
|
+
/**
|
|
2167
|
+
* Gets historical credit usage. Pass byApiKey=true to break down by API key.
|
|
2168
|
+
*/
|
|
2169
|
+
async getCreditUsageHistorical(byApiKey?: boolean): Promise<CreditUsageHistoricalResponseV1 | ErrorResponse> {
|
|
2170
|
+
const headers = this.prepareHeaders();
|
|
2171
|
+
try {
|
|
2172
|
+
const url = `${this.apiUrl}/v1/team/credit-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2173
|
+
const response: AxiosResponse = await this.getRequest(url, headers);
|
|
2174
|
+
if (response.status === 200) {
|
|
2175
|
+
return response.data as CreditUsageHistoricalResponseV1;
|
|
2176
|
+
} else {
|
|
2177
|
+
this.handleError(response, "get credit usage historical");
|
|
2178
|
+
}
|
|
2179
|
+
} catch (error: any) {
|
|
2180
|
+
if (error.response?.data?.error) {
|
|
2181
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2182
|
+
} else {
|
|
2183
|
+
throw new FirecrawlError(error.message, 500);
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
return { success: false, error: "Internal server error." };
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
/**
|
|
2190
|
+
* Gets historical token usage. Pass byApiKey=true to break down by API key.
|
|
2191
|
+
*/
|
|
2192
|
+
async getTokenUsageHistorical(byApiKey?: boolean): Promise<TokenUsageHistoricalResponseV1 | ErrorResponse> {
|
|
2193
|
+
const headers = this.prepareHeaders();
|
|
2194
|
+
try {
|
|
2195
|
+
const url = `${this.apiUrl}/v1/team/token-usage/historical${byApiKey ? "?byApiKey=true" : ""}`;
|
|
2196
|
+
const response: AxiosResponse = await this.getRequest(url, headers);
|
|
2197
|
+
if (response.status === 200) {
|
|
2198
|
+
return response.data as TokenUsageHistoricalResponseV1;
|
|
2199
|
+
} else {
|
|
2200
|
+
this.handleError(response, "get token usage historical");
|
|
2201
|
+
}
|
|
2202
|
+
} catch (error: any) {
|
|
2203
|
+
if (error.response?.data?.error) {
|
|
2204
|
+
throw new FirecrawlError(`Request failed with status code ${error.response.status}. Error: ${error.response.data.error} ${error.response.data.details ? ` - ${JSON.stringify(error.response.data.details)}` : ''}`, error.response.status);
|
|
2205
|
+
} else {
|
|
2206
|
+
throw new FirecrawlError(error.message, 500);
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
return { success: false, error: "Internal server error." };
|
|
2210
|
+
}
|
|
2030
2211
|
}
|
|
2031
2212
|
|
|
2032
2213
|
interface CrawlWatcherEvents {
|
package/src/v2/client.ts
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
batchScrape as batchWaiter,
|
|
20
20
|
} from "./methods/batch";
|
|
21
21
|
import { startExtract, getExtractStatus, extract as extractWaiter } from "./methods/extract";
|
|
22
|
-
import { getConcurrency, getCreditUsage, getTokenUsage } from "./methods/usage";
|
|
22
|
+
import { getConcurrency, getCreditUsage, getQueueStatus, getTokenUsage, getCreditUsageHistorical, getTokenUsageHistorical } from "./methods/usage";
|
|
23
23
|
import type {
|
|
24
24
|
Document,
|
|
25
25
|
ScrapeOptions,
|
|
@@ -269,6 +269,21 @@ export class FirecrawlClient {
|
|
|
269
269
|
return getTokenUsage(this.http);
|
|
270
270
|
}
|
|
271
271
|
|
|
272
|
+
/** Historical credit usage by month; set byApiKey to true to break down by API key. */
|
|
273
|
+
async getCreditUsageHistorical(byApiKey?: boolean) {
|
|
274
|
+
return getCreditUsageHistorical(this.http, byApiKey);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/** Historical token usage by month; set byApiKey to true to break down by API key. */
|
|
278
|
+
async getTokenUsageHistorical(byApiKey?: boolean) {
|
|
279
|
+
return getTokenUsageHistorical(this.http, byApiKey);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** Metrics about the team's scrape queue. */
|
|
283
|
+
async getQueueStatus() {
|
|
284
|
+
return getQueueStatus(this.http);
|
|
285
|
+
}
|
|
286
|
+
|
|
272
287
|
// Watcher
|
|
273
288
|
/**
|
|
274
289
|
* Create a watcher for a crawl or batch job. Emits: `document`, `snapshot`, `done`, `error`.
|
package/src/v2/methods/usage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConcurrencyCheck, CreditUsage, TokenUsage } from "../types";
|
|
1
|
+
import type { ConcurrencyCheck, CreditUsage, QueueStatusResponse, TokenUsage, CreditUsageHistoricalResponse, TokenUsageHistoricalResponse } from "../types";
|
|
2
2
|
import { HttpClient } from "../utils/httpClient";
|
|
3
3
|
import { normalizeAxiosError, throwForBadResponse } from "../utils/errorHandler";
|
|
4
4
|
|
|
@@ -16,10 +16,15 @@ export async function getConcurrency(http: HttpClient): Promise<ConcurrencyCheck
|
|
|
16
16
|
|
|
17
17
|
export async function getCreditUsage(http: HttpClient): Promise<CreditUsage> {
|
|
18
18
|
try {
|
|
19
|
-
const res = await http.get<{ success: boolean; data?: { remainingCredits?: number; remaining_credits?: number } }>("/v2/team/credit-usage");
|
|
19
|
+
const res = await http.get<{ success: boolean; data?: { remainingCredits?: number; remaining_credits?: number; planCredits?: number; plan_credits?: number; billingPeriodStart?: string | null; billing_period_start?: string | null; billingPeriodEnd?: string | null; billing_period_end?: string | null } }>("/v2/team/credit-usage");
|
|
20
20
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage");
|
|
21
21
|
const d = res.data.data || (res.data as any);
|
|
22
|
-
return {
|
|
22
|
+
return {
|
|
23
|
+
remainingCredits: d.remainingCredits ?? d.remaining_credits ?? 0,
|
|
24
|
+
planCredits: d.planCredits ?? d.plan_credits,
|
|
25
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
26
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null,
|
|
27
|
+
};
|
|
23
28
|
} catch (err: any) {
|
|
24
29
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage");
|
|
25
30
|
throw err;
|
|
@@ -28,12 +33,52 @@ export async function getCreditUsage(http: HttpClient): Promise<CreditUsage> {
|
|
|
28
33
|
|
|
29
34
|
export async function getTokenUsage(http: HttpClient): Promise<TokenUsage> {
|
|
30
35
|
try {
|
|
31
|
-
const res = await http.get<{ success: boolean; data?:
|
|
36
|
+
const res = await http.get<{ success: boolean; data?: { remainingTokens?: number; planTokens?: number; billingPeriodStart?: string | null; billingPeriodEnd?: string | null; remaining_tokens?: number; plan_tokens?: number; billing_period_start?: string | null; billing_period_end?: string | null } }>("/v2/team/token-usage");
|
|
32
37
|
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage");
|
|
33
|
-
|
|
38
|
+
const d = res.data.data || (res.data as any);
|
|
39
|
+
return {
|
|
40
|
+
remainingTokens: d.remainingTokens ?? d.remaining_tokens ?? 0,
|
|
41
|
+
planTokens: d.planTokens ?? d.plan_tokens,
|
|
42
|
+
billingPeriodStart: d.billingPeriodStart ?? d.billing_period_start ?? null,
|
|
43
|
+
billingPeriodEnd: d.billingPeriodEnd ?? d.billing_period_end ?? null,
|
|
44
|
+
};
|
|
34
45
|
} catch (err: any) {
|
|
35
46
|
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage");
|
|
36
47
|
throw err;
|
|
37
48
|
}
|
|
38
49
|
}
|
|
39
50
|
|
|
51
|
+
export async function getQueueStatus(http: HttpClient): Promise<QueueStatusResponse> {
|
|
52
|
+
try {
|
|
53
|
+
const res = await http.get<QueueStatusResponse>("/v2/team/queue-status");
|
|
54
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get queue status");
|
|
55
|
+
return res.data;
|
|
56
|
+
} catch (err: any) {
|
|
57
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get queue status");
|
|
58
|
+
throw err;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export async function getCreditUsageHistorical(http: HttpClient, byApiKey?: boolean): Promise<CreditUsageHistoricalResponse> {
|
|
63
|
+
try {
|
|
64
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
65
|
+
const res = await http.get<CreditUsageHistoricalResponse>(`/v2/team/credit-usage/historical${query}`);
|
|
66
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get credit usage historical");
|
|
67
|
+
return res.data;
|
|
68
|
+
} catch (err: any) {
|
|
69
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get credit usage historical");
|
|
70
|
+
throw err;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export async function getTokenUsageHistorical(http: HttpClient, byApiKey?: boolean): Promise<TokenUsageHistoricalResponse> {
|
|
75
|
+
try {
|
|
76
|
+
const query = byApiKey ? "?byApiKey=true" : "";
|
|
77
|
+
const res = await http.get<TokenUsageHistoricalResponse>(`/v2/team/token-usage/historical${query}`);
|
|
78
|
+
if (res.status !== 200 || !res.data?.success) throwForBadResponse(res, "get token usage historical");
|
|
79
|
+
return res.data;
|
|
80
|
+
} catch (err: any) {
|
|
81
|
+
if (err?.isAxiosError) return normalizeAxiosError(err, "get token usage historical");
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
}
|
package/src/v2/types.ts
CHANGED
|
@@ -339,10 +339,40 @@ export interface ConcurrencyCheck {
|
|
|
339
339
|
|
|
340
340
|
export interface CreditUsage {
|
|
341
341
|
remainingCredits: number;
|
|
342
|
+
planCredits?: number;
|
|
343
|
+
billingPeriodStart?: string | null;
|
|
344
|
+
billingPeriodEnd?: string | null;
|
|
342
345
|
}
|
|
343
346
|
|
|
344
347
|
export interface TokenUsage {
|
|
345
348
|
remainingTokens: number;
|
|
349
|
+
planTokens?: number;
|
|
350
|
+
billingPeriodStart?: string | null;
|
|
351
|
+
billingPeriodEnd?: string | null;
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
export interface CreditUsageHistoricalPeriod {
|
|
355
|
+
startDate: string | null;
|
|
356
|
+
endDate: string | null;
|
|
357
|
+
apiKey?: string;
|
|
358
|
+
creditsUsed: number;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
export interface CreditUsageHistoricalResponse {
|
|
362
|
+
success: boolean;
|
|
363
|
+
periods: CreditUsageHistoricalPeriod[];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export interface TokenUsageHistoricalPeriod {
|
|
367
|
+
startDate: string | null;
|
|
368
|
+
endDate: string | null;
|
|
369
|
+
apiKey?: string;
|
|
370
|
+
tokensUsed: number;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
export interface TokenUsageHistoricalResponse {
|
|
374
|
+
success: boolean;
|
|
375
|
+
periods: TokenUsageHistoricalPeriod[];
|
|
346
376
|
}
|
|
347
377
|
|
|
348
378
|
export interface CrawlErrorsResponse {
|
|
@@ -388,3 +418,11 @@ export class SdkError extends Error {
|
|
|
388
418
|
}
|
|
389
419
|
}
|
|
390
420
|
|
|
421
|
+
export interface QueueStatusResponse {
|
|
422
|
+
success: boolean;
|
|
423
|
+
jobsInQueue: number;
|
|
424
|
+
activeJobsInQueue: number;
|
|
425
|
+
waitingJobsInQueue: number;
|
|
426
|
+
maxConcurrency: number;
|
|
427
|
+
mostRecentSuccess: string | null;
|
|
428
|
+
}
|