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 OpenAiSTT constructor (AnythingLLM's native OpenAI speech-to-text wrapper) when process.env.OPEN_AI_KEY is unset or empty at the moment the provider is instantiated. The class cannot build an OpenAI SDK client without an API key, so it fails fast instead of erroring later during transcription. Note the exact variable name: OPEN_AI_KEY, not OPENAI_API_KEY.

Solutions

  1. Add OPEN_AI_KEY=sk-... to the server's .env (or docker-compose environment section) and restart the process/container.
  2. Confirm the variable name is exactly OPEN_AI_KEY — OPENAI_API_KEY or TTS_OPEN_AI_KEY will not satisfy this check.
  3. Verify the running process sees it: `docker exec <container> printenv OPEN_AI_KEY` or log process.env.OPEN_AI_KEY at boot.
  4. If you do not want OpenAI STT, set STT_PROVIDER to another supported provider (e.g. generic-openai with STT_OPEN_AI_COMPATIBLE_ENDPOINT).

Example fix

# before (.env)
STT_PROVIDER=openai
# OPEN_AI_KEY missing -> Error: No OpenAI API key was set.

# after (.env)
STT_PROVIDER=openai
OPEN_AI_KEY=sk-your-key-here
Defensive patterns

Strategy: validation

Validate before calling

const canUseOpenAiSTT = () => Boolean(process.env.OPEN_AI_KEY);

// gate before constructing the provider
if (process.env.STT_PROVIDER === "openai" && !canUseOpenAiSTT()) {
  throw new Error("STT misconfigured: set OPEN_AI_KEY or change STT_PROVIDER");
}

Try / catch

try {
  stt = getSTTProvider();
} catch (e) {
  if (/No OpenAI API key was set/.test(e.message)) return respondConfigError("OPEN_AI_KEY missing");
  throw e;
}

Prevention

When it happens

Trigger: Selecting STT_PROVIDER=openai (or leaving it unset, since openai is the default STT) and then triggering any speech-to-text path (voice input, STT endpoint) while OPEN_AI_KEY is missing from the server process environment.

Common situations: Fresh clone/deploy without a complete .env; docker-compose or systemd unit that does not pass OPEN_AI_KEY into the container/process; setting OPENAI_API_KEY (the OpenAI SDK's usual name) instead of OPEN_AI_KEY; key set in an interactive shell but not in the service manager's environment; expecting the LLM provider's key to be reused for STT.

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


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/ce7bdfbf3d5da9dc. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/SpeechToText/openAi/index.js:3

class OpenAiSTT {
  constructor() {
    if (!process.env.OPEN_AI_KEY) throw new Error("No OpenAI API key was set.");
    const { OpenAI: OpenAIApi } = require("openai");
    this.openai = new OpenAIApi({
      apiKey: process.env.OPEN_AI_KEY,
    });
    this.model = process.env.STT_OPEN_AI_MODEL ?? "whisper-1";
  }

  /**
   * Transcribes an audio buffer to text using the OpenAI STT service.
   * @param {Buffer} audioBuffer - The audio buffer to be transcribed.
   * @param {string} filename - Original filename, used to hint the audio container/codec to OpenAI.
   * @returns {Promise<string>} The transcribed text.
   */
  async transcribe(audioBuffer, filename = "audio.webm") {
    const { toFile } = require("openai");
    const file = await toFile(audioBuffer, filename);
    const result = await this.openai.audio.transcriptions.create({
      file,

View on GitHub (pinned to 3aec848f28)