{"record":{"id":"236ca84d914f3800","repo":"harry0703/MoneyPrinterTurbo","slug":"minimax-tts-api-key-is-not-set","errorCode":null,"errorMessage":"MiniMax TTS API key is not set","messagePattern":"MiniMax TTS API key is not set","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"app/services/voice.py","lineNumber":1389,"sourceCode":"\ndef get_minimax_voice_catalog(\n    api_key: str = \"\",\n    endpoint: str = \"\",\n    voice_type: str = \"all\",\n) -> list[dict[str, str]]:\n    \"\"\"\n    查询当前 MiniMax 账号可用的系统、克隆和生成音色。\n\n    返回值统一为 voice_id、voice_name、voice_type 三个字段，调用方无需了解\n    MiniMax 按音色来源拆分数组的响应结构。查询失败时抛出异常，让 WebUI、\n    API 或 CLI 可以按各自交互方式展示明确错误，而不是静默返回空列表。\n    \"\"\"\n    if voice_type not in {\"system\", \"voice_cloning\", \"voice_generation\", \"all\"}:\n        raise ValueError(f\"Unsupported MiniMax voice type: {voice_type}\")\n\n    effective_api_key = str(api_key or get_minimax_tts_api_key()).strip()\n    if not effective_api_key:\n        raise ValueError(\"MiniMax TTS API key is not set\")\n\n    tts_endpoint = (\n        _resolve_minimax_tts_url(endpoint)\n        if endpoint\n        else get_minimax_tts_endpoint()\n    )\n    voice_endpoint = (\n        f\"{tts_endpoint[:-len('/t2a_v2')]}/get_voice\"\n        if tts_endpoint.endswith(\"/t2a_v2\")\n        else f\"{tts_endpoint.rstrip('/')}/get_voice\"\n    )\n    response = requests.post(\n        voice_endpoint,\n        json={\"voice_type\": voice_type},\n        headers={\n            \"Authorization\": f\"Bearer {effective_api_key}\",\n            \"Content-Type\": \"application/json\",\n        },","sourceCodeStart":1371,"sourceCodeEnd":1407,"githubUrl":"https://github.com/harry0703/MoneyPrinterTurbo/blob/1f9f19c2021a68d04df228f33e9099a0c947f6f8/app/services/voice.py#L1371-L1407","documentation":"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.","triggerScenarios":"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.","commonSituations":".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.","solutions":["Set the MiniMax TTS API key in configuration (env/config) so get_minimax_tts_api_key() returns it, or pass api_key explicitly.","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.","Verify the key name expected by get_minimax_tts_api_key() in your config source."],"exampleFix":"# before\nvoices = list_minimax_voices()  # ValueError: key is not set\n\n# after\nvoices = list_minimax_voices(api_key=os.environ[\"MINIMAX_API_KEY\"])  # or set MINIMAX_TTS_API_KEY in config","handlingStrategy":"validation","validationCode":"from app.services.voice import get_minimax_tts_api_key\n\nif not (str(get_minimax_tts_api_key() or \"\").strip() or api_key.strip()):\n    raise RuntimeError(\"configure MINIMAX TTS API key before querying voices\")","typeGuard":null,"tryCatchPattern":"try:\n    voices = list_minimax_voices(voice_type=vt)\nexcept ValueError as exc:\n    if \"API key is not set\" in str(exc):\n        return \"MiniMax API key missing — set it in settings\"  # user-facing message\n    raise","preventionTips":["Add a config sanity check at startup that required provider keys are present when the feature is enabled.","Pass api_key explicitly from your own secret store instead of relying on ambient config."],"tags":["minimax","tts","api-key","configuration"],"backgroundTag":null,"analyzedSha":"1f9f19c2021a68d04df228f33e9099a0c947f6f8","analyzedAt":"2026-08-14T19:41:05.568Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}