{"record":{"id":"50bdd3e5514dd16e","repo":"Mintplex-Labs/anything-llm","slug":"no-elevenlabs-api-key-was-set","errorCode":null,"errorMessage":"No ElevenLabs API key was set.","messagePattern":"No ElevenLabs API key was set\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/TextToSpeech/elevenLabs/index.js","lineNumber":6,"sourceCode":"const { ElevenLabsClient } = require(\"elevenlabs\");\n\nclass ElevenLabsTTS {\n  constructor() {\n    if (!process.env.TTS_ELEVEN_LABS_KEY)\n      throw new Error(\"No ElevenLabs API key was set.\");\n    this.elevenLabs = new ElevenLabsClient({\n      apiKey: process.env.TTS_ELEVEN_LABS_KEY,\n    });\n\n    // Rachel as default voice\n    // https://api.elevenlabs.io/v1/voices\n    this.voiceId =\n      process.env.TTS_ELEVEN_LABS_VOICE_MODEL ?? \"21m00Tcm4TlvDq8ikWAM\";\n    this.modelId = \"eleven_multilingual_v2\";\n  }\n\n  static async voices(apiKey = null) {\n    try {\n      const client = new ElevenLabsClient({\n        apiKey: apiKey ?? process.env.TTS_ELEVEN_LABS_KEY ?? null,\n      });\n      return (await client.voices.getAll())?.voices ?? [];\n    } catch {}","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/TextToSpeech/elevenLabs/index.js#L1-L24","documentation":"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.","triggerScenarios":"Setting TTS_PROVIDER=elevenlabs and starting any TTS flow (agent speech, browser-extension narration) with no TTS_ELEVEN_LABS_KEY in the server environment.","commonSituations":"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.","solutions":["Set TTS_ELEVEN_LABS_KEY=<your key> in the server's .env / container environment and restart.","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.","Validate the key before wiring it in by calling the static helper ElevenLabsTTS.voices(apiKey) — a 401 there means the key is bad.","If you meant to use OpenAI speech instead, set TTS_PROVIDER=openai (and TTS_OPEN_AI_KEY)."],"exampleFix":"# before (.env)\nTTS_PROVIDER=elevenlabs\n# -> Error: No ElevenLabs API key was set.\n\n# after (.env)\nTTS_PROVIDER=elevenlabs\nTTS_ELEVEN_LABS_KEY=xi-your-key\nTTS_ELEVEN_LABS_VOICE_MODEL=21m00Tcm4TlvDq8ikWAM","handlingStrategy":"validation","validationCode":"const canUseElevenLabsTTS = () => Boolean(process.env.TTS_ELEVEN_LABS_KEY);\n\nif (process.env.TTS_PROVIDER === \"elevenlabs\" && !canUseElevenLabsTTS()) {\n  throw new Error(\"elevenlabs TTS requires TTS_ELEVEN_LABS_KEY\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  tts = getTTSProvider();\n} catch (e) {\n  if (/No ElevenLabs API key was set/.test(e.message))\n    return respondConfigError(\"TTS_ELEVEN_LABS_KEY missing\");\n  throw e;\n}","preventionTips":["Verify keys early by calling the class's static voices(apiKey) helper, which fails fast on a bad key without constructing the provider.","Store TTS keys alongside other secrets in the same injection mechanism (env_file / secret store) so they rotate together.","Check the ElevenLabs dashboard for key status if TTS suddenly starts failing."],"tags":["env","configuration","tts","elevenlabs","missing-api-key"],"backgroundTag":"missing-env-var","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}