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 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.

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 526360e320)

Solutions

  1. Add OPEN_AI_KEY=<sk-...> to .env and restart.
  2. Confirm the exact name is OPEN_AI_KEY (shared with other OpenAI features), not STT_OPEN_AI_KEY.
  3. In Docker, pass the variable to the container.
  4. Optionally set STT_OPEN_AI_MODEL (defaults to whisper-1).

Example fix

# before
STT_PROVIDER=openai
# OPEN_AI_KEY missing

# after
STT_PROVIDER=openai
OPEN_AI_KEY=sk-xxxxxxxx
Defensive patterns

Strategy: validation

Validate before calling

if (process.env.STT_PROVIDER === "openai" && !process.env.OPEN_AI_KEY) {
  throw new Error("STT_PROVIDER is 'openai' but OPEN_AI_KEY is not set.");
}

Try / catch

try {
  return new OpenAiSTT();
} catch (e) {
  if (/No OpenAI API key/i.test(e.message)) {
    logger.error("Set OPEN_AI_KEY (shared) in .env, then restart.");
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: Fresh install without OPEN_AI_KEY; key rotated and the new one not added; Docker env not passed through.

Related errors


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