chenhg5/cc-connect · error
openai tts: request: %w
Error message
openai tts: request: %w
What it means
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.
Source
Thrown at core/tts.go:257
if opts.Speed > 0 {
reqBody["speed"] = opts.Speed
}
jsonData, err := json.Marshal(reqBody)
if err != nil {
return nil, "", fmt.Errorf("openai tts: marshal request: %w", err)
}
url := strings.TrimRight(o.BaseURL, "/") + "/audio/speech"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(jsonData))
if err != nil {
return nil, "", fmt.Errorf("openai tts: create request: %w", err)
}
req.Header.Set("Authorization", "Bearer "+o.APIKey)
req.Header.Set("Content-Type", "application/json")
resp, err := o.Client.Do(req)
if err != nil {
return nil, "", fmt.Errorf("openai tts: request: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
body, _ := io.ReadAll(resp.Body)
return nil, "", fmt.Errorf("openai tts API %d: %s", resp.StatusCode, body)
}
mp3Data, err := io.ReadAll(resp.Body)
if err != nil {
return nil, "", fmt.Errorf("openai tts: read audio: %w", err)
}
return mp3Data, "mp3", nil
}
// ──────────────────────────────────────────────────────────────
// MiniMaxTTS — MiniMax T2A v2 TTS implementation
// ──────────────────────────────────────────────────────────────View on GitHub (pinned to 4000b2338a)
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
Example fix
// before ctx := context.Background() // no timeout anywhere; hangs then fails // after ctx, cancel := context.WithTimeout(context.Background(), 60*time.Second) defer cancel()
Defensive patterns
Strategy: retry
Validate before calling
conn, err := net.DialTimeout("tcp", host+":443", 5*time.Second)
if err != nil { return fmt.Errorf("tts endpoint unreachable: %w", err) }
conn.Close() Type guard
var netErr net.Error
if errors.As(err, &netErr) && netErr.Timeout() { /* retry with backoff */ } Try / catch
mp3, format, err := tts.Synthesize(ctx, text)
if err != nil {
if strings.Contains(err.Error(), "tts: request:") && errors.Is(ctx.Err(), context.DeadlineExceeded) {
// timeout: extend deadline or retry
}
return err
} Prevention
- 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
When it happens
Trigger: Unreachable or wrong BaseURL host, DNS failure, TLS certificate errors, proxy misconfiguration, or the per-request context deadline expiring mid-request.
Common situations: 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.
Understand the failure class
Background: "API request failed": what wrapped HTTP errors from external APIs mean and how to find the real cause — this error's family across 29 libraries.
Related errors
- openai tts: read audio: %w
- minimax tts: request: %w
- minimax tts: read SSE stream: %w
- mimo tts: request: %w
- max: edit message: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/8fbaf19e8cda1724.
Report an issue: GitHub.