Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Fix search endpoint PDF billing when parsePDF=false (#1806)

devin-ai-integration[bot]10796b0db07c
diff --git a/apps/api/src/__tests__/snips/billing.test.ts b/apps/api/src/__tests__/snips/billing.test.ts
index 959eca36c..f1f45d51f 100644
--- a/apps/api/src/__tests__/snips/billing.test.ts
+++ b/apps/api/src/__tests__/snips/billing.test.ts
@@ -240,6 +240,31 @@ describe("Billing tests", () => {
expect(rc1 - rc2).toBe(shouldUse);
}, 600000);
+ it.concurrent("bills search with parsePDF=false correctly", async () => {
+ const identity = await idmux({
+ name: "billing/bills search with parsePDF=false correctly",
+ credits: 100,
+ });
+
+ const rc1 = (await creditUsage(identity)).remaining_credits;
+
+ const results = await search({
+ query: "firecrawl filetype:pdf",
+ scrapeOptions: {
+ formats: ["markdown"],
+ parsePDF: false,
+ },
+ }, identity);
+
+ await sleepForBatchBilling();
+
+ const rc2 = (await creditUsage(identity)).remaining_credits;
+
+ const expectedCredits = results.length;
+
+ expect(rc1 - rc2).toBe(expectedCredits);
+ }, 600000);
+
it.concurrent("bills extract correctly", async () => {
const identity = await idmux({
name: "billing/bills extract correctly",
diff --git a/apps/api/src/controllers/v1/search.ts b/apps/api/src/controllers/v1/search.ts
index bd1d89801..82efbcfb3 100644
--- a/apps/api/src/controllers/v1/search.ts
+++ b/apps/api/src/controllers/v1/search.ts
@@ -326,7 +326,7 @@ export async function searchController(
{ teamId: req.auth.team_id, bypassBilling: true, zeroDataRetention: false },
matchingDocWithCost.document,
matchingDocWithCost.costTracking,
- req.acuc.flags,
+ req.acuc?.flags ?? null,
);
} else {
return 1;
diff --git a/apps/api/src/lib/scrape-billing.ts b/apps/api/src/lib/scrape-billing.ts
index 2c2a9077f..ef5be7554 100644
--- a/apps/api/src/lib/scrape-billing.ts
+++ b/apps/api/src/lib/scrape-billing.ts
@@ -32,7 +32,7 @@ export async function calculateCreditsToBeBilled(options: ScrapeOptions, interna
creditsToBeBilled += (flags?.zdrCost ?? 1);
}
- if (document.metadata?.numPages !== undefined && document.metadata.numPages > 1) {
+ if (options.parsePDF && document.metadata?.numPages !== undefined && document.metadata.numPages > 1) {
creditsToBeBilled += creditsPerPDFPage * (document.metadata.numPages - 1);
}