JuliusBrussee/caveman · error

provider upstream URL must be absolute

Error message

provider %q upstream URL must be absolute

What it means

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.

Solutions

  1. Prefix the base URL with its scheme, e.g. https://myhost.com/v1
  2. Validate with url.Parse + IsAbs + Hostname() != "" before wiring the adapter
  3. Fix host-vs-scheme confusion: "localhost:8080" needs "http://" prepended

Example fix

// before
BaseURL: "api.openai.com/v1"
// after
BaseURL: "https://api.openai.com/v1"
Defensive patterns

Strategy: validation

Validate before calling

func validAbsoluteURL(s string) bool {
	u, err := url.Parse(s)
	return err == nil && u.IsAbs() && u.Hostname() != ""
}
// call before constructing adapter
if !validAbsoluteURL(cfg.BaseURL) { return fmt.Errorf("base URL %q must be absolute", cfg.BaseURL) }

Try / catch

u, err := adapter.ResolveUpstreamURL(ctx, req, route)
if err != nil && strings.Contains(err.Error(), "must be absolute") {
	// reject config / return 500 with correction hint
}

Prevention

When it happens

Trigger: 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").

Common situations: 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.

Understand the failure class

Background: "Invalid URL" errors: why new URL(), URI.parse, and reqwest::Url reject your string — missing scheme, whitespace, and bad path format — this error's family across 39 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/841c8e40fbe78c77. Report an issue: GitHub.

Appendix: source

Thrown at proxy/providers/adapter.go:475

		}
	}
	return false
}

func (b Base) ResolveUpstreamURL(ctx context.Context, req *http.Request, route RouteContext) (*url.URL, error) {
	baseURL := b.BaseURL
	if route.BaseURL != "" {
		baseURL = route.BaseURL
	}
	if strings.TrimSpace(baseURL) == "" {
		return nil, fmt.Errorf("provider %q has no configured upstream URL", b.Provider)
	}
	base, err := url.Parse(baseURL)
	if err != nil {
		return nil, err
	}
	if !base.IsAbs() || base.Hostname() == "" {
		return nil, fmt.Errorf("provider %q upstream URL must be absolute", b.Provider)
	}
	path := req.URL.Path
	for _, prefix := range []string{"/openai", "/anthropic", "/gemini", "/compat/stub", "/compat/openai-compatible"} {
		path = strings.TrimPrefix(path, prefix)
	}
	if strings.HasPrefix(req.URL.Path, "/azure/") {
		path = strings.TrimPrefix(req.URL.Path, "/azure")
	}
	base.Path = strings.TrimRight(base.Path, "/") + path
	base.RawQuery = req.URL.RawQuery
	return base, nil
}

func (b Base) SanitizeAndMapHeaders(ctx context.Context, req *http.Request, credential Credential, _ *url.URL) (http.Header, error) {
	out := http.Header{}
	copyIfPresent(out, req.Header, "content-type")
	copyIfPresent(out, req.Header, "content-encoding")
	copyIfPresent(out, req.Header, "accept")

View on GitHub (pinned to 3ee70a1026)