{"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":"critical","filePath":"enterprise/litellm_enterprise/proxy/hooks/managed_files.py","lineNumber":1000,"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":982,"sourceCodeEnd":1018,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/enterprise/litellm_enterprise/proxy/hooks/managed_files.py#L982-L1018","documentation":"create_file_for_each_model fans a file upload out to each target model deployment via llm_router.acreate_file. If the proxy's Router is None at call time (no models loaded), it raises immediately: the managed-files feature cannot replicate uploads without live deployments. This indicates proxy misconfiguration or calling the hook before router initialization rather than a user input problem.","triggerScenarios":"Uploading a file through the proxy while model_list is empty or failed to load; invoking the hook during startup before initialize() completed; config YAML errors that left the router uninitialized but the HTTP server running.","commonSituations":"Fresh proxy installs with a broken config.yaml; DATABASE_URL-only setups where models come from DB but the router wasn't populated; tests that construct the hook directly without a Router.","solutions":["Check proxy startup logs for model-loading errors and fix the config (model_list entries, provider keys)","Verify GET /v1/models or /health returns the expected deployments before uploading files","If models come from the database, confirm they were synced and the router was re-initialized after adding them","In tests, pass a real Router instance with at least one deployment instead of None"],"exampleFix":"# before: hook invoked with no router\nawait hook.create_file_for_each_model(None, req, [\"gpt-4o\"], span)\n\n# after: build/populate the router first\nrouter = Router(model_list=[{\"model_name\": \"gpt-4o\", \"litellm_params\": {...}}])\nawait hook.create_file_for_each_model(router, req, [\"gpt-4o\"], span)","handlingStrategy":"fallback","validationCode":"# Before uploads, confirm the router is serving models\nhealth = await client.get(\"/health\")\nassert health[\"healthy_endpoints\"], \"no healthy deployments; fix model_list first\"","typeGuard":null,"tryCatchPattern":"try:\n    await proxy_upload_file(...)\nexcept Exception as e:\n    if \"LLM Router not initialized\" in str(e):\n        # configuration failure: do not retry; surface to operator\n        raise RuntimeError(\"proxy has no models loaded; check config\") from e\n    raise","preventionTips":["Add /health checks to deployment readiness gates before enabling file uploads","Validate config.yaml model entries in CI","Watch proxy startup logs for router initialization failures"],"tags":["configuration","router","files","startup"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}