chenhg5/cc-connect · error

qwen tts: create request: %w

Error message

qwen tts: create request: %w

What it means

After marshaling, Synthesize builds the HTTP POST request with http.NewRequestWithContext against q.BaseURL. If request construction fails (invalid method/URL, malformed base URL) the error is wrapped as 'qwen tts: create request'. It indicates the outgoing request could not even be created.

Source

Thrown at core/tts.go:141

	reqBody := map[string]any{
		"model": q.Model,
	}
	input := map[string]any{
		"text":  text,
		"voice": voice,
	}
	if opts.LanguageType != "" {
		input["language_type"] = opts.LanguageType
	}
	reqBody["input"] = input
	jsonData, err := json.Marshal(reqBody)
	if err != nil {
		return nil, "", fmt.Errorf("qwen tts: marshal request: %w", err)
	}

	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)
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check the TTS base_url in config.toml — it must be a full URL like https://dashscope.aliyuncs.com/api/v1/services/aigc/multimodal-generation/generation.
  2. Verify the env var backing BaseURL is set and has no stray whitespace or quotes.
  3. Validate the URL with url.ParseRequestURI before constructing the client/client options.

Example fix

// before
q := &core.QwenTTS{BaseURL: cfg.TTSBaseURL} // may be ""
// after
if u, err := url.Parse(cfg.TTSBaseURL); err != nil || u.Scheme == "" {
    log.Fatal("invalid tts base_url")
}
q := &core.QwenTTS{BaseURL: cfg.TTSBaseURL}
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.ParseRequestURI(cfg.TTSBaseURL)
if err != nil || u.Scheme != "https" && u.Scheme != "http" {
    return fmt.Errorf("invalid tts base_url: %q", cfg.TTSBaseURL)
}

Try / catch

audio, _, err := q.Synthesize(ctx, text, opts)
if err != nil && strings.Contains(err.Error(), "create request") {
    slog.Error("qwen tts: check base_url config", "err", err)
    return fmt.Errorf("TTS is misconfigured (check base_url): %w", err)
}

Prevention

When it happens

Trigger: http.NewRequestWithContext returns an error, almost always because q.BaseURL is not a valid absolute URL (empty, missing scheme, contains spaces or control characters).

Common situations: Config missing or mistyping the TTS base URL; env var for the endpoint unset leaving BaseURL empty; a trailing typo or whitespace pasted into the configured URL.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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