Skip to content

Commit eb9bcc8

Browse files
feat(billing): gate auto-recharge behind AUTO_RECHARGE_ENABLED env flag (firecrawl#3263)
Add AUTO_RECHARGE_ENABLED environment variable (defaults to false) to globally disable the auto-recharge flow. When unset or false, auto-recharge will not trigger regardless of per-team database settings. Set AUTO_RECHARGE_ENABLED=true to re-enable the previous behavior. Co-authored-by: firecrawl-spring[bot] <254786068+firecrawl-spring[bot]@users.noreply.github.com> Co-authored-by: micahstairs <micah@sideguide.dev>
1 parent d90b1cd commit eb9bcc8

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

apps/api/src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ const configSchema = z.object({
231231
SENTRY_ENVIRONMENT: z.string().default("production"),
232232
NUQ_POD_NAME: z.string().default("main"),
233233

234+
// Billing
235+
AUTO_RECHARGE_ENABLED: z.stringbool().default(false),
236+
234237
// Miscellaneous
235238
IDMUX_URL: z.string().optional(),
236239
GITHUB_RUN_NUMBER: z.string().optional(),

apps/api/src/services/billing/credit_billing.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { queueBillingOperation } from "./batch_billing";
1111
import { autumnService } from "../autumn/autumn.service";
1212
import { toAutumnBillingProperties, type BillingMetadata } from "./types";
1313
import type { Logger } from "winston";
14+
import { config } from "../../config";
1415

1516
/**
1617
* If you do not know the subscription_id in the current context, pass subscription_id as undefined.
@@ -92,8 +93,7 @@ function evaluateTeamCredits(
9293
credits: number,
9394
isAutoRechargeEnabled: boolean,
9495
) {
95-
const allowOverages =
96-
chunk.price_should_be_graceful && isAutoRechargeEnabled;
96+
const allowOverages = chunk.price_should_be_graceful && isAutoRechargeEnabled;
9797
const remainingCredits = allowOverages
9898
? chunk.remaining_credits + chunk.price_credits
9999
: chunk.remaining_credits;
@@ -173,6 +173,7 @@ async function supaCheckTeamCredits(
173173
} = evaluateTeamCredits(chunk, credits, isAutoRechargeEnabled);
174174

175175
if (
176+
config.AUTO_RECHARGE_ENABLED &&
176177
isAutoRechargeEnabled &&
177178
chunk.remaining_credits < autoRechargeThreshold &&
178179
!chunk.is_extract

0 commit comments

Comments
 (0)