danny-avila/LibreChat · error · Error

Missing FLUX_API_KEY environment variable.

Error message

Missing FLUX_API_KEY environment variable.

What it means

Thrown by FluxAPI.getApiKey() when `process.env.FLUX_API_KEY` is falsy and `this.override` is false. Unlike DALLE3 there is only one accepted env var. getApiKey is called from _call() via `this.apiKey || this.getApiKey()`, so it fires at request time, not at construction.

Source

Thrown at api/app/clients/tools/structured/FluxAPI.js:170

  }

  getAxiosConfig() {
    const config = {};
    return applyAxiosProxyConfig(config, this.baseUrl);
  }

  /** @param {Object|string} value */
  getDetails(value) {
    if (typeof value === 'string') {
      return value;
    }
    return JSON.stringify(value, null, 2);
  }

  getApiKey() {
    const apiKey = process.env.FLUX_API_KEY || '';
    if (!apiKey && !this.override) {
      throw new Error('Missing FLUX_API_KEY environment variable.');
    }
    return apiKey;
  }

  wrapInMarkdown(imageUrl) {
    const serverDomain = process.env.DOMAIN_SERVER || 'http://localhost:3080';
    return `![generated image](${serverDomain}${imageUrl})`;
  }

  returnValue(value) {
    if (this.isAgent === true && typeof value === 'string') {
      return [value, {}];
    } else if (this.isAgent === true && typeof value === 'object') {
      if (Array.isArray(value)) {
        return value;
      }
      return [displayMessage, value];
    }

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Set `FLUX_API_KEY=<key>` in .env and restart the server.
  2. Confirm the variable name is exactly FLUX_API_KEY (no underscores moved) with `printenv FLUX_API_KEY`.
  3. Pass `override: true` at construction if you are only registering the tool for the catalog and will not call it.
  4. If running tests, inject the key via the constructor or mock getApiKey rather than relying on a real secret.

Example fix

// before
const t = new FluxAPI({});
await t._call({ prompt: 'a fox' }); // throws in getApiKey()

// after
// .env: FLUX_API_KEY=<bfl-key>
const t = new FluxAPI({ override: true }); // catalog-only
Defensive patterns

Strategy: validation

Validate before calling

function resolveFluxKey() {
  const key = process.env.FLUX_API_KEY;
  if (!key) throw new Error('Set FLUX_API_KEY before invoking the FluxAPI tool.');
  return key;
}

Type guard

function hasFluxKey() {
  return Boolean(process.env.FLUX_API_KEY);
}

Try / catch

try {
  await fluxTool.invoke({ prompt });
} catch (e) {
  if (/Missing FLUX_API_KEY/.test(e.message)) return 'Flux image generation is not configured.';
  throw e;
}

Prevention

When it happens

Trigger: Calling FluxAPI._call() (generate / list_finetunes / generate_finetuned) on an instance whose `this.apiKey` was never set and FLUX_API_KEY is absent from the environment, with override not set to true.

Common situations: Enabled the Flux image tool without provisioning a fal.ai / BFL API key; env var named FLUX_KEY or FLUXAPI_KEY by mistake; secret injected at deploy but the process was started before the secret was available; running the tool in a test without mocking getApiKey.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/191cc73f3a3ff5c5. Report an issue: GitHub.