{"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":"validation","errorClass":"Error","httpStatus":null,"severity":"critical","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/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/EmbeddingEngines/openAi/index.js#L1-L23","documentation":"Thrown by the OpenAiEmbedder constructor when process.env.OPEN_AI_KEY is falsy. The openai SDK client is built with only the apiKey (no custom baseURL), so an empty key means every request would 401; construction aborts immediately. The default model falls back to text-embedding-ada-002 but the key has no default.","triggerScenarios":"Selecting the OpenAI embedding engine while OPEN_AI_KEY is unset/empty; constructing `new OpenAiEmbedder()` before env load. The check on line 5 precedes client creation.","commonSituations":"Fresh OpenAI setup; key revoked/rotated on platform.openai.com but not in .env; secret not injected into the container/CI; env var typo (OPENAI_API_KEY vs OPEN_AI_KEY — AnythingLLM uses the underscore form); billing paused so the key was deactivated.","solutions":["Set OPEN_AI_KEY (note the underscore form AnythingLLM expects) in .env to a valid key","Confirm the key is active and funded at platform.openai.com","Reload AnythingLLM env after the edit"],"exampleFix":"// before\n// OPEN_AI_KEY unset (common mistake: using OPENAI_API_KEY instead)\n\n// after\nOPEN_AI_KEY=sk-...\nEMBEDDING_MODEL_PREF=text-embedding-3-small","handlingStrategy":"validation","validationCode":"function hasOpenAiKey(env = process.env) {\n  return typeof env.OPEN_AI_KEY === 'string' &&\n         env.OPEN_AI_KEY.trim().length > 0;\n}\nif (!hasOpenAiKey()) {\n  throw new Error('Missing OPEN_AI_KEY (note the underscore form AnythingLLM uses).');\n}","typeGuard":"function isOpenAiKey(v) {\n  return typeof v === 'string' && /^sk-[A-Za-z0-9_-]{20,}$/.test(v);\n}","tryCatchPattern":null,"preventionTips":["Use AnythingLLM's exact var name OPEN_AI_KEY, not OPENAI_API_KEY.","Confirm the key is active and funded at platform.openai.com.","Validate env at boot for the selected engine."],"tags":["openai","embedding","config","env","auth","constructor"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}