infiniflow/ragflow · error · LookupError

Model({mdlnm}@{fid}) not authorized

Error message

Model({mdlnm}@{fid}) not authorized

What it means

Raised by TenantLLMService.get_model_config when no TenantLLM row authorizes the requested model: get_api_key(tenant_id, mdlnm, llm_type) found nothing (even after retry without factory id), and the special TEI/Builtin embedding exception did not apply. It means the tenant never added/enabled that model in RAGFlow's model providers.

Source

Thrown at api/db/services/tenant_llm_service.py:171

            assert False, "LLM type error"

        model_config = cls.get_api_key(tenant_id, mdlnm, llm_type)
        mdlnm, fid = TenantLLMService.split_model_name_and_factory(mdlnm)
        if not model_config:  # for some cases seems fid mismatch
            model_config = cls.get_api_key(tenant_id, mdlnm, llm_type)
        if model_config:
            model_config = model_config.to_dict()
            api_key, is_tools, api_key_payload = cls._decode_api_key_config(model_config.get("api_key", ""))
            model_config["api_key"] = api_key
            if api_key_payload is not None:
                model_config["api_key_payload"] = api_key_payload
            if is_tools is not None:
                model_config["is_tools"] = is_tools
        elif llm_type == LLMType.EMBEDDING and fid == "Builtin" and "tei-" in os.getenv("COMPOSE_PROFILES", "") and mdlnm == os.getenv("TEI_MODEL", ""):
            embedding_cfg = settings.EMBEDDING_CFG
            model_config = {"llm_factory": "Builtin", "api_key": embedding_cfg["api_key"], "llm_name": mdlnm, "api_base": embedding_cfg["base_url"]}
        else:
            raise LookupError(f"Model({mdlnm}@{fid}) not authorized")

        llm = LLMService.query(llm_name=mdlnm) if not fid else LLMService.query(llm_name=mdlnm, fid=fid)
        if not llm and fid:  # for some cases seems fid mismatch
            llm = LLMService.query(llm_name=mdlnm)
        if "is_tools" not in model_config and llm:
            model_config["is_tools"] = llm[0].is_tools
        return model_config

    @classmethod
    @DB.connection_context()
    def model_instance(cls, model_config: dict, lang="Chinese", **kwargs):
        if not model_config:
            raise LookupError("Model config is required")
        from rag.llm import ChatModel, CvModel, EmbeddingModel, OcrModel, RerankModel, Seq2txtModel, TTSModel

        kwargs.update({"provider": model_config["llm_factory"]})
        api_key = model_config.get("api_key_payload", model_config["api_key"])
        if model_config["model_type"] == LLMType.EMBEDDING.value:

View on GitHub (pinned to 554fb1133a)

Solutions

  1. In the RAGFlow UI, add the model under Settings -> Model Providers with a valid API key, then retry.
  2. Use the exact model name shown in the provider list, including the @factory suffix when applicable.
  3. If relying on the built-in TEI embedding, ensure COMPOSE_PROFILES includes the TEI profile and TEI_MODEL matches the requested model name.
  4. Check tenant_llm table rows for the tenant to confirm the model/llm_factory pair exists.

Example fix

# before
# model never added for tenant -> LookupError
cfg = TenantLLMService.get_model_config(tenant_id, LLMType.CHAT, 'foo-model')

# after
# add the model via the API/UI first, or fall back to a configured one
cfg = TenantLLMService.get_model_config(tenant_id, LLMType.CHAT, tenant.llm_id)
Defensive patterns

Strategy: try-catch

Validate before calling

authorized = TenantLLMService.get_api_key(tenant_id, model_name, llm_type)
if not authorized:
    return json_error_response('model not configured for tenant; add it in Model Providers', 400)

Try / catch

try:
    cfg = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name)
except LookupError as e:
    if 'not authorized' in str(e):
        # prompt user to add the model in Settings -> Model Providers
        return json_error_response('model not configured', 400)
    raise

Prevention

When it happens

Trigger: Requesting a chat/embedding/rerank model that the tenant has not configured; model name spelled differently from the provider entry (e.g. 'gpt-4o' vs 'gpt-4o@OpenAI' mismatch); using a tenant's default embd_id/llm_id pointing to a model whose TenantLLM row was removed; expecting the built-in TEI embedding without the teu COMPOSE_PROFILES/TEI_MODEL env setup.

Common situations: Fresh installs where users chat before adding an API key in Settings -> Model Providers; switching default models without re-adding credentials; renamed models after upgrade; TEI deployment env vars (COMPOSE_PROFILES, TEI_MODEL) not set so the Builtin embedding exception misses.

Related errors


AI-assisted analysis of infiniflow/ragflow@554fb1133a (2026-08-15). Data as JSON: /api/errors/643cb276f2b12494. Report an issue: GitHub.