chenhg5/cc-connect · error
create request: %w
Error message
create request: %w
What it means
http.NewRequestWithContext failed while constructing the POST to BaseURL + '/audio/transcriptions'. NewRequestWithContext returns an error for an unparseable/invalid URL or an unsupported method, so this points at a malformed BaseURL configured on the OpenAIWhisper instance.
Source
Thrown at core/speech.go:79
part, err := writer.CreateFormFile("file", "audio."+ext)
if err != nil {
return "", fmt.Errorf("create form file: %w", err)
}
if _, err := part.Write(audio); err != nil {
return "", fmt.Errorf("write audio: %w", err)
}
_ = writer.WriteField("model", w.Model)
_ = writer.WriteField("response_format", "text")
if lang != "" {
_ = writer.WriteField("language", lang)
}
writer.Close()
url := w.BaseURL + "/audio/transcriptions"
req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, &buf)
if err != nil {
return "", fmt.Errorf("create request: %w", err)
}
req.Header.Set("Authorization", "Bearer "+w.APIKey)
req.Header.Set("Content-Type", writer.FormDataContentType())
resp, err := w.Client.Do(req)
if err != nil {
return "", fmt.Errorf("whisper request: %w", err)
}
defer resp.Body.Close()
body, err := io.ReadAll(resp.Body)
if err != nil {
return "", fmt.Errorf("read response: %w", err)
}
if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("whisper API %d: %s", resp.StatusCode, string(body))
}View on GitHub (pinned to 4000b2338a)
Solutions
- Check BaseURL for missing scheme — it must start with http:// or https://
- Trim whitespace/newlines from the configured base_url value
- Validate the URL with url.Parse before constructing OpenAIWhisper
- Fall back to the default https://api.openai.com/v1 (NewOpenAIWhisper does this only when BaseURL is empty, not invalid)
Example fix
// before (config.toml) base_url = "api.openai.com/v1" // after base_url = "https://api.openai.com/v1"
Defensive patterns
Strategy: validation
Validate before calling
u, err := url.Parse(cfg.BaseURL)
if err != nil || u.Scheme == "" || u.Host == "" {
return fmt.Errorf("invalid whisper base_url %q: %w", cfg.BaseURL, err)
} Try / catch
text, err := stt.Transcribe(ctx, audio, format, lang)
if err != nil && strings.Contains(err.Error(), "create request") {
slog.Error("whisper base_url is malformed", "err", err)
return ""
} Prevention
- Always include the https:// scheme in base_url config values
- Trim whitespace from URL values loaded from env/config
- Run url.Parse on configured URLs at startup (fail fast), not at request time
When it happens
Trigger: Transcribe called with OpenAIWhisper.BaseURL containing invalid URL syntax (spaces, control characters, missing scheme such as 'api.openai.com/v1' without https://).
Common situations: Typo or bad paste in config.toml for the whisper base_url; missing scheme; trailing whitespace or newline in an env-provided URL; misconfigured self-hosted proxy 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
- reasonix: create request: %w
- gemini stt: create request: %w
- yuanbao: create request: %w
- url is required for type=http
- providerproxy: parse target: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/c56882469918216d.
Report an issue: GitHub.