Mintplex-Labs/anything-llm · error · Error

No ElevenLabs API key was set.

Error message

No ElevenLabs API key was set.

What it means

Thrown by the ElevenLabsTTS constructor when TTS_ELEVEN_LABS_KEY is unset. ElevenLabs requires an API key for every request, so the client (ElevenLabsClient) is never created without one; the class then configures voice (TTS_ELEVEN_LABS_VOICE_MODEL, default Rachel '21m00Tcm4TlvDq8ikWAM') and model eleven_multilingual_v2.

Solutions

  1. Set TTS_ELEVEN_LABS_KEY=<your key> in the server's .env / container environment and restart.
  2. Optionally set TTS_ELEVEN_LABS_VOICE_MODEL to a voice ID from https://api.elevenlabs.io/v1/voices if you don't want the Rachel default.
  3. Validate the key before wiring it in by calling the static helper ElevenLabsTTS.voices(apiKey) — a 401 there means the key is bad.
  4. If you meant to use OpenAI speech instead, set TTS_PROVIDER=openai (and TTS_OPEN_AI_KEY).

Example fix

# before (.env)
TTS_PROVIDER=elevenlabs
# -> Error: No ElevenLabs API key was set.

# after (.env)
TTS_PROVIDER=elevenlabs
TTS_ELEVEN_LABS_KEY=xi-your-key
TTS_ELEVEN_LABS_VOICE_MODEL=21m00Tcm4TlvDq8ikWAM
Defensive patterns

Strategy: validation

Validate before calling

const canUseElevenLabsTTS = () => Boolean(process.env.TTS_ELEVEN_LABS_KEY);

if (process.env.TTS_PROVIDER === "elevenlabs" && !canUseElevenLabsTTS()) {
  throw new Error("elevenlabs TTS requires TTS_ELEVEN_LABS_KEY");
}

Try / catch

try {
  tts = getTTSProvider();
} catch (e) {
  if (/No ElevenLabs API key was set/.test(e.message))
    return respondConfigError("TTS_ELEVEN_LABS_KEY missing");
  throw e;
}

Prevention

When it happens

Trigger: Setting TTS_PROVIDER=elevenlabs and starting any TTS flow (agent speech, browser-extension narration) with no TTS_ELEVEN_LABS_KEY in the server environment.

Common situations: Free-tier ElevenLabs account whose key was never exported; key stored only in the frontend/.env instead of the server environment; typo in the variable name (ELEVEN_LABS_KEY vs TTS_ELEVEN_LABS_KEY); expired/revoked key still in .env after rotating.

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/50bdd3e5514dd16e. Report an issue: GitHub.

Appendix: source

Thrown at server/utils/TextToSpeech/elevenLabs/index.js:6

const { ElevenLabsClient } = require("elevenlabs");

class ElevenLabsTTS {
  constructor() {
    if (!process.env.TTS_ELEVEN_LABS_KEY)
      throw new Error("No ElevenLabs API key was set.");
    this.elevenLabs = new ElevenLabsClient({
      apiKey: process.env.TTS_ELEVEN_LABS_KEY,
    });

    // Rachel as default voice
    // https://api.elevenlabs.io/v1/voices
    this.voiceId =
      process.env.TTS_ELEVEN_LABS_VOICE_MODEL ?? "21m00Tcm4TlvDq8ikWAM";
    this.modelId = "eleven_multilingual_v2";
  }

  static async voices(apiKey = null) {
    try {
      const client = new ElevenLabsClient({
        apiKey: apiKey ?? process.env.TTS_ELEVEN_LABS_KEY ?? null,
      });
      return (await client.voices.getAll())?.voices ?? [];
    } catch {}

View on GitHub (pinned to 3aec848f28)