@mendable/firecrawl 4.2.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-MKEZ44MR.js → chunk-KCQFB5LN.js} +1 -1
- package/dist/index.cjs +136 -3
- package/dist/index.d.cts +85 -1
- package/dist/index.d.ts +85 -1
- package/dist/index.js +137 -4
- package/dist/{package-7YDUGTZ6.js → package-QFGMHRQZ.js} +1 -1
- package/package.json +1 -1
- package/src/v1/index.ts +138 -0
- package/src/v2/client.ts +11 -1
- package/src/v2/methods/usage.ts +40 -5
- package/src/v2/types.ts +30 -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,7 +755,13 @@ 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;
|
|
@@ -766,6 +777,28 @@ async function getQueueStatus(http) {
|
|
|
766
777
|
throw err;
|
|
767
778
|
}
|
|
768
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
|
+
}
|
|
769
802
|
|
|
770
803
|
// src/v2/watcher.ts
|
|
771
804
|
var import_events = require("events");
|
|
@@ -1073,6 +1106,14 @@ var FirecrawlClient = class {
|
|
|
1073
1106
|
async getTokenUsage() {
|
|
1074
1107
|
return getTokenUsage(this.http);
|
|
1075
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
|
+
}
|
|
1076
1117
|
/** Metrics about the team's scrape queue. */
|
|
1077
1118
|
async getQueueStatus() {
|
|
1078
1119
|
return getQueueStatus(this.http);
|
|
@@ -2348,6 +2389,98 @@ var FirecrawlApp = class {
|
|
|
2348
2389
|
}
|
|
2349
2390
|
return { success: false, error: "Internal server error." };
|
|
2350
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
|
+
}
|
|
2351
2484
|
};
|
|
2352
2485
|
var CrawlWatcher = class extends e {
|
|
2353
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: {
|
|
@@ -552,6 +578,10 @@ declare class FirecrawlClient {
|
|
|
552
578
|
getCreditUsage(): Promise<CreditUsage>;
|
|
553
579
|
/** Recent token usage. */
|
|
554
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>;
|
|
555
585
|
/** Metrics about the team's scrape queue. */
|
|
556
586
|
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
557
587
|
/**
|
|
@@ -1092,6 +1122,44 @@ interface QueueStatusResponse {
|
|
|
1092
1122
|
*/
|
|
1093
1123
|
mostRecentSuccess: string | null;
|
|
1094
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
|
+
}
|
|
1095
1163
|
/**
|
|
1096
1164
|
* Main class for interacting with the Firecrawl API.
|
|
1097
1165
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1362,6 +1430,22 @@ declare class FirecrawlApp {
|
|
|
1362
1430
|
* @returns The current queue status.
|
|
1363
1431
|
*/
|
|
1364
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>;
|
|
1365
1449
|
}
|
|
1366
1450
|
interface CrawlWatcherEvents {
|
|
1367
1451
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1403,4 +1487,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1403
1487
|
get v1(): FirecrawlApp;
|
|
1404
1488
|
}
|
|
1405
1489
|
|
|
1406
|
-
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 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 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: {
|
|
@@ -552,6 +578,10 @@ declare class FirecrawlClient {
|
|
|
552
578
|
getCreditUsage(): Promise<CreditUsage>;
|
|
553
579
|
/** Recent token usage. */
|
|
554
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>;
|
|
555
585
|
/** Metrics about the team's scrape queue. */
|
|
556
586
|
getQueueStatus(): Promise<QueueStatusResponse$1>;
|
|
557
587
|
/**
|
|
@@ -1092,6 +1122,44 @@ interface QueueStatusResponse {
|
|
|
1092
1122
|
*/
|
|
1093
1123
|
mostRecentSuccess: string | null;
|
|
1094
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
|
+
}
|
|
1095
1163
|
/**
|
|
1096
1164
|
* Main class for interacting with the Firecrawl API.
|
|
1097
1165
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -1362,6 +1430,22 @@ declare class FirecrawlApp {
|
|
|
1362
1430
|
* @returns The current queue status.
|
|
1363
1431
|
*/
|
|
1364
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>;
|
|
1365
1449
|
}
|
|
1366
1450
|
interface CrawlWatcherEvents {
|
|
1367
1451
|
document: CustomEvent<FirecrawlDocument<undefined>>;
|
|
@@ -1403,4 +1487,4 @@ declare class Firecrawl extends FirecrawlClient {
|
|
|
1403
1487
|
get v1(): FirecrawlApp;
|
|
1404
1488
|
}
|
|
1405
1489
|
|
|
1406
|
-
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 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 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,7 +639,13 @@ 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;
|
|
@@ -650,6 +661,28 @@ async function getQueueStatus(http) {
|
|
|
650
661
|
throw err;
|
|
651
662
|
}
|
|
652
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
|
+
}
|
|
653
686
|
|
|
654
687
|
// src/v2/watcher.ts
|
|
655
688
|
import { EventEmitter } from "events";
|
|
@@ -957,6 +990,14 @@ var FirecrawlClient = class {
|
|
|
957
990
|
async getTokenUsage() {
|
|
958
991
|
return getTokenUsage(this.http);
|
|
959
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
|
+
}
|
|
960
1001
|
/** Metrics about the team's scrape queue. */
|
|
961
1002
|
async getQueueStatus() {
|
|
962
1003
|
return getQueueStatus(this.http);
|
|
@@ -1006,7 +1047,7 @@ var FirecrawlApp = class {
|
|
|
1006
1047
|
if (typeof process !== "undefined" && process.env && process.env.npm_package_version) {
|
|
1007
1048
|
return process.env.npm_package_version;
|
|
1008
1049
|
}
|
|
1009
|
-
const packageJson = await import("./package-
|
|
1050
|
+
const packageJson = await import("./package-QFGMHRQZ.js");
|
|
1010
1051
|
return packageJson.default.version;
|
|
1011
1052
|
} catch (error) {
|
|
1012
1053
|
const isTest = typeof process !== "undefined" && (process.env.JEST_WORKER_ID != null || false);
|
|
@@ -2232,6 +2273,98 @@ var FirecrawlApp = class {
|
|
|
2232
2273
|
}
|
|
2233
2274
|
return { success: false, error: "Internal server error." };
|
|
2234
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
|
+
}
|
|
2235
2368
|
};
|
|
2236
2369
|
var CrawlWatcher = class extends e {
|
|
2237
2370
|
ws;
|
package/package.json
CHANGED
package/src/v1/index.ts
CHANGED
|
@@ -584,6 +584,48 @@ export interface QueueStatusResponse {
|
|
|
584
584
|
mostRecentSuccess: string | null;
|
|
585
585
|
}
|
|
586
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
|
+
|
|
587
629
|
/**
|
|
588
630
|
* Main class for interacting with the Firecrawl API.
|
|
589
631
|
* Provides methods for scraping, searching, crawling, and mapping web content.
|
|
@@ -2070,6 +2112,102 @@ export default class FirecrawlApp {
|
|
|
2070
2112
|
}
|
|
2071
2113
|
return { success: false, error: "Internal server error." };
|
|
2072
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
|
+
}
|
|
2073
2211
|
}
|
|
2074
2212
|
|
|
2075
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, getQueueStatus, 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,16 @@ 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
|
+
|
|
272
282
|
/** Metrics about the team's scrape queue. */
|
|
273
283
|
async getQueueStatus() {
|
|
274
284
|
return getQueueStatus(this.http);
|
package/src/v2/methods/usage.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConcurrencyCheck, CreditUsage, QueueStatusResponse, 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,9 +33,15 @@ 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;
|
|
@@ -47,3 +58,27 @@ export async function getQueueStatus(http: HttpClient): Promise<QueueStatusRespo
|
|
|
47
58
|
throw err;
|
|
48
59
|
}
|
|
49
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 {
|