chenhg5/cc-connect · error

qwen tts API %d: %s

Error message

qwen tts API %d: %s

What it means

If the TTS API responds with an HTTP status other than 200, Synthesize surfaces 'qwen tts API <status>: <body>', including the raw response body for diagnosis. This means the request reached the server and was rejected or failed server-side.

Source

Thrown at core/tts.go:157

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

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

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

	var result struct {
		Code    string `json:"code"`
		Message string `json:"message"`
		Output  struct {
			Audio struct {
				URL string `json:"url"`
			} `json:"audio"`
		} `json:"output"`
	}
	if err := json.Unmarshal(body, &result); err != nil {
		return nil, "", fmt.Errorf("qwen tts: parse response: %w", err)
	}
	if result.Code != "" {
		return nil, "", fmt.Errorf("qwen tts API error %s: %s", result.Code, result.Message)
	}
	if result.Output.Audio.URL == "" {

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the status and body in the error: 401/403 -> fix the API key and its permissions; 429 -> back off and retry; 5xx -> retry later.
  2. Verify the Authorization header input: ensure q.APIKey is set and valid for the Dashscope account.
  3. Confirm the BaseURL path matches the current Qwen TTS API version.
  4. Check account quota and model enablement in the provider console.

Example fix

// before
q := &core.QwenTTS{APIKey: os.Getenv("QWEN_KEY"), BaseURL: oldURL} // key may be ""
// after
key := os.Getenv("DASHSCOPE_API_KEY")
if key == "" { log.Fatal("DASHSCOPE_API_KEY not set") }
q := &core.QwenTTS{APIKey: key, BaseURL: currentAPIURL}
Defensive patterns

Strategy: try-catch

Validate before calling

// fail fast before first user request
if q.APIKey == "" {
    return fmt.Errorf("missing TTS API key (set DASHSCOPE_API_KEY)")
}

Try / catch

audio, _, err := q.Synthesize(ctx, text, opts)
if err != nil {
    var apiErr struct{ status string }
    if strings.HasPrefix(err.Error(), "qwen tts API ") {
        switch {
        case strings.Contains(err.Error(), "401"), strings.Contains(err.Error(), "403"):
            return fmt.Errorf("check your TTS API key/permissions")
        case strings.Contains(err.Error(), "429"):
            return retryAfterBackoff(ctx, text, opts)
        default:
            return err // 5xx: surface and retry later
        }
    }
    return err
}

Prevention

When it happens

Trigger: resp.StatusCode != http.StatusOK — e.g. 401 for a bad/expired API key, 403 quota/permission, 404 wrong endpoint path, 429 rate limited, 5xx server error.

Common situations: Missing or revoked DASHSCOPE API key; free-tier quota exhausted; base URL pointing to a wrong path after an API version change; model name not enabled for the account; upstream outage.

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/f212d54945ae0589. Report an issue: GitHub.