Skip to content

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

feat(api): bill search+scrape scrape credits against SEARCH_CREDITS (#3738)

firecrawl-spring[bot]796a688cd44b
diff --git a/apps/api/src/services/worker/scrape-worker.ts b/apps/api/src/services/worker/scrape-worker.ts
index adc009944..fa084dc01 100644
--- a/apps/api/src/services/worker/scrape-worker.ts
+++ b/apps/api/src/services/worker/scrape-worker.ts
@@ -34,7 +34,10 @@ import {
resolveBillingMetadata,
toAutumnBillingProperties,
} from "../billing/types";
-import { autumnService } from "../autumn/autumn.service";
+import {
+ autumnService,
+ featureIdForBillingEndpoint,
+} from "../autumn/autumn.service";
import {
_addScrapeJobToBullMQ,
addScrapeJob,
@@ -118,6 +121,10 @@ async function billScrapeJob(
...toAutumnBillingProperties(billing),
apiKeyId: job.data.apiKeyId,
};
+ // Scrapes initiated by a search (billing.endpoint === "search", e.g. search +
+ // scrapeOptions) are metered against SEARCH_CREDITS, matching the search
+ // request's own credits. Standalone scrapes stay on CREDITS.
+ const featureId = featureIdForBillingEndpoint(billing.endpoint);
let trackedInRequest = false;
if (job.data.is_scrape !== true && !job.data.internalOptions?.bypassBilling) {
@@ -141,6 +148,7 @@ async function billScrapeJob(
value: creditsToBeBilled,
properties: autumnProperties,
requestScoped: true,
+ featureId,
});
const billingJobId = uuidv7();
logger.debug(
@@ -184,6 +192,7 @@ async function billScrapeJob(
teamId: job.data.team_id,
value: creditsToBeBilled,
properties: autumnProperties,
+ featureId,
});
}
captureExceptionWithZdrCheck(error, {