{"record":{"id":"7280421e0ebbf282","repo":"Mintplex-Labs/anything-llm","slug":"no-openai-api-key-was-set-728042","errorCode":null,"errorMessage":"No OpenAI API key was set.","messagePattern":"No OpenAI API key was set\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/utils/EmbeddingEngines/openAi/index.js","lineNumber":5,"sourceCode":"const { toChunks, reportEmbeddingProgress } = require(\"../../helpers\");\n\nclass OpenAiEmbedder {\n  constructor() {\n    if (!process.env.OPEN_AI_KEY) throw new Error(\"No OpenAI API key was set.\");\n    this.className = \"OpenAiEmbedder\";\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.openai = new OpenAIApi({\n      apiKey: process.env.OPEN_AI_KEY,\n    });\n    this.model = process.env.EMBEDDING_MODEL_PREF || \"text-embedding-ada-002\";\n\n    // Limit of how many strings we can process in a single pass to stay with resource or network limits\n    this.maxConcurrentChunks = 500;\n\n    // https://platform.openai.com/docs/guides/embeddings/embedding-models\n    this.embeddingMaxChunkLength = 8_191;\n  }\n\n  log(text, ...args) {\n    console.log(`\\x1b[36m[${this.className}]\\x1b[0m ${text}`, ...args);\n  }\n","sourceCodeStart":1,"sourceCodeEnd":23,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/EmbeddingEngines/openAi/index.js#L1-L23","documentation":"The OpenAiEmbedder constructor throws immediately when the OPEN_AI_KEY environment variable is unset or empty. The key is required to instantiate the OpenAI SDK client used for /v1/embeddings calls; there is no default or fallback, so engine selection fails fast at construction time.","triggerScenarios":"Selecting the OpenAI embedding engine while OPEN_AI_KEY is unset; adding the key after the process started without a restart; a typo in the variable name; docker run without the -e flag / env_file entry; the key was cleared by re-saving provider settings.","commonSituations":"New installs that previously only used a local LLM; key rotation where .env was updated on one node but not others; deployments that copy .env selectively.","solutions":["Set OPEN_AI_KEY in server .env (or via the OpenAI settings in the UI) to a valid sk-... key.","Restart the server or recreate the container so the env is loaded.","Verify the key works: curl https://api.openai.com/v1/embeddings with the Authorization header.","Check the .env line for quotes, spaces, or an = typo."],"exampleFix":"# .env — before\nEMBEDDING_ENGINE=openai\n\n# .env — after\nEMBEDDING_ENGINE=openai\nOPEN_AI_KEY=sk-proj-...","handlingStrategy":"validation","validationCode":"if (!process.env.OPEN_AI_KEY) {\n  throw new Error(\n    \"OpenAI embedder selected but OPEN_AI_KEY is missing — set it before use.\"\n  );\n}\nconst { OpenAiEmbedder } = require(\"server/utils/EmbeddingEngines/openAi\");\nconst embedder = new OpenAiEmbedder();","typeGuard":"function hasOpenAiEmbedderConfig(env = process.env) {\n  return typeof env.OPEN_AI_KEY === \"string\" && env.OPEN_AI_KEY.length > 0;\n}","tryCatchPattern":"try {\n  new OpenAiEmbedder();\n} catch (err) {\n  if (err.message === \"No OpenAI API key was set.\") {\n    // render a settings error pointing at OPEN_AI_KEY instead of crashing the job\n  }\n}","preventionTips":["Check provider-specific env vars at boot for whichever engine is selected.","After key rotation, update .env on every node and restart.","Treat constructor throws from embedder factories as configuration errors, not runtime failures."],"tags":["openai","embeddings","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"}