danny-avila/LibreChat · error

Invalid provider

Error message

Invalid provider

What it means

getVoices switch default branch: the provider string returned by TTSService.getProvider does not match any case constant (openai, azureOpenAI, elevenlabs, localai). This is hard to hit in normal operation because getProvider already validates exactly one provider exists, but it fires if the configured provider key value drifts from the TTSProviders constants used in the switch.

Source

Thrown at api/server/services/Files/Audio/getVoices.js:47

    const provider = await getProvider(appConfig);
    let voices;

    switch (provider) {
      case TTSProviders.OPENAI:
        voices = ttsSchema.openai?.voices;
        break;
      case TTSProviders.AZURE_OPENAI:
        voices = ttsSchema.azureOpenAI?.voices;
        break;
      case TTSProviders.ELEVENLABS:
        voices = ttsSchema.elevenlabs?.voices;
        break;
      case TTSProviders.LOCALAI:
        voices = ttsSchema.localai?.voices;
        break;
      default:
        throw new Error('Invalid provider');
    }

    res.json(voices);
  } catch (error) {
    res.status(500).json({ error: `Failed to get voices: ${error.message}` });
  }
}

module.exports = getVoices;

View on GitHub (pinned to 5ff282f900)

Solutions

  1. Set the provider key in speech.tts to a value matching a TTSProviders constant exactly.
  2. Upgrade librechat-data-provider and the API service in lockstep so constants and switch cases agree.
  3. Confirm only one provider is populated so getProvider returns the intended one.
Defensive patterns

Strategy: type-guard

Validate before calling

const { TTSProviders } = require('librechat-data-provider');
if (!Object.values(TTSProviders).includes(provider)) {
  return res.status(500).json({ error: `Unsupported TTS provider: ${provider}` });
}

Type guard

/** @param {string} p */
function isValidTtsProvider(p) {
  const { TTSProviders } = require('librechat-data-provider');
  return Object.values(TTSProviders).includes(p);
}

Prevention

When it happens

Trigger: speech.tts has one populated provider whose key is not one of the four supported constants (e.g. a renamed/cased value, or a future provider constant not yet added to the switch).

Common situations: librechat-data-provider TTSProviders constant value changed but the switch wasn't updated; hand-edited provider string with wrong casing; new provider added to data-provider before the switch caught up.

Related errors


AI-assisted analysis of danny-avila/LibreChat@5ff282f900 (2026-08-12). Data as JSON: /api/errors/aa278386777a924e. Report an issue: GitHub.