{"record":{"id":"d3ff669f92c1dcd3","repo":"Mintplex-Labs/anything-llm","slug":"no-openai-image-generation-api-key-was-set","errorCode":null,"errorMessage":"No OpenAI image generation API key was set.","messagePattern":"No OpenAI image generation API key was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/ImageGenerators/openAi/index.js","lineNumber":6,"sourceCode":"const { BaseImageGenerator } = require(\"../base\");\n\nclass OpenAiImageGenerator extends BaseImageGenerator {\n  constructor() {\n    if (!process.env.IMAGE_GEN_OPENAI_KEY)\n      throw new Error(\"No OpenAI image generation API key was set.\");\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    // gpt-image-1 is the default since OpenAI has deprecated the dall-e models.\n    // It does not support 512x512, so base.js upsizes to the nearest supported\n    // square (1024x1024) automatically.\n    super({\n      client: new OpenAIApi({\n        apiKey: process.env.IMAGE_GEN_OPENAI_KEY,\n      }),\n      model: process.env.IMAGE_GEN_MODEL_PREF || \"gpt-image-1\",\n      className: \"OpenAiImageGenerator\",\n    });\n  }\n\n  imageFieldName(count) {\n    return count > 1 ? \"image[]\" : \"image\";\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/ImageGenerators/openAi/index.js#L1-L24","documentation":"The OpenAiImageGenerator constructor throws immediately when IMAGE_GEN_OPENAI_KEY is unset or empty. Note this is a separate variable from the chat/embedding OPEN_AI_KEY — image generation has its own credential. The key instantiates the OpenAI SDK client (default model gpt-image-1), so selection fails fast at construction.","triggerScenarios":"Choosing OpenAI image generation while IMAGE_GEN_OPENAI_KEY is unset; setting only OPEN_AI_KEY and assuming image gen shares it; the key was added after the process started; docker env not propagated.","commonSituations":"Users who configured the OpenAI chat provider and expected image generation to reuse the same key; org keys restricted from the images API.","solutions":["Set IMAGE_GEN_OPENAI_KEY (not OPEN_AI_KEY) in .env to a valid OpenAI key.","Confirm the key's project/org has access to the images API and gpt-image-1.","Restart the server / recreate the container after saving.","Check the variable spelling and value for stray quotes or spaces."],"exampleFix":"# .env — before\nIMAGE_GEN_ENGINE=openai\nOPEN_AI_KEY=sk-...\n\n# .env — after\nIMAGE_GEN_ENGINE=openai\nOPEN_AI_KEY=sk-...\nIMAGE_GEN_OPENAI_KEY=sk-proj-...","handlingStrategy":"validation","validationCode":"if (!process.env.IMAGE_GEN_OPENAI_KEY) {\n  throw new Error(\n    \"OpenAI image engine selected but IMAGE_GEN_OPENAI_KEY is missing (this is separate from OPEN_AI_KEY).\"\n  );\n}\nconst { OpenAiImageGenerator } = require(\"server/utils/ImageGenerators/openAi\");\nconst generator = new OpenAiImageGenerator();","typeGuard":"function hasOpenAiImageGenConfig(env = process.env) {\n  return (\n    typeof env.IMAGE_GEN_OPENAI_KEY === \"string\" &&\n    env.IMAGE_GEN_OPENAI_KEY.length > 0\n  );\n}","tryCatchPattern":"try {\n  new OpenAiImageGenerator();\n} catch (err) {\n  if (err.message === \"No OpenAI image generation API key was set.\") {\n    // route the user to image-gen settings; do not assume OPEN_AI_KEY covers it\n  }\n}","preventionTips":["Document that image generation uses IMAGE_GEN_OPENAI_KEY, distinct from the chat/embedding OPEN_AI_KEY.","Env-check the active image engine's credentials at boot.","Restart/recreate the process after rotating keys."],"tags":["openai","image-generation","configuration","environment-variables","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}