alibaba/open-code-review · error

resolve LLM endpoint: %w

Error message

resolve LLM endpoint: %w

What it means

loadLLMRuntime resolves the LLM endpoint via llm.ResolveEndpointWithOptions and wraps failure as `resolve LLM endpoint: %w`. Resolution combines the config file, environment, and CLI resolve options; it fails when no usable endpoint is configured (missing URL/api key, invalid provider, or conflicting options).

Source

Thrown at cmd/opencodereview/shared.go:239

	cfgPath, err := defaultConfigPath()
	if err != nil {
		return nil, err
	}
	appCfg, err := LoadAppConfig(cfgPath)
	if err != nil {
		return nil, fmt.Errorf("load app config: %w", err)
	}
	// Apply the language directive even when the config file is missing
	// (upstream #fix: ApplyLanguage with empty lang falls back to default).
	var lang string
	if appCfg != nil {
		lang = appCfg.Language
	}
	tpl.ApplyLanguage(lang)

	ep, err := llm.ResolveEndpointWithOptions(cfgPath, resolveOpts)
	if err != nil {
		return nil, fmt.Errorf("resolve LLM endpoint: %w", err)
	}

	retryCollector := newRetryCollector()

	return &llmRuntime{
		Client:         llm.NewLLMClient(ep, retryCollector),
		Model:          ep.Model,
		Provider:       ep.Provider,
		PlanToolDefs:   planToolDefs,
		MainToolDefs:   mainToolDefs,
		Collector:      tool.NewCommentCollector(),
		RetryCollector: retryCollector,
		AppCfg:         appCfg,
		RuntimeConfig: agent.RuntimeConfig{
			Protocol:     ep.Protocol,
			EndpointHost: sanitizeEndpointHost(ep.URL),
			Language:     lang,
			Timeout:      ep.Timeout,

View on GitHub (pinned to 5cf97d0d15)

Solutions

  1. Configure the LLM endpoint (URL + API key) in the config file or export the expected env variables
  2. If using flags/options, verify the provider name and URL are valid for your ocr version
  3. Check for typos in the endpoint URL (scheme, host, port)
  4. Confirm CI secrets are actually set in the job environment

Example fix

// before
export OPENAI_BASE_URL=api.openai.com/v1   # missing scheme
// after
export OPENAI_BASE_URL=https://api.openai.com/v1
export OPENAI_API_KEY=sk-...
Defensive patterns

Strategy: validation

Validate before calling

cfg, _ := LoadAppConfig(cfgPath)
if cfg == nil || cfg.Endpoint == "" && os.Getenv("OCR_LLM_URL") == "" {
	return errors.New("no LLM endpoint configured: set it in config or env before running")
}

Try / catch

if err != nil {
	if strings.Contains(err.Error(), "resolve LLM endpoint") {
		// prompt user to run setup or export credentials, don't retry blindly
	}
	return err
}

Prevention

When it happens

Trigger: ocr review/scan invoked with no endpoint in config and no env/flags supplying one; an explicit resolveOpts that references an unknown provider; malformed endpoint URL; missing required credentials for the chosen provider.

Common situations: Fresh install without running any setup; CI job missing the API-key env var; renamed env variables after a version upgrade; custom self-hosted endpoint URL with a typo; switching providers without updating credentials.

Related errors


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