{"record":{"id":"e5cdf8e02fd56f05","repo":"micro/go-micro","slug":"failed-to-create-stream-request-w-e5cdf8","errorCode":null,"errorMessage":"failed to create stream request: %w","messagePattern":"failed to create stream request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ai/openai/openai.go","lineNumber":216,"sourceCode":"\t\t\"model\":          p.opts.Model,\n\t\t\"messages\":       messages,\n\t\t\"stream\":         true,\n\t\t\"stream_options\": map[string]any{\"include_usage\": true},\n\t}\n\tif p.opts.MaxTokens > 0 {\n\t\tapiReq[\"max_tokens\"] = p.opts.MaxTokens\n\t}\n\tif p.opts.Effort != \"\" {\n\t\tapiReq[\"reasoning_effort\"] = p.opts.Effort\n\t}\n\treqBody, err := json.Marshal(apiReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to marshal stream request: %w\", err)\n\t}\n\tapiURL := strings.TrimRight(p.opts.BaseURL, \"/\") + \"/v1/chat/completions\"\n\thttpReq, err := http.NewRequestWithContext(ctx, http.MethodPost, apiURL, bytes.NewReader(reqBody))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create stream request: %w\", err)\n\t}\n\thttpReq.Header.Set(\"Content-Type\", \"application/json\")\n\thttpReq.Header.Set(\"Accept\", \"text/event-stream\")\n\thttpReq.Header.Set(\"Authorization\", \"Bearer \"+p.opts.APIKey)\n\n\thttpResp, err := http.DefaultClient.Do(httpReq)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"stream API request failed: %w\", err)\n\t}\n\tif httpResp.StatusCode != http.StatusOK {\n\t\tdefer httpResp.Body.Close()\n\t\trespBody, _ := io.ReadAll(httpResp.Body)\n\t\treturn nil, fmt.Errorf(\"stream API error (%s): %s\", httpResp.Status, string(respBody))\n\t}\n\treturn &openAIStream{body: httpResp.Body, scanner: bufio.NewScanner(httpResp.Body)}, nil\n}\n\ntype openAIStream struct {","sourceCodeStart":198,"sourceCodeEnd":234,"githubUrl":"https://github.com/micro/go-micro/blob/24529f140421a11a33b6999ab7944f2021cfd69c/ai/openai/openai.go#L198-L234","documentation":"Thrown in the OpenAI provider's Stream when http.NewRequestWithContext fails to construct the HTTP request for the streaming chat-completions call. Per net/http this only fails on an invalid method or an unparseable URL, so it almost always indicates a malformed or empty BaseURL option.","triggerScenarios":"Calling Stream() when opts.BaseURL is empty, contains spaces/invalid characters, or lacks a scheme (e.g. \"localhost:8080\" or \"\"), producing a URL http.NewRequestWithContext cannot parse (apiURL = BaseURL + \"/v1/chat/completions\").","commonSituations":"BaseURL left at zero value because WithBaseURL was never called and no default applied; trailing typo in a config file (unquoted YAML value); users pointing at Azure/OpenRouter with a URL missing 'https://'.","solutions":["Set a valid absolute BaseURL, e.g. WithBaseURL(\"https://api.openai.com\")","Verify the configured URL parses: add 'https://' if the scheme is missing","Print/validate opts.BaseURL before constructing the provider","Check config loading so an empty env var doesn't overwrite the default BaseURL"],"exampleFix":"// before\nWithBaseURL(\"localhost:8080\")\n// after\nWithBaseURL(\"https://localhost:8080\")","handlingStrategy":"validation","validationCode":"u, err := url.Parse(baseURL)\nif err != nil || u.Scheme == \"\" || u.Host == \"\" {\n    return fmt.Errorf(\"invalid BaseURL %q\", baseURL)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always configure BaseURL with scheme and host","Validate the URL with url.Parse at provider construction","Reject empty env-derived BaseURLs with a fallback default","Add startup config validation that fails fast on bad URLs"],"tags":["http","configuration","openai","streaming","url"],"backgroundTag":"invalid-url","analyzedSha":"24529f140421a11a33b6999ab7944f2021cfd69c","analyzedAt":"2026-09-01T02:52:24.923Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}