{"record":{"id":"841c8e40fbe78c77","repo":"JuliusBrussee/caveman","slug":"provider-q-upstream-url-must-be-absolute","errorCode":null,"errorMessage":"provider %q upstream URL must be absolute","messagePattern":"provider %q upstream URL must be absolute","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"proxy/providers/adapter.go","lineNumber":475,"sourceCode":"\t\t}\n\t}\n\treturn false\n}\n\nfunc (b Base) ResolveUpstreamURL(ctx context.Context, req *http.Request, route RouteContext) (*url.URL, error) {\n\tbaseURL := b.BaseURL\n\tif route.BaseURL != \"\" {\n\t\tbaseURL = route.BaseURL\n\t}\n\tif strings.TrimSpace(baseURL) == \"\" {\n\t\treturn nil, fmt.Errorf(\"provider %q has no configured upstream URL\", b.Provider)\n\t}\n\tbase, err := url.Parse(baseURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif !base.IsAbs() || base.Hostname() == \"\" {\n\t\treturn nil, fmt.Errorf(\"provider %q upstream URL must be absolute\", b.Provider)\n\t}\n\tpath := req.URL.Path\n\tfor _, prefix := range []string{\"/openai\", \"/anthropic\", \"/gemini\", \"/compat/stub\", \"/compat/openai-compatible\"} {\n\t\tpath = strings.TrimPrefix(path, prefix)\n\t}\n\tif strings.HasPrefix(req.URL.Path, \"/azure/\") {\n\t\tpath = strings.TrimPrefix(req.URL.Path, \"/azure\")\n\t}\n\tbase.Path = strings.TrimRight(base.Path, \"/\") + path\n\tbase.RawQuery = req.URL.RawQuery\n\treturn base, nil\n}\n\nfunc (b Base) SanitizeAndMapHeaders(ctx context.Context, req *http.Request, credential Credential, _ *url.URL) (http.Header, error) {\n\tout := http.Header{}\n\tcopyIfPresent(out, req.Header, \"content-type\")\n\tcopyIfPresent(out, req.Header, \"content-encoding\")\n\tcopyIfPresent(out, req.Header, \"accept\")","sourceCodeStart":457,"sourceCodeEnd":493,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/proxy/providers/adapter.go#L457-L493","documentation":"ResolveUpstreamURL parses the resolved base URL and requires it to be an absolute URL with a hostname. A relative URL (e.g. \"/v1\") or one missing a host cannot serve as a proxy target, so it rejects with this error naming the provider.","triggerScenarios":"BaseURL or RouteContext.BaseURL set to a relative path like \"/api\" or a malformed value like \"localhost:8080/v1\" (parsed as scheme \"localhost\" with no host), or a URL missing the scheme entirely (\"myhost.com\").","commonSituations":"Copy-pasting just the path portion of an API endpoint; omitting the https:// scheme; relying on a config value intended to be a suffix path, not a base URL; environment-specific configs where one region left the scheme off.","solutions":["Prefix the base URL with its scheme, e.g. https://myhost.com/v1","Validate with url.Parse + IsAbs + Hostname() != \"\" before wiring the adapter","Fix host-vs-scheme confusion: \"localhost:8080\" needs \"http://\" prepended"],"exampleFix":"// before\nBaseURL: \"api.openai.com/v1\"\n// after\nBaseURL: \"https://api.openai.com/v1\"","handlingStrategy":"validation","validationCode":"func validAbsoluteURL(s string) bool {\n\tu, err := url.Parse(s)\n\treturn err == nil && u.IsAbs() && u.Hostname() != \"\"\n}\n// call before constructing adapter\nif !validAbsoluteURL(cfg.BaseURL) { return fmt.Errorf(\"base URL %q must be absolute\", cfg.BaseURL) }","typeGuard":null,"tryCatchPattern":"u, err := adapter.ResolveUpstreamURL(ctx, req, route)\nif err != nil && strings.Contains(err.Error(), \"must be absolute\") {\n\t// reject config / return 500 with correction hint\n}","preventionTips":["Always include scheme (https://) in base URL config values","Normalize host:port values by prefixing http:// when the scheme is missing","Unit-test URL parsing of every configured provider endpoint"],"tags":["url","configuration","proxy"],"backgroundTag":"invalid-url-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}