Skip to content

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

feat(billing): gate auto-recharge behind AUTO_RECHARGE_ENABLED env flag (#3263)

firecrawl-spring[bot]eb9bcc82f5fb
diff --git a/apps/api/src/config.ts b/apps/api/src/config.ts
index 6b04dc208..91e3cee12 100644
--- a/apps/api/src/config.ts
+++ b/apps/api/src/config.ts
@@ -231,6 +231,9 @@ const configSchema = z.object({
SENTRY_ENVIRONMENT: z.string().default("production"),
NUQ_POD_NAME: z.string().default("main"),
+ // Billing
+ AUTO_RECHARGE_ENABLED: z.stringbool().default(false),
+
// Miscellaneous
IDMUX_URL: z.string().optional(),
GITHUB_RUN_NUMBER: z.string().optional(),
diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts
index f951620cc..d67a08ee8 100644
--- a/apps/api/src/services/billing/credit_billing.ts
+++ b/apps/api/src/services/billing/credit_billing.ts
@@ -11,6 +11,7 @@ import { queueBillingOperation } from "./batch_billing";
import { autumnService } from "../autumn/autumn.service";
import { toAutumnBillingProperties, type BillingMetadata } from "./types";
import type { Logger } from "winston";
+import { config } from "../../config";
/**
* If you do not know the subscription_id in the current context, pass subscription_id as undefined.
@@ -92,8 +93,7 @@ function evaluateTeamCredits(
credits: number,
isAutoRechargeEnabled: boolean,
) {
- const allowOverages =
- chunk.price_should_be_graceful && isAutoRechargeEnabled;
+ const allowOverages = chunk.price_should_be_graceful && isAutoRechargeEnabled;
const remainingCredits = allowOverages
? chunk.remaining_credits + chunk.price_credits
: chunk.remaining_credits;
@@ -173,6 +173,7 @@ async function supaCheckTeamCredits(
} = evaluateTeamCredits(chunk, credits, isAutoRechargeEnabled);
if (
+ config.AUTO_RECHARGE_ENABLED &&
isAutoRechargeEnabled &&
chunk.remaining_credits < autoRechargeThreshold &&
!chunk.is_extract