{"record":{"id":"1b170adb51bba041","repo":"Mintplex-Labs/anything-llm","slug":"no-openai-api-key-was-set-1b170a","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/TextToSpeech/openAi/index.js","lineNumber":4,"sourceCode":"class OpenAiTTS {\n  constructor() {\n    if (!process.env.TTS_OPEN_AI_KEY)\n      throw new Error(\"No OpenAI API key was set.\");\n    const { OpenAI: OpenAIApi } = require(\"openai\");\n    this.openai = new OpenAIApi({\n      apiKey: process.env.TTS_OPEN_AI_KEY,\n    });\n    this.voice = process.env.TTS_OPEN_AI_VOICE_MODEL ?? \"alloy\";\n  }\n\n  async ttsBuffer(textInput) {\n    try {\n      const result = await this.openai.audio.speech.create({\n        model: \"tts-1\",\n        voice: this.voice,\n        input: textInput,\n      });\n      return Buffer.from(await result.arrayBuffer());\n    } catch (e) {\n      console.error(e);\n    }","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/TextToSpeech/openAi/index.js#L1-L22","documentation":"Thrown by the OpenAiTTS constructor when process.env.TTS_OPEN_AI_KEY is falsy. Note this uses a dedicated TTS_OPEN_AI_KEY, distinct from the main OPEN_AI_KEY used by STT. The class builds an OpenAI client for the tts-1 audio.speech API. Without the key the client cannot authenticate.","triggerScenarios":"TTS_PROVIDER=openai (the default) is active but TTS_OPEN_AI_KEY is missing/empty; the key was added but the process not restarted; confusion between OPEN_AI_KEY and TTS_OPEN_AI_KEY.","commonSituations":"Fresh install relying on default TTS provider without setting a dedicated TTS key; rotated key not updated; Docker env not passed through; assuming OPEN_AI_KEY covers TTS (it does not — TTS needs TTS_OPEN_AI_KEY).","solutions":["Add TTS_OPEN_AI_KEY=<sk-...> to .env and restart.","Confirm the exact name is TTS_OPEN_AI_KEY, not OPEN_AI_KEY.","Optionally set TTS_OPEN_AI_VOICE_MODEL (defaults to 'alloy').","In Docker, pass the variable to the container."],"exampleFix":"# before\n# TTS_PROVIDER unset → defaults to openai\n# TTS_OPEN_AI_KEY missing\n\n# after\nTTS_PROVIDER=openai\nTTS_OPEN_AI_KEY=sk-xxxxxxxx","handlingStrategy":"validation","validationCode":"if (\n  (process.env.TTS_PROVIDER || \"openai\") === \"openai\" &&\n  !process.env.TTS_OPEN_AI_KEY\n) {\n  throw new Error(\n    \"TTS provider is 'openai' but TTS_OPEN_AI_KEY is not set (this is separate from OPEN_AI_KEY).\"\n  );\n}","typeGuard":null,"tryCatchPattern":"try {\n  return new OpenAiTTS();\n} catch (e) {\n  if (/No OpenAI API key/i.test(e.message)) {\n    logger.error(\"Set TTS_OPEN_AI_KEY (dedicated TTS key) in .env, then restart.\");\n  }\n  throw e;\n}","preventionTips":["Remember TTS uses TTS_OPEN_AI_KEY, NOT the shared OPEN_AI_KEY — they are distinct.","Since 'openai' is the default TTS provider, this key is effectively required unless you switch providers.","Restart after editing .env."],"tags":["tts","openai","configuration","environment","credentials"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}