chenhg5/cc-connect · error

minimax tts API %d: %s

Error message

minimax tts API %d: %s

What it means

This error is returned when the MiniMax TTS endpoint replies with a non-200 HTTP status. It includes the status code and up to the full response body so the caller can see the server's reason (auth failure, bad model, rate limit, etc.). Unlike the business-error path (error 893), this fires before any SSE parsing, on transport-level rejection.

Source

Thrown at core/tts.go:349

	}

	url := strings.TrimRight(m.BaseURL, "/") + "/v1/t2a_v2"
	req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))
	if err != nil {
		return nil, "", fmt.Errorf("minimax tts: create request: %w", err)
	}
	req.Header.Set("Authorization", "Bearer "+m.APIKey)
	req.Header.Set("Content-Type", "application/json")

	resp, err := m.Client.Do(req)
	if err != nil {
		return nil, "", fmt.Errorf("minimax tts: request: %w", err)
	}
	defer resp.Body.Close()

	if resp.StatusCode != http.StatusOK {
		body, _ := io.ReadAll(resp.Body)
		return nil, "", fmt.Errorf("minimax tts API %d: %s", resp.StatusCode, body)
	}

	// Parse SSE stream: each line is "data: {...}" with hex-encoded audio chunks.
	var audioBuf bytes.Buffer
	scanner := bufio.NewScanner(resp.Body)
	scanner.Buffer(make([]byte, 0, 1024*1024), 10*1024*1024)
	for scanner.Scan() {
		select {
		case <-ctx.Done():
			return nil, "", ctx.Err()
		default:
		}
		line := scanner.Text()
		if !strings.HasPrefix(line, "data:") {
			continue
		}
		data := strings.TrimSpace(strings.TrimPrefix(line, "data:"))
		if data == "" {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the body embedded in the error: 401/403 → fix the API key in config.toml; 429 → back off and retry; 5xx → retry later or check MiniMax status.
  2. Regenerate the MiniMax API key and update config.toml if authentication failed.
  3. Confirm base_url points to the correct MiniMax host for your region.
  4. Implement retry with exponential backoff for 429 and 5xx responses.

Example fix

// before
client.Do(req) // 401 body: {"base_resp":{"status_code":1004,"status_msg":"invalid api key"}}
// after
// fix config.toml: api_key = "sk-..." with a fresh key from the MiniMax console
Defensive patterns

Strategy: try-catch

Validate before calling

if cfg.APIKey == "" { return errors.New("minimax api_key missing") }

Try / catch

if err != nil {
    var apiErr *HTTPStatusError // or parse "minimax tts API %d: %s"
    if strings.Contains(err.Error(), "minimax tts API 401") {
        // rotate API key
    } else if strings.Contains(err.Error(), "minimax tts API 429") {
        // backoff and retry
    }
}

Prevention

When it happens

Trigger: MiniMax API returns 401 (invalid/expired API key), 400 (malformed request body), 429 (rate limited), or 5xx; a proxy or gateway returns an HTML error page with a non-200 status.

Common situations: Expired or wrong minimax API key in config.toml; account out of quota; wrong base_url hitting a non-MiniMax service; 502/503 from a gateway during MiniMax incidents.

Understand the failure class

Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/89a5c83d6bf96321. Report an issue: GitHub.