MemPalace/mempalace · error · LLMError

openai-compat provider requires --llm-endpoint

Error message

openai-compat provider requires --llm-endpoint

What it means

LLMError raised by OpenAICompatProvider._resolve_url() when the provider was constructed without an endpoint. Unlike Ollama/Anthropic, the openai-compat provider has no default host — it targets any /v1/chat/completions server, so --llm-endpoint is mandatory.

Source

Thrown at mempalace/llm_client.py:311

    ):
        if api_key:
            resolved_key = api_key
            source: Optional[str] = "flag"
        else:
            env_key = os.environ.get("OPENAI_API_KEY")
            resolved_key = env_key or None
            source = "env" if env_key else None
        super().__init__(
            model=model,
            endpoint=endpoint,
            api_key=resolved_key,
            timeout=timeout,
            api_key_source=source,
        )

    def _resolve_url(self) -> str:
        if not self.endpoint:
            raise LLMError("openai-compat provider requires --llm-endpoint")
        url = self.endpoint.rstrip("/")
        if url.endswith("/chat/completions"):
            return url
        if not url.endswith("/v1"):
            url = f"{url}/v1"
        return f"{url}/chat/completions"

    def check_available(self) -> tuple[bool, str]:
        if not self.endpoint:
            return False, "no --llm-endpoint configured"
        base = self.endpoint.rstrip("/")
        base = base.removesuffix("/chat/completions").removesuffix("/v1")
        try:
            req = Request(f"{base}/v1/models")
            if self.api_key and (self.api_key_source != "env" or not self.is_external_service):
                req.add_header("Authorization", f"Bearer {self.api_key}")
            with urlopen(req, timeout=5):
                pass

View on GitHub (pinned to 06cb6987f0)

Solutions

  1. Pass the endpoint: build_provider("openai-compat", model="...", endpoint="http://localhost:8000")
  2. With or without /v1 is fine — the provider appends /v1/chat/completions as needed
  3. If the endpoint comes from config/env, validate it is non-empty at startup, not at first call

Example fix

# before
provider = build_provider("openai-compat", model="Qwen/Qwen2.5-7B-Instruct")
provider.classify(s, u)  # LLMError: openai-compat provider requires --llm-endpoint

# after
provider = build_provider("openai-compat", model="Qwen/Qwen2.5-7B-Instruct", endpoint="http://localhost:8000")
Defensive patterns

Strategy: validation

Validate before calling

provider = build_provider("openai-compat", model=m, endpoint=endpoint)
if not provider.endpoint:
    raise RuntimeError("--llm-endpoint is required for openai-compat")

Try / catch

from mempalace.llm_client import LLMError

try:
    provider.classify(s, u)
except LLMError as e:
    if "requires --llm-endpoint" in str(e):
        provider.endpoint = "http://localhost:8000"  # then retry
    else:
        raise

Prevention

When it happens

Trigger: build_provider("openai-compat", model=...) without passing endpoint (and no default resolution supplying one); the first classify() call then hits _resolve_url() and fails.

Common situations: Switching config from ollama to openai-compat (vLLM, LM Studio, llama.cpp server) and forgetting the endpoint flag; reading the endpoint from an env var that is unset so None propagates.

Related errors


AI-assisted analysis of MemPalace/mempalace@06cb6987f0 (2026-08-15). Data as JSON: /api/errors/4460464959c845cd. Report an issue: GitHub.