{"record":{"id":"8fbaf19e8cda1724","repo":"chenhg5/cc-connect","slug":"openai-tts-request-w","errorCode":null,"errorMessage":"openai tts: request: %w","messagePattern":"openai tts: request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/tts.go","lineNumber":257,"sourceCode":"\tif opts.Speed > 0 {\n\t\treqBody[\"speed\"] = opts.Speed\n\t}\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"openai tts: marshal request: %w\", err)\n\t}\n\n\turl := strings.TrimRight(o.BaseURL, \"/\") + \"/audio/speech\"\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"openai tts: create request: %w\", err)\n\t}\n\treq.Header.Set(\"Authorization\", \"Bearer \"+o.APIKey)\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\n\tresp, err := o.Client.Do(req)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"openai tts: request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tbody, _ := io.ReadAll(resp.Body)\n\t\treturn nil, \"\", fmt.Errorf(\"openai tts API %d: %s\", resp.StatusCode, body)\n\t}\n\n\tmp3Data, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn nil, \"\", fmt.Errorf(\"openai tts: read audio: %w\", err)\n\t}\n\treturn mp3Data, \"mp3\", nil\n}\n\n// ──────────────────────────────────────────────────────────────\n// MiniMaxTTS — MiniMax T2A v2 TTS implementation\n// ──────────────────────────────────────────────────────────────","sourceCodeStart":239,"sourceCodeEnd":275,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/tts.go#L239-L275","documentation":"This error is returned when the HTTP transport itself fails during o.Client.Do(req) for the /audio/speech TTS request — connection setup, TLS, DNS, or timeout — before any HTTP response is received. The library wraps the transport error so callers can tell network-level failures apart from non-200 API responses.","triggerScenarios":"Unreachable or wrong BaseURL host, DNS failure, TLS certificate errors, proxy misconfiguration, or the per-request context deadline expiring mid-request.","commonSituations":"Offline machine or missing proxy env in a container, typo in base_url hostname, corporate firewall blocking the endpoint, very short context timeout cutting off a slow TTS call.","solutions":["Verify network reachability: curl the BaseURL host from the same machine/container","Check proxy environment variables (HTTP_PROXY/HTTPS_PROXY) and the http.Client transport/timeout settings","Increase the context deadline passed to Synthesize if timeouts are the cause"],"exampleFix":"// before\nctx := context.Background()\n// no timeout anywhere; hangs then fails\n// after\nctx, cancel := context.WithTimeout(context.Background(), 60*time.Second)\ndefer cancel()","handlingStrategy":"retry","validationCode":"conn, err := net.DialTimeout(\"tcp\", host+\":443\", 5*time.Second)\nif err != nil { return fmt.Errorf(\"tts endpoint unreachable: %w\", err) }\nconn.Close()","typeGuard":"var netErr net.Error\nif errors.As(err, &netErr) && netErr.Timeout() { /* retry with backoff */ }","tryCatchPattern":"mp3, format, err := tts.Synthesize(ctx, text)\nif err != nil {\n    if strings.Contains(err.Error(), \"tts: request:\") && errors.Is(ctx.Err(), context.DeadlineExceeded) {\n        // timeout: extend deadline or retry\n    }\n    return err\n}","preventionTips":["Set a generous timeout (30-60s) on the TTS context","Verify proxy env vars and TLS trust in containers","Test endpoint reachability with curl before deploying"],"tags":["go","tts","network","http-client"],"backgroundTag":"api-request-failed","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"}