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 TTS_OPEN_AI_KEY is unset. This is a separate variable from OPEN_AI_KEY (used by STT) and from the LLM provider keys — AnythingLLM deliberately scopes TTS credentials to TTS_OPEN_AI_*, so having a working chat/STT key does not satisfy this check. The voice defaults to 'alloy' via TTS_OPEN_AI_VOICE_MODEL and the model is hardcoded to tts-1.
Solutions
- Set TTS_OPEN_AI_KEY=sk-... explicitly in the server environment and restart.
- Confirm you are not relying on OPEN_AI_KEY — the TTS class only reads TTS_OPEN_AI_KEY.
- Optionally set TTS_OPEN_AI_VOICE_MODEL (e.g. nova, shimmer) — defaults to alloy if omitted.
- Verify the key has access to the tts-1 model on your OpenAI account.
Example fix
# before (.env) TTS_PROVIDER=openai OPEN_AI_KEY=sk-abc # wrong var for TTS # -> Error: No OpenAI API key was set. # after (.env) TTS_PROVIDER=openai TTS_OPEN_AI_KEY=sk-abc # correct var TTS_OPEN_AI_VOICE_MODEL=alloy
Defensive patterns
Strategy: validation
Validate before calling
const canUseOpenAiTTS = () => Boolean(process.env.TTS_OPEN_AI_KEY);
if ((process.env.TTS_PROVIDER || "openai") === "openai" && !canUseOpenAiTTS()) {
throw new Error("openai TTS requires TTS_OPEN_AI_KEY (OPEN_AI_KEY is NOT used for TTS)");
} Try / catch
try {
tts = getTTSProvider();
} catch (e) {
if (/No OpenAI API key was set/.test(e.message) && (process.env.TTS_PROVIDER || "openai") === "openai")
return respondConfigError("TTS_OPEN_AI_KEY missing");
throw e;
} Prevention
- Don't assume key reuse: chat (LLM provider key), STT (OPEN_AI_KEY), and TTS (TTS_OPEN_AI_KEY) are separate variables in this codebase.
- Add a deploy-time assertion listing all three OpenAI-related vars and which subsystem each unlocks.
- Restart the process after .env changes; Node reads env once at boot.
When it happens
Trigger: TTS_PROVIDER=openai (the default) and any speech-generation request while TTS_OPEN_AI_KEY is missing from the server environment.
Common situations: User sets OPEN_AI_KEY for chat, assumes TTS inherits it, and never sets TTS_OPEN_AI_KEY; .env updated but container not restarted; key placed under the generic-openai variables (TTS_OPEN_AI_COMPATIBLE_KEY) by mistake.
Understand the failure class
Background: "environment variable is not set" and "Missing keys in environment" errors: what missing required env var messages mean and how to fix them — this error's family across 28 libraries.
Related errors
- No ElevenLabs API key was set.
- No OpenAI API key was set.
- ENV: No TTS_PROVIDER value found in environment!
- No Kokoro endpoint was set. Please set TTS_KOKORO_ENDPOINT…
- No OpenAI compatible endpoint was set. Please set this to…
AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18).
Data as JSON: /api/errors/1b170adb51bba041.
Report an issue: GitHub.
Appendix: 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 3aec848f28)