{"record":{"id":"74af9220eddaadd9","repo":"plandex-ai/plandex","slug":"error-creating-request-w","errorCode":null,"errorMessage":"error creating request: %w","messagePattern":"error creating request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/model/client.go","lineNumber":340,"sourceCode":"\tvar err error\n\tif openaiReq != nil {\n\t\tjsonBody, err = json.Marshal(openaiReq)\n\t} else {\n\t\tjsonBody, err = json.Marshal(extendedReq)\n\t}\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error marshaling request: %w\", err)\n\t}\n\n\t// log.Println(\"request jsonBody\", string(jsonBody))\n\n\t// Create new request\n\tbaseUrl := baseModelConfig.BaseUrl\n\turl := baseUrl + \"/chat/completions\"\n\n\treq, err := http.NewRequestWithContext(ctx, \"POST\", url, bytes.NewReader(jsonBody))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating request: %w\", err)\n\t}\n\n\t// Set required headers for streaming\n\treq.Header.Set(\"Content-Type\", \"application/json\")\n\treq.Header.Set(\"Accept\", \"text/event-stream\")\n\treq.Header.Set(\"Cache-Control\", \"no-cache\")\n\treq.Header.Set(\"Connection\", \"keep-alive\")\n\n\t// some providers send api key in the body, some in the header\n\t// some use other auth methods and so don't have a simple api key\n\tif client.ApiKey != \"\" {\n\t\treq.Header.Set(\"Authorization\", \"Bearer \"+client.ApiKey)\n\t}\n\tif client.OpenAIOrgId != \"\" {\n\t\treq.Header.Set(\"OpenAI-Organization\", client.OpenAIOrgId)\n\t}\n\n\taddOpenRouterHeaders(req)","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/client.go#L322-L358","documentation":"The library constructs the outgoing HTTP request with http.NewRequestWithContext(ctx, \"POST\", baseUrl+\"/chat/completions\", body). If that call fails, it returns \"error creating request: %w\". Since the body is a valid bytes.Reader, failure almost always means the URL failed to parse — i.e. baseUrl is empty or malformed — or the context was already invalid.","triggerScenarios":"createChatCompletionStreamExtended builds url := baseModelConfig.BaseUrl + \"/chat/completions\" and http.NewRequestWithContext fails because BaseUrl is empty (\"/chat/completions\" is a relative URL and http.NewRequest rejects it with http: nil Request.URL), contains spaces/illegal characters, has an unsupported scheme, or ctx is already done.","commonSituations":"Missing AZURE_API_BASE / provider base URL env var so BaseUrl resolves to empty string; base URL set with a trailing space or embedded quotes in an env file; using an \"localhost:8080\" value without the http:// scheme; DNS-style typos like \"https://api provider.com\".","solutions":["Log/inspect baseModelConfig.BaseUrl for this provider — it is usually empty or malformed; fix the provider base-URL env var (e.g. AZURE_API_BASE, OPENAI_API_BASE).","Ensure BaseUrl includes the scheme (https://...) and has no whitespace or quotes.","Add a startup config check that every provider's BaseUrl parses with url.Parse before serving traffic.","Sanitize: strings.TrimSpace the env value before assigning it to BaseUrl."],"exampleFix":"// before\nAZURE_API_BASE=\" https://myres.openai.azure.com \"  // leading/trailing space -> url parse error\n// after\nAZURE_API_BASE=https://myres.openai.azure.com\n// defensively in code:\nurl := strings.TrimSpace(baseModelConfig.BaseUrl) + \"/chat/completions\"","handlingStrategy":"validation","validationCode":"// validate the provider base URL before calling the API\nu, err := url.Parse(strings.TrimSpace(os.Getenv(\"AZURE_API_BASE\")))\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"provider base URL missing or invalid: %q\", os.Getenv(\"AZURE_API_BASE\"))\n}","typeGuard":"func isValidBaseURL(s string) bool {\n    u, err := url.Parse(strings.TrimSpace(s))\n    return err == nil && (u.Scheme == \"http\" || u.Scheme == \"https\") && u.Host != \"\"\n}","tryCatchPattern":"stream, err := client.CreateChatCompletionStream(ctx, req)\nif err != nil && strings.Contains(err.Error(), \"error creating request\") {\n    return fmt.Errorf(\"check the provider BaseUrl env var — it must be an absolute http(s) URL with no whitespace: %w\", err)\n}","preventionTips":["Always set base URLs as absolute https:// URLs; never leave the env var empty.","Trim whitespace and strip quotes from base-URL env values at load time.","Run url.Parse on every provider base URL during startup config validation.","Keep base URLs in one config layer rather than scattered across env files."],"tags":["go","http","url","configuration"],"backgroundTag":"invalid-base-url","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}