harry0703/MoneyPrinterTurbo · error · ValueError

MiniMax TTS API key is not set

Error message

MiniMax TTS API key is not set

What it means

The MiniMax voice-catalog query requires a bearer API key. The function falls back from the explicit api_key argument to get_minimax_tts_api_key(); if neither yields a non-blank string, it raises ValueError before making any request.

Source

Thrown at app/services/voice.py:1389

def get_minimax_voice_catalog(
    api_key: str = "",
    endpoint: str = "",
    voice_type: str = "all",
) -> list[dict[str, str]]:
    """
    查询当前 MiniMax 账号可用的系统、克隆和生成音色。

    返回值统一为 voice_id、voice_name、voice_type 三个字段,调用方无需了解
    MiniMax 按音色来源拆分数组的响应结构。查询失败时抛出异常,让 WebUI、
    API 或 CLI 可以按各自交互方式展示明确错误,而不是静默返回空列表。
    """
    if voice_type not in {"system", "voice_cloning", "voice_generation", "all"}:
        raise ValueError(f"Unsupported MiniMax voice type: {voice_type}")

    effective_api_key = str(api_key or get_minimax_tts_api_key()).strip()
    if not effective_api_key:
        raise ValueError("MiniMax TTS API key is not set")

    tts_endpoint = (
        _resolve_minimax_tts_url(endpoint)
        if endpoint
        else get_minimax_tts_endpoint()
    )
    voice_endpoint = (
        f"{tts_endpoint[:-len('/t2a_v2')]}/get_voice"
        if tts_endpoint.endswith("/t2a_v2")
        else f"{tts_endpoint.rstrip('/')}/get_voice"
    )
    response = requests.post(
        voice_endpoint,
        json={"voice_type": voice_type},
        headers={
            "Authorization": f"Bearer {effective_api_key}",
            "Content-Type": "application/json",
        },

View on GitHub (pinned to 1f9f19c202)

Solutions

  1. Set the MiniMax TTS API key in configuration (env/config) so get_minimax_tts_api_key() returns it, or pass api_key explicitly.
  2. Trim stray quotes/spaces around the key in the .env file — the code strips whitespace, so the raw value must be non-empty after stripping.
  3. Verify the key name expected by get_minimax_tts_api_key() in your config source.

Example fix

# before
voices = list_minimax_voices()  # ValueError: key is not set

# after
voices = list_minimax_voices(api_key=os.environ["MINIMAX_API_KEY"])  # or set MINIMAX_TTS_API_KEY in config
Defensive patterns

Strategy: validation

Validate before calling

from app.services.voice import get_minimax_tts_api_key

if not (str(get_minimax_tts_api_key() or "").strip() or api_key.strip()):
    raise RuntimeError("configure MINIMAX TTS API key before querying voices")

Try / catch

try:
    voices = list_minimax_voices(voice_type=vt)
except ValueError as exc:
    if "API key is not set" in str(exc):
        return "MiniMax API key missing — set it in settings"  # user-facing message
    raise

Prevention

When it happens

Trigger: Calling the MiniMax voice listing (or TTS paths sharing the key getter) with no explicit api_key while the configured MiniMax TTS key is empty, None, or whitespace.

Common situations: .env / config file missing the MINIMAX_TTS_API_KEY entry (or set to an empty string); key configured for a different provider and passed under the wrong name; environment not loaded in the deployed container.

Related errors


AI-assisted analysis of harry0703/MoneyPrinterTurbo@1f9f19c202 (2026-08-14). Data as JSON: /api/errors/236ca84d914f3800. Report an issue: GitHub.