{"record":{"id":"ce7bdfbf3d5da9dc","repo":"Mintplex-Labs/anything-llm","slug":"no-openai-api-key-was-set-ce7bdf","errorCode":null,"errorMessage":"No OpenAI API key was set.","messagePattern":"No OpenAI API key was set\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/SpeechToText/openAi/index.js","lineNumber":3,"sourceCode":"class OpenAiSTT {\n  constructor() {\n    if (!process.env.OPEN_AI_KEY) throw new Error(\"No OpenAI API key was set.\");\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.openai = new OpenAIApi({\n      apiKey: process.env.OPEN_AI_KEY,\n    });\n    this.model = process.env.STT_OPEN_AI_MODEL ?? \"whisper-1\";\n  }\n\n  /**\n   * Transcribes an audio buffer to text using the OpenAI STT service.\n   * @param {Buffer} audioBuffer - The audio buffer to be transcribed.\n   * @param {string} filename - Original filename, used to hint the audio container/codec to OpenAI.\n   * @returns {Promise<string>} The transcribed text.\n   */\n  async transcribe(audioBuffer, filename = \"audio.webm\") {\n    const { toFile } = require(\"openai\");\n    const file = await toFile(audioBuffer, filename);\n    const result = await this.openai.audio.transcriptions.create({\n      file,","sourceCodeStart":1,"sourceCodeEnd":21,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/SpeechToText/openAi/index.js#L1-L21","documentation":"Thrown by the OpenAiSTT constructor when process.env.OPEN_AI_KEY is falsy. Note this uses the generic OPEN_AI_KEY, not a dedicated STT key, so it shares the main OpenAI key. The class builds an OpenAI client for the Whisper transcription API.","triggerScenarios":"STT_PROVIDER=openai is set but OPEN_AI_KEY is missing/empty; the key was removed or renamed; the process was not restarted after adding it.","commonSituations":"Fresh install without OPEN_AI_KEY; key rotated and the new one not added; Docker env not passed through.","solutions":["Add OPEN_AI_KEY=<sk-...> to .env and restart.","Confirm the exact name is OPEN_AI_KEY (shared with other OpenAI features), not STT_OPEN_AI_KEY.","In Docker, pass the variable to the container.","Optionally set STT_OPEN_AI_MODEL (defaults to whisper-1)."],"exampleFix":"# before\nSTT_PROVIDER=openai\n# OPEN_AI_KEY missing\n\n# after\nSTT_PROVIDER=openai\nOPEN_AI_KEY=sk-xxxxxxxx","handlingStrategy":"validation","validationCode":"if (process.env.STT_PROVIDER === \"openai\" && !process.env.OPEN_AI_KEY) {\n  throw new Error(\"STT_PROVIDER is 'openai' but OPEN_AI_KEY is not set.\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  return new OpenAiSTT();\n} catch (e) {\n  if (/No OpenAI API key/i.test(e.message)) {\n    logger.error(\"Set OPEN_AI_KEY (shared) in .env, then restart.\");\n  }\n  throw e;\n}","preventionTips":["Remember STT uses OPEN_AI_KEY, not a dedicated STT key.","Validate OPEN_AI_KEY presence whenever STT_PROVIDER=openai.","Restart the process after setting the key."],"tags":["stt","openai","configuration","environment","credentials"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}