{"record":{"id":"191cc73f3a3ff5c5","repo":"danny-avila/LibreChat","slug":"missing-flux-api-key-environment-variable","errorCode":null,"errorMessage":"Missing FLUX_API_KEY environment variable.","messagePattern":"Missing FLUX_API_KEY environment variable\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"api/app/clients/tools/structured/FluxAPI.js","lineNumber":170,"sourceCode":"  }\n\n  getAxiosConfig() {\n    const config = {};\n    return applyAxiosProxyConfig(config, this.baseUrl);\n  }\n\n  /** @param {Object|string} value */\n  getDetails(value) {\n    if (typeof value === 'string') {\n      return value;\n    }\n    return JSON.stringify(value, null, 2);\n  }\n\n  getApiKey() {\n    const apiKey = process.env.FLUX_API_KEY || '';\n    if (!apiKey && !this.override) {\n      throw new Error('Missing FLUX_API_KEY environment variable.');\n    }\n    return apiKey;\n  }\n\n  wrapInMarkdown(imageUrl) {\n    const serverDomain = process.env.DOMAIN_SERVER || 'http://localhost:3080';\n    return `![generated image](${serverDomain}${imageUrl})`;\n  }\n\n  returnValue(value) {\n    if (this.isAgent === true && typeof value === 'string') {\n      return [value, {}];\n    } else if (this.isAgent === true && typeof value === 'object') {\n      if (Array.isArray(value)) {\n        return value;\n      }\n      return [displayMessage, value];\n    }","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/app/clients/tools/structured/FluxAPI.js#L152-L188","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set `FLUX_API_KEY=<key>` in .env and restart the server.","Confirm the variable name is exactly FLUX_API_KEY (no underscores moved) with `printenv FLUX_API_KEY`.","Pass `override: true` at construction if you are only registering the tool for the catalog and will not call it.","If running tests, inject the key via the constructor or mock getApiKey rather than relying on a real secret."],"exampleFix":"// before\nconst t = new FluxAPI({});\nawait t._call({ prompt: 'a fox' }); // throws in getApiKey()\n\n// after\n// .env: FLUX_API_KEY=<bfl-key>\nconst t = new FluxAPI({ override: true }); // catalog-only","handlingStrategy":"validation","validationCode":"function resolveFluxKey() {\n  const key = process.env.FLUX_API_KEY;\n  if (!key) throw new Error('Set FLUX_API_KEY before invoking the FluxAPI tool.');\n  return key;\n}","typeGuard":"function hasFluxKey() {\n  return Boolean(process.env.FLUX_API_KEY);\n}","tryCatchPattern":"try {\n  await fluxTool.invoke({ prompt });\n} catch (e) {\n  if (/Missing FLUX_API_KEY/.test(e.message)) return 'Flux image generation is not configured.';\n  throw e;\n}","preventionTips":["Use the exact var name FLUX_API_KEY.","Validate all tool keys at startup.","Mock getApiKey in unit tests instead of relying on a real secret."],"tags":["fluxapi","config","environment-variables","api-key"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}