Skip to content

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

fix(billing): use Autumn for browser session TTL credit checks (#3269)

firecrawl-spring[bot]7e6bbef3ea30
diff --git a/apps/api/src/controllers/v2/browser.ts b/apps/api/src/controllers/v2/browser.ts
index 71900c03d..8712e7865 100644
--- a/apps/api/src/controllers/v2/browser.ts
+++ b/apps/api/src/controllers/v2/browser.ts
@@ -32,6 +32,7 @@ import {
INTERACT_CREDITS_PER_HOUR,
calculateBrowserSessionCredits,
} from "../../lib/browser-billing";
+import { autumnService } from "../../services/autumn/autumn.service";
// ---------------------------------------------------------------------------
// Zod schemas
@@ -225,10 +226,15 @@ export async function browserCreateController(
// 0a. Check if team has enough credits for the full TTL
const estimatedCredits = calculateBrowserSessionCredits(ttl * 1000);
- if (req.acuc && req.acuc.remaining_credits < estimatedCredits) {
+ const autumnAllowed = await autumnService.checkCredits({
+ teamId: req.auth.team_id,
+ value: estimatedCredits,
+ properties: { source: "browserCreate", path: req.path },
+ });
+
+ if (autumnAllowed === false) {
logger.warn("Insufficient credits for browser session TTL", {
estimatedCredits,
- remainingCredits: req.acuc.remaining_credits,
ttl,
});
return res.status(402).json({
diff --git a/apps/api/src/controllers/v2/scrape-browser.ts b/apps/api/src/controllers/v2/scrape-browser.ts
index bd7cb604b..ebbcf4fd9 100644
--- a/apps/api/src/controllers/v2/scrape-browser.ts
+++ b/apps/api/src/controllers/v2/scrape-browser.ts
@@ -50,6 +50,7 @@ import {
INTERACT_CREDITS_PER_HOUR,
calculateBrowserSessionCredits,
} from "../../lib/browser-billing";
+import { autumnService } from "../../services/autumn/autumn.service";
// ---------------------------------------------------------------------------
// Schemas
@@ -354,11 +355,14 @@ export async function scrapeStopInteractiveBrowserController(
invalidateActiveBrowserSessionCount(session.team_id).catch(() => {});
removeConcurrencyLimitActiveJob(session.team_id, session.id).catch(error => {
- logger.error("Failed to remove concurrency limiter entry for browser session", {
- error,
- sessionId: session.id,
- teamId: session.team_id,
- });
+ logger.error(
+ "Failed to remove concurrency limiter entry for browser session",
+ {
+ error,
+ sessionId: session.id,
+ teamId: session.team_id,
+ },
+ );
});
if (!claimed) {
@@ -462,7 +466,13 @@ async function createSessionForScrape(
// Credit check (uses base rate — actual billing may be higher if prompts are used)
const estimatedCredits = calculateBrowserSessionCredits(ttl * 1000);
- if (req.acuc && req.acuc.remaining_credits < estimatedCredits) {
+ const autumnAllowed = await autumnService.checkCredits({
+ teamId: req.auth.team_id,
+ value: estimatedCredits,
+ properties: { source: "scrapeBrowserCreate", path: req.path },
+ });
+
+ if (autumnAllowed === false) {
return {
status: 402,
body: {