This commit is contained in:
Nicolas 2025-01-17 23:47:22 -03:00
parent 260a726f37
commit 9cd48d7f73
4 changed files with 5 additions and 1 deletions

View File

@ -704,6 +704,7 @@ export async function performExtraction(
scrapeOptions: request, scrapeOptions: request,
origin: request.origin ?? "api", origin: request.origin ?? "api",
num_tokens: totalTokensUsed, num_tokens: totalTokensUsed,
tokens_billed: tokensToBill,
}).then(() => { }).then(() => {
updateExtract(extractId, { updateExtract(extractId, {
status: "completed", status: "completed",

View File

@ -12,7 +12,7 @@ const tokenPerCharacter = 4;
const baseTokenCost = 200; const baseTokenCost = 200;
export function calculateFinalResultCost(data: any): number { export function calculateFinalResultCost(data: any): number {
return JSON.stringify(data).length / tokenPerCharacter + baseTokenCost; return Math.floor((JSON.stringify(data).length / tokenPerCharacter) + baseTokenCost);
} }
export function estimateTotalCost(tokenUsage: TokenUsage[]): number { export function estimateTotalCost(tokenUsage: TokenUsage[]): number {

View File

@ -59,6 +59,7 @@ export async function logJob(job: FirecrawlJob, force: boolean = false) {
num_tokens: job.num_tokens, num_tokens: job.num_tokens,
retry: !!job.retry, retry: !!job.retry,
crawl_id: job.crawl_id, crawl_id: job.crawl_id,
tokens_billed: job.tokens_billed,
}; };
if (force) { if (force) {
@ -128,6 +129,7 @@ export async function logJob(job: FirecrawlJob, force: boolean = false) {
origin: job.origin, origin: job.origin,
num_tokens: job.num_tokens, num_tokens: job.num_tokens,
retry: job.retry, retry: job.retry,
tokens_billed: job.tokens_billed,
}, },
}; };
if (job.mode !== "single_urls") { if (job.mode !== "single_urls") {

View File

@ -87,6 +87,7 @@ export interface FirecrawlJob {
num_tokens?: number; num_tokens?: number;
retry?: boolean; retry?: boolean;
crawl_id?: string; crawl_id?: string;
tokens_billed?: number;
} }
export interface FirecrawlScrapeResponse { export interface FirecrawlScrapeResponse {