{"record":{"id":"fb918c11773a807b","repo":"BerriAI/litellm","slug":"llm-router-not-initialized-ensure-models-added-to","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":"error","filePath":"enterprise/litellm_enterprise/proxy/hooks/managed_files.py","lineNumber":1017,"sourceCode":"            # Get all cache keys matching the pattern file_id:*\n            for file_id in litellm_managed_file_ids:\n                # Search for any cache key starting with this file_id\n                unified_file_object = await self.get_unified_file_id(file_id, litellm_parent_otel_span)\n\n                if unified_file_object:\n                    file_id_mapping[file_id] = unified_file_object.model_mappings\n\n        return file_id_mapping\n\n    async def create_file_for_each_model(\n        self,\n        llm_router: Optional[Router],\n        _create_file_request: CreateFileRequest,\n        target_model_names_list: List[str],\n        litellm_parent_otel_span: Span,\n    ) -> List[OpenAIFileObject]:\n        if llm_router is None:\n            raise Exception(\"LLM Router not initialized. Ensure models added to proxy.\")\n        responses = []\n        for model in target_model_names_list:\n            individual_response = await llm_router.acreate_file(model=model, **_create_file_request)\n            responses.append(individual_response)\n\n        return responses\n\n    async def acreate_file(\n        self,\n        create_file_request: CreateFileRequest,\n        llm_router: Router,\n        target_model_names_list: List[str],\n        litellm_parent_otel_span: Span,\n        user_api_key_dict: UserAPIKeyAuth,\n    ) -> OpenAIFileObject:\n        responses = await self.create_file_for_each_model(\n            llm_router=llm_router,\n            _create_file_request=create_file_request,","sourceCodeStart":999,"sourceCodeEnd":1035,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/enterprise/litellm_enterprise/proxy/hooks/managed_files.py#L999-L1035","documentation":"Raised by ManagedFilesHook.create_file_for_each_model when llm_router is None. In managed-files mode a single POST /v1/files upload is fanned out to one real upload per target model, and each goes through llm_router.acreate_file (routed from litellm/proxy/openai_files_endpoints/files_endpoints.py:243 when the 'managed_files' hook is active). With no router the proxy has zero deployments, so the hook fails fast before contacting any provider.","triggerScenarios":"POST /v1/files with managed files enabled while proxy_server.llm_router is None: config.yaml has no (or an empty) model_list, DB-backed models failed to load at startup, or the request arrives before router initialization completes.","commonSituations":"First-run proxy yaml with general_settings configured but model_list omitted; models expected from the database while DATABASE_URL is unset so nothing loads; integration tests that call the hook directly without passing a Router.","solutions":["Add at least one entry under model_list in the proxy config and restart so llm_router initializes","If models load from the database, check startup logs for router init errors and fix the root cause (DATABASE_URL set, migrations applied, DB reachable)","Wait for /health/liveliness to report the router ready before sending file uploads","Programmatic callers: pass a live Router (proxy_server.llm_router) instead of None"],"exampleFix":"# before (config.yaml)\nmodel_list: []\ngeneral_settings:\n  master_key: sk-1234\n\n# after\nmodel_list:\n  - model_name: gpt-4o\n    litellm_params:\n      model: openai/gpt-4o\n      api_key: os.environ/OPENAI_API_KEY\ngeneral_settings:\n  master_key: sk-1234","handlingStrategy":"validation","validationCode":"from litellm.proxy import proxy_server\n\ndef managed_files_upload_ready() -> bool:\n    router = getattr(proxy_server, \"llm_router\", None)\n    return router is not None and len(router.get_model_names()) > 0\n\n# only upload when ready\nif managed_files_upload_ready():\n    await client.files.create(...)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always define a non-empty model_list before enabling managed files","Probe /health/liveliness after startup and gate file uploads on it","Add a startup assertion in CI configs that llm_router is not None"],"tags":["litellm","litellm-proxy","managed-files","configuration","router"],"backgroundTag":"router-not-initialized","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}