{"record":{"id":"45512b7fd9ed6260","repo":"BerriAI/litellm","slug":"llm-router-not-initialized-ensure-models-added-to-45512b","errorCode":null,"errorMessage":"LLM Router not initialized. Ensure models added to proxy.","messagePattern":"LLM Router not initialized\\. Ensure models added to proxy\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"critical","filePath":"litellm/llms/base_llm/managed_resources/base_managed_resource.py","lineNumber":384,"sourceCode":"        llm_router: Router,\n        request_data: dict[str, Any],\n        target_model_names_list: list[str],\n        litellm_parent_otel_span: Span,\n    ) -> list[ResourceObjectType]:\n        \"\"\"\n        Create a resource for each model in the target list.\n\n        Args:\n            llm_router: LiteLLM router instance\n            request_data: Request data for resource creation\n            target_model_names_list: List of target model names\n            litellm_parent_otel_span: OpenTelemetry span for tracing\n\n        Returns:\n            List of resource objects created for each model\n        \"\"\"\n        if llm_router is None:\n            raise Exception(\"LLM Router not initialized. Ensure models added to proxy.\")\n\n        responses: Final = []\n        for model in target_model_names_list:\n            individual_response = await self.create_resource_for_model(\n                llm_router=llm_router,\n                model=model,\n                request_data=request_data,\n                litellm_parent_otel_span=litellm_parent_otel_span,\n            )\n            responses.append(individual_response)\n        return responses\n\n    def generate_unified_resource_id(\n        self,\n        resource_objects: list[ResourceObjectType],\n        target_model_names_list: list[str],\n    ) -> str:\n        \"\"\"","sourceCodeStart":366,"sourceCodeEnd":402,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/llms/base_llm/managed_resources/base_managed_resource.py#L366-L402","documentation":"Raised when bulk resource creation (create_resources_for_models) is called with llm_router=None. Managed resources are created per model via router completions; without an initialized LiteLLM Router (no models added to the proxy) there is nothing to dispatch to, so the operation aborts before iterating models.","triggerScenarios":"Calling managed-resource bulk creation on a proxy instance whose router failed to initialize (no models in config.yaml, DB model list empty, startup error swallowed); unit tests that pass llm_router=None; programmatic use of the handler outside a running proxy.","commonSituations":"Config.yaml with an empty model_list; models stored in DB but Prisma not connected at startup; CI harness exercising managed resources without booting the router; refactors that bypass proxy initialization.","solutions":["Ensure the proxy config has at least one valid model under model_list and the router initialized before serving managed-resource requests.","If models come from the DB, verify DB connectivity and that the model table is populated.","Pass a live llm_router instance when invoking the handler programmatically.","Check proxy startup logs for earlier router-init failures instead of only seeing this downstream error."],"exampleFix":"# before\nawait handler.create_resources_for_models(llm_router=None, request_data=req, target_model_names_list=['gpt-4'])\n\n# after\nrouter = litellm.Router(model_list=[{'model_name': 'gpt-4', 'litellm_params': {'model': 'gpt-4o'}}])\nawait handler.create_resources_for_models(llm_router=router, request_data=req, target_model_names_list=['gpt-4'])","handlingStrategy":"validation","validationCode":"def router_ready(router) -> bool:\n    return router is not None and len(getattr(router, 'model_names', []) or router.get_model_names()) > 0","typeGuard":null,"tryCatchPattern":"try:\n    await handler.create_resources_for_models(llm_router=router, ...)\nexcept Exception as e:\n    if 'LLM Router not initialized' in str(e):\n        raise RuntimeError('proxy has no models; check model_list/DB') from e\n    raise","preventionTips":["Fail proxy startup loudly when model_list resolves to zero models.","Add a readiness endpoint asserting router is non-None before serving managed resources.","In tests, always construct a real Router with at least one stub model."],"tags":["managed-resources","router","initialization","proxy"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}