{"record":{"id":"643cb276f2b12494","repo":"infiniflow/ragflow","slug":"model-mdlnm-fid-not-authorized","errorCode":null,"errorMessage":"Model({mdlnm}@{fid}) not authorized","messagePattern":"Model\\((.+?)@(.+?)\\) not authorized","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"api/db/services/tenant_llm_service.py","lineNumber":171,"sourceCode":"            assert False, \"LLM type error\"\n\n        model_config = cls.get_api_key(tenant_id, mdlnm, llm_type)\n        mdlnm, fid = TenantLLMService.split_model_name_and_factory(mdlnm)\n        if not model_config:  # for some cases seems fid mismatch\n            model_config = cls.get_api_key(tenant_id, mdlnm, llm_type)\n        if model_config:\n            model_config = model_config.to_dict()\n            api_key, is_tools, api_key_payload = cls._decode_api_key_config(model_config.get(\"api_key\", \"\"))\n            model_config[\"api_key\"] = api_key\n            if api_key_payload is not None:\n                model_config[\"api_key_payload\"] = api_key_payload\n            if is_tools is not None:\n                model_config[\"is_tools\"] = is_tools\n        elif llm_type == LLMType.EMBEDDING and fid == \"Builtin\" and \"tei-\" in os.getenv(\"COMPOSE_PROFILES\", \"\") and mdlnm == os.getenv(\"TEI_MODEL\", \"\"):\n            embedding_cfg = settings.EMBEDDING_CFG\n            model_config = {\"llm_factory\": \"Builtin\", \"api_key\": embedding_cfg[\"api_key\"], \"llm_name\": mdlnm, \"api_base\": embedding_cfg[\"base_url\"]}\n        else:\n            raise LookupError(f\"Model({mdlnm}@{fid}) not authorized\")\n\n        llm = LLMService.query(llm_name=mdlnm) if not fid else LLMService.query(llm_name=mdlnm, fid=fid)\n        if not llm and fid:  # for some cases seems fid mismatch\n            llm = LLMService.query(llm_name=mdlnm)\n        if \"is_tools\" not in model_config and llm:\n            model_config[\"is_tools\"] = llm[0].is_tools\n        return model_config\n\n    @classmethod\n    @DB.connection_context()\n    def model_instance(cls, model_config: dict, lang=\"Chinese\", **kwargs):\n        if not model_config:\n            raise LookupError(\"Model config is required\")\n        from rag.llm import ChatModel, CvModel, EmbeddingModel, OcrModel, RerankModel, Seq2txtModel, TTSModel\n\n        kwargs.update({\"provider\": model_config[\"llm_factory\"]})\n        api_key = model_config.get(\"api_key_payload\", model_config[\"api_key\"])\n        if model_config[\"model_type\"] == LLMType.EMBEDDING.value:","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/api/db/services/tenant_llm_service.py#L153-L189","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["In the RAGFlow UI, add the model under Settings -> Model Providers with a valid API key, then retry.","Use the exact model name shown in the provider list, including the @factory suffix when applicable.","If relying on the built-in TEI embedding, ensure COMPOSE_PROFILES includes the TEI profile and TEI_MODEL matches the requested model name.","Check tenant_llm table rows for the tenant to confirm the model/llm_factory pair exists."],"exampleFix":"# before\n# model never added for tenant -> LookupError\ncfg = TenantLLMService.get_model_config(tenant_id, LLMType.CHAT, 'foo-model')\n\n# after\n# add the model via the API/UI first, or fall back to a configured one\ncfg = TenantLLMService.get_model_config(tenant_id, LLMType.CHAT, tenant.llm_id)","handlingStrategy":"try-catch","validationCode":"authorized = TenantLLMService.get_api_key(tenant_id, model_name, llm_type)\nif not authorized:\n    return json_error_response('model not configured for tenant; add it in Model Providers', 400)","typeGuard":null,"tryCatchPattern":"try:\n    cfg = TenantLLMService.get_model_config(tenant_id, llm_type, llm_name)\nexcept LookupError as e:\n    if 'not authorized' in str(e):\n        # prompt user to add the model in Settings -> Model Providers\n        return json_error_response('model not configured', 400)\n    raise","preventionTips":["Add and validate the model (with API key) in Model Providers before first use.","Prefer tenant default model ids (tenant.llm_id, tenant.embd_id) when the user has not chosen one.","For built-in TEI embeddings, verify COMPOSE_PROFILES and TEI_MODEL env vars match the requested model name."],"tags":["authorization","model-providers","llm","configuration","lookup-error"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}