Mintplex-Labs/anything-llm · error · Error
No OpenAI API key was set.
Error message
No OpenAI API key was set.
What it means
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.
Source
Thrown at server/utils/TextToSpeech/openAi/index.js:4
class OpenAiTTS {
constructor() {
if (!process.env.TTS_OPEN_AI_KEY)
throw new Error("No OpenAI API key was set.");
const { OpenAI: OpenAIApi } = require("openai");
this.openai = new OpenAIApi({
apiKey: process.env.TTS_OPEN_AI_KEY,
});
this.voice = process.env.TTS_OPEN_AI_VOICE_MODEL ?? "alloy";
}
async ttsBuffer(textInput) {
try {
const result = await this.openai.audio.speech.create({
model: "tts-1",
voice: this.voice,
input: textInput,
});
return Buffer.from(await result.arrayBuffer());
} catch (e) {
console.error(e);
}View on GitHub (pinned to 526360e320)
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.
Example fix
# before # TTS_PROVIDER unset → defaults to openai # TTS_OPEN_AI_KEY missing # after TTS_PROVIDER=openai TTS_OPEN_AI_KEY=sk-xxxxxxxx
Defensive patterns
Strategy: validation
Validate before calling
if (
(process.env.TTS_PROVIDER || "openai") === "openai" &&
!process.env.TTS_OPEN_AI_KEY
) {
throw new Error(
"TTS provider is 'openai' but TTS_OPEN_AI_KEY is not set (this is separate from OPEN_AI_KEY)."
);
} Try / catch
try {
return new OpenAiTTS();
} catch (e) {
if (/No OpenAI API key/i.test(e.message)) {
logger.error("Set TTS_OPEN_AI_KEY (dedicated TTS key) in .env, then restart.");
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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).
Related errors
- No OpenAI API key was set.
- No ElevenLabs API key was set.
- No Deepgram API key was set.
- No Groq API key was set.
- ENV: No TTS_PROVIDER value found in environment!
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/1b170adb51bba041.
Report an issue: GitHub.