chenhg5/cc-connect · error
minimax tts: marshal request: %w
Error message
minimax tts: marshal request: %w
What it means
This error is returned by the MiniMax TTS Synthesize method when json.Marshal fails to serialize the T2A v2 request body. Since the request body is built from a map[string]any of plain strings/numbers, this failure is extremely rare and would indicate a programmer error or a non-marshalable value injected into the request map rather than a runtime/user problem.
Source
Thrown at core/tts.go:330
speed = 1.0
}
reqBody := map[string]any{
"model": m.Model,
"text": text,
"stream": true,
"voice_setting": map[string]any{
"voice_id": voice,
"speed": speed,
},
"audio_setting": map[string]any{
"format": "mp3",
"sample_rate": 32000,
},
}
jsonData, err := json.Marshal(reqBody)
if err != nil {
return nil, "", fmt.Errorf("minimax tts: marshal request: %w", err)
}
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)View on GitHub (pinned to 4000b2338a)
Solutions
- Audit any modified code that adds values to the reqBody map for non-JSON-serializable types
- Convert dynamic values to JSON-safe types (string, float64, bool, nested maps) before adding them
- If marshaling complex options, use typed structs with json tags instead of map[string]any
Example fix
// before reqBody["voice_modifier"] = someFunc // not marshalable // after reqBody["voice_modifier"] = someFuncName // string value
Defensive patterns
Strategy: try-catch
Validate before calling
null
Type guard
null
Try / catch
mp3, format, err := tts.Synthesize(ctx, text)
if err != nil {
if strings.Contains(err.Error(), "minimax tts: marshal request") {
// non-serializable value in request body; audit custom modifications
}
return err
} Prevention
- Use typed request structs with json tags instead of map[string]any
- Never inject funcs, channels, or cyclic data into request maps
- Add a unit test that marshals the exact request body construction
When it happens
Trigger: Only if the request body map contains a value json.Marshal cannot encode (e.g. a channel, func, or cyclic value placed into reqBody after a code change). The current hardcoded map cannot trigger it.
Common situations: Essentially never seen in production; encountered only after custom modifications that inject dynamic values (e.g. plugin-supplied voice params) into the request body.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- marshal Agy permission hook: %w
- marshal Agy hooks overlay: %w
- bridge: marshal reconstruct reply ctx: %w
- mimo tts: marshal request: %w
- parse existing Agy hooks %s: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/6cacf54c74a30029.
Report an issue: GitHub.