alibaba/open-code-review · error

Base URL must use http or https scheme, got

Error message

Base URL must use http or https scheme, got %q

What it means

validateBaseURL requires the Base URL's scheme to be http or https; any other scheme (ftp://, file://, or a missing scheme where url.Parse yields an empty Scheme) is rejected with this message. This prevents saving endpoints the LLM HTTP client could never reach.

Solutions

  1. Prefix the URL with https:// (or http:// for local/insecure endpoints)
  2. Example: change "api.example.com/v1" to "https://api.example.com/v1"
  3. For local gateways use "http://localhost:8080/v1"
  4. Re-run the provider set command after fixing the scheme

Example fix

// before
$ ocr config provider set base-url api.example.com/v1
// error: Base URL must use http or https scheme, got ""
// after
$ ocr config provider set base-url https://api.example.com/v1
Defensive patterns

Strategy: validation

Validate before calling

u, _ := url.Parse(raw)
if u != nil && u.Scheme != "http" && u.Scheme != "https" {
    return fmt.Errorf("add http:// or https:// prefix to %q", raw)
}

Type guard

func hasHTTPScheme(raw string) bool {
    u, err := url.Parse(raw)
    return err == nil && (u.Scheme == "http" || u.Scheme == "https")
}

Try / catch

if err := applyProviderField(...); err != nil {
    if strings.Contains(err.Error(), "must use http or https scheme") {
        fmt.Fprintln(os.Stderr, "prefix the endpoint with https://")
    }
    return err
}

Prevention

When it happens

Trigger: applyProviderField receiving a Base URL like "api.example.com/v1" (no scheme), "ftp://...", or "localhost:8080" where url.Parse's Scheme ends up not http/https.

Common situations: Users omitting https:// when pasting hostnames; copying non-HTTP links from vendor docs; assuming a bare host:port string is a valid URL.

Related errors


AI-assisted analysis of alibaba/open-code-review@5cf97d0d15 (2026-09-02). Data as JSON: /api/errors/fcfe73309a402e1a. Report an issue: GitHub.

Appendix: source

Thrown at cmd/opencodereview/provider_cmd.go:456

	if key == "" {
		return "(not set)"
	}
	if len(key) <= 8 {
		return "***"
	}
	return key[:4] + "***" + key[len(key)-4:]
}

// validateBaseURL checks that a provider Base URL has an http or https scheme
// and a non-empty host, giving the user immediate feedback rather than
// a runtime failure when the LLM client tries to use it.
func validateBaseURL(raw string) error {
	parsed, err := url.Parse(raw)
	if err != nil {
		return fmt.Errorf("invalid Base URL %q: %w", raw, err)
	}
	if parsed.Scheme != "http" && parsed.Scheme != "https" {
		return fmt.Errorf("Base URL must use http or https scheme, got %q", parsed.Scheme)
	}
	if parsed.Host == "" {
		return fmt.Errorf("Base URL %q must include a host", raw)
	}
	return nil
}

View on GitHub (pinned to 5cf97d0d15)