{"record":{"id":"07080292f11e6c54","repo":"chenhg5/cc-connect","slug":"minimax-tts-api-error-d-s","errorCode":null,"errorMessage":"minimax tts API error %d: %s","messagePattern":"minimax tts API error (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":384,"sourceCode":"\t\tdata := strings.TrimSpace(strings.TrimPrefix(line, \"data:\"))\n\t\tif data == \"\" {\n\t\t\tcontinue\n\t\t}\n\t\tvar chunk struct {\n\t\t\tData struct {\n\t\t\t\tAudio  string `json:\"audio\"`\n\t\t\t\tStatus int    `json:\"status\"`\n\t\t\t} `json:\"data\"`\n\t\t\tBaseResp struct {\n\t\t\t\tStatusCode int    `json:\"status_code\"`\n\t\t\t\tStatusMsg  string `json:\"status_msg\"`\n\t\t\t} `json:\"base_resp\"`\n\t\t}\n\t\tif err := json.Unmarshal([]byte(data), &chunk); err != nil {\n\t\t\tcontinue\n\t\t}\n\t\tif chunk.BaseResp.StatusCode != 0 {\n\t\t\treturn nil, \"\", fmt.Errorf(\"minimax tts API error %d: %s\", chunk.BaseResp.StatusCode, chunk.BaseResp.StatusMsg)\n\t\t}\n\t\t// MiniMax T2A v2 stream protocol: status=1 carries incremental audio\n\t\t// chunks; the final status=2 chunk re-sends the full audio as a\n\t\t// trailer for non-stream clients. Appending the trailer doubles the\n\t\t// audio length and makes the spoken text play twice, so skip it.\n\t\tif chunk.Data.Status == 2 {\n\t\t\tbreak\n\t\t}\n\t\tif chunk.Data.Audio != \"\" {\n\t\t\taudioBytes, err := hex.DecodeString(chunk.Data.Audio)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, \"\", fmt.Errorf(\"minimax tts: decode audio hex: %w\", err)\n\t\t\t}\n\t\t\taudioBuf.Write(audioBytes)\n\t\t}\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"minimax tts: read SSE stream: %w\", err)","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L366-L402","documentation":"MiniMax T2A v2 returns business-level errors inside a 200 OK SSE stream via base_resp.status_code/status_msg. This error surfaces those: the HTTP transport succeeded but MiniMax itself rejected the request (e.g. invalid key, bad model name, quota exhaustion). The JSON chunk is decoded and its non-zero status code and message are propagated.","triggerScenarios":"A data: SSE chunk carries base_resp.status_code != 0 — invalid API key (1004), insufficient balance, unsupported model/voice, request param rejection.","commonSituations":"Wrong api_key in config.toml; MiniMax account out of credits; model name or voice_id typo; free-tier quota exhausted mid-session.","solutions":["Parse the code and message in the error: 1004/invalid key → replace the API key in config.toml; quota messages → top up the MiniMax account.","Verify model and voice parameters against current MiniMax T2A v2 docs (names change between API versions).","Check account balance/quota in the MiniMax console.","If the error persists with valid credentials, confirm the base_url matches the API version that accepts your request shape."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if cfg.APIKey == \"\" || cfg.Model == \"\" || cfg.VoiceID == \"\" { return errors.New(\"minimax tts: missing key/model/voice config\") }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    // error text: \"minimax tts API error %d: %s\"\n    if strings.Contains(err.Error(), \"API error 1004\") {\n        // invalid api key — reconfigure\n    } else if strings.Contains(err.Error(), \"quota\") || strings.Contains(err.Error(), \"balance\") {\n        // top up account / switch provider\n    }\n}","preventionTips":["Verify model and voice IDs against current MiniMax docs on every API version bump","Monitor account balance/quota programmatically","Centralize the status_code → action mapping so new codes surface loudly"],"tags":["go","api","tts","minimax","business-error"],"backgroundTag":"api-error-response","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}