{"record":{"id":"0c01967e0db591b7","repo":"chenhg5/cc-connect","slug":"gemini-stt-create-request-w","errorCode":null,"errorMessage":"gemini stt: create request: %w","messagePattern":"gemini stt: create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/speech.go","lineNumber":260,"sourceCode":"\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\t\"text\": prompt,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t},\n\t}\n\n\tjsonData, err := json.Marshal(reqBody)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gemini stt: marshal request: %w\", err)\n\t}\n\n\tapiURL := fmt.Sprintf(\"%s/models/%s:generateContent\", g.BaseURL, url.PathEscape(g.Model))\n\treq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(jsonData))\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gemini stt: create request: %w\", err)\n\t}\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"x-goog-api-key\", g.APIKey)\n\n\tresp, err := g.Client.Do(req)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gemini stt: request: %w\", err)\n\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"gemini stt: read response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\treturn \"\", fmt.Errorf(\"gemini stt API %d: %s\", resp.StatusCode, string(body))\n\t}","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/speech.go#L242-L278","documentation":"Thrown by GeminiSTT.Transcribe in core/speech.go when http.NewRequestWithContext fails to construct the POST request to the Gemini generateContent endpoint. This is a client-side URL/parameter construction failure before any network traffic occurs.","triggerScenarios":"http.NewRequestWithContext returns an error — almost always because the assembled apiURL is malformed, e.g. BaseURL contains spaces or invalid characters, or BaseURL is empty causing a relative/invalid URL.","commonSituations":"BaseURL in config.toml has a typo, trailing whitespace/newline, or quotes; environment variable substitution left the BaseURL empty; pasted URL contains invisible characters.","solutions":["Check the error's url.Parse message and fix the Gemini BaseURL in config.toml (should be like https://generativelanguage.googleapis.com/v1beta).","Ensure no stray spaces, quotes, or newlines around the configured URL.","Verify the provider's env var/config key is actually set so BaseURL isn't empty.","Test the URL with curl to confirm it forms a valid endpoint."],"exampleFix":"// before\nBaseURL = \"https://generativelanguage.googleapis.com/v1beta \" // trailing space\n// after\nBaseURL = \"https://generativelanguage.googleapis.com/v1beta\"","handlingStrategy":"validation","validationCode":"u, err := url.Parse(g.BaseURL)\nif err != nil || u.Scheme != \"https\" || u.Host == \"\" {\n    return fmt.Errorf(\"gemini: invalid BaseURL %q\", g.BaseURL)\n}","typeGuard":null,"tryCatchPattern":"text, err := stt.Transcribe(ctx, audio)\nif err != nil {\n    if strings.Contains(err.Error(), \"create request\") {\n        return fmt.Errorf(\"gemini: check BaseURL config: %w\", err)\n    }\n    return err\n}","preventionTips":["Validate BaseURL with url.Parse at provider construction time, not per-request.","Trim whitespace/quotes from config values when loading config.toml.","Fail fast at startup with a doctor check if the URL is malformed.","Keep BaseURL to the documented form: https://generativelanguage.googleapis.com/v1beta."],"tags":["http","url","speech-to-text","gemini","config"],"backgroundTag":"invalid-url","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"}