FlowiseAI/Flowise · critical · Error

Stripe is not initialized

Error message

Stripe is not initialized

What it means

StripeManager is a singleton that lazily constructs the Stripe SDK client inside initialize(), but only when process.env.STRIPE_SECRET_KEY is set. getStripe() returns the cached client and throws this generic Error if the client was never constructed. Because nearly every billing method delegates through getStripe(), this surfaces wherever Stripe is first touched in a misconfigured environment.

Source

Thrown at packages/server/src/StripeManager.ts:30

    private cacheManager: UsageCacheManager

    public static async getInstance(): Promise<StripeManager> {
        if (!StripeManager.instance) {
            StripeManager.instance = new StripeManager()
            await StripeManager.instance.initialize()
        }
        return StripeManager.instance
    }

    private async initialize() {
        if (!this.stripe && process.env.STRIPE_SECRET_KEY) {
            this.stripe = new Stripe(process.env.STRIPE_SECRET_KEY)
        }
        this.cacheManager = await UsageCacheManager.getInstance()
    }

    public getStripe() {
        if (!this.stripe) throw new Error('Stripe is not initialized')
        return this.stripe
    }

    public getSubscriptionObject(subscription: Stripe.Response<Stripe.Subscription>) {
        return {
            customer: subscription.customer,
            status: subscription.status,
            created: subscription.created
        }
    }

    public async getProductIdFromSubscription(subscriptionId: string) {
        if (!subscriptionId || subscriptionId.trim() === '') {
            return ''
        }

        if (!this.stripe) {
            throw new Error('Stripe is not initialized')

View on GitHub (pinned to abe4a8601a)

Solutions

  1. Set STRIPE_SECRET_KEY in the active environment (sk_test_... or sk_live_...) and restart the process so initialize() constructs the client.
  2. Verify the env file is actually loaded for the running NODE_ENV before StripeManager.getInstance() is first called.
  3. If Stripe is optional for your deployment, guard the calling code path so billing routes aren't registered/invoked when the key is absent.
  4. Reset the singleton in tests (or restart) after injecting the key, since the cached instance won't reinitialize on its own.

Example fix

// before
public getStripe() {
    if (!this.stripe) throw new Error('Stripe is not initialized')
    return this.stripe
}

// after: explain the root cause
public getStripe() {
    if (!this.stripe) {
        throw new Error('Stripe is not initialized. Set STRIPE_SECRET_KEY and restart before calling billing APIs.')
    }
    return this.stripe
}
Defensive patterns

Strategy: validation

Validate before calling

// At boot, fail fast if Stripe is required but unconfigured
function requireStripeKey() {
    if (!process.env.STRIPE_SECRET_KEY) {
        throw new Error('STRIPE_SECRET_KEY is not set. Configure it before enabling billing routes.')
    }
}

// only register billing routes when the key is present
if (process.env.STRIPE_SECRET_KEY) {
    app.use('/billing', billingRouter)
} else {
    logger.warn('Stripe disabled: STRIPE_SECRET_KEY not set')
}

Type guard

function isStripeInitialized(mgr: StripeManager): boolean {
    // getStripe throws when uninitialized; probe safely instead
    try {
        mgr.getStripe()
        return true
    } catch {
        return false
    }
}

Try / catch

try {
    const stripe = stripeManager.getStripe()
} catch (err) {
    if (err instanceof Error && err.message === 'Stripe is not initialized') {
        return res.status(StatusCodes.SERVICE_UNAVAILABLE).json({ error: 'Billing is not configured on this server' })
    }
    throw err
}

Prevention

When it happens

Trigger: Any call path reaching getStripe() (getProductIdFromSubscription, createStripeCustomerPortalSession, getAdditionalSeatsQuantity, etc.) while STRIPE_SECRET_KEY is unset, empty, or loaded after getInstance() ran. Running the server with the wrong NODE_ENV that doesn't load the billing env file. Stripe-only code paths invoked in a self-hosted OSS deployment that intentionally omits Stripe.

Common situations: Missing .env entry for STRIPE_SECRET_KEY. Env loaded asynchronously but getInstance() cached an uninitialized instance before vars were available. Copying config between environments and dropping the Stripe key. Feature flags enabling cloud billing code in a non-cloud build.

Related errors


AI-assisted analysis of FlowiseAI/Flowise@abe4a8601a (2026-08-12). Data as JSON: /api/errors/7efd79f0808522c8. Report an issue: GitHub.