BerriAI/litellm · critical · Exception

LLM Router not initialized. Ensure models added to proxy.

Error message

LLM Router not initialized. Ensure models added to proxy.

What it means

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.

Source

Thrown at enterprise/litellm_enterprise/proxy/hooks/managed_files.py:1000

            # Get all cache keys matching the pattern file_id:*
            for file_id in litellm_managed_file_ids:
                # Search for any cache key starting with this file_id
                unified_file_object = await self.get_unified_file_id(file_id, litellm_parent_otel_span)

                if unified_file_object:
                    file_id_mapping[file_id] = unified_file_object.model_mappings

        return file_id_mapping

    async def create_file_for_each_model(
        self,
        llm_router: Optional[Router],
        _create_file_request: CreateFileRequest,
        target_model_names_list: List[str],
        litellm_parent_otel_span: Span,
    ) -> List[OpenAIFileObject]:
        if llm_router is None:
            raise Exception("LLM Router not initialized. Ensure models added to proxy.")
        responses = []
        for model in target_model_names_list:
            individual_response = await llm_router.acreate_file(model=model, **_create_file_request)
            responses.append(individual_response)

        return responses

    async def acreate_file(
        self,
        create_file_request: CreateFileRequest,
        llm_router: Router,
        target_model_names_list: List[str],
        litellm_parent_otel_span: Span,
        user_api_key_dict: UserAPIKeyAuth,
    ) -> OpenAIFileObject:
        responses = await self.create_file_for_each_model(
            llm_router=llm_router,
            _create_file_request=create_file_request,

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Check proxy startup logs for model-loading errors and fix the config (model_list entries, provider keys)
  2. Verify GET /v1/models or /health returns the expected deployments before uploading files
  3. If models come from the database, confirm they were synced and the router was re-initialized after adding them
  4. In tests, pass a real Router instance with at least one deployment instead of None

Example fix

# before: hook invoked with no router
await hook.create_file_for_each_model(None, req, ["gpt-4o"], span)

# after: build/populate the router first
router = Router(model_list=[{"model_name": "gpt-4o", "litellm_params": {...}}])
await hook.create_file_for_each_model(router, req, ["gpt-4o"], span)
Defensive patterns

Strategy: fallback

Validate before calling

# Before uploads, confirm the router is serving models
health = await client.get("/health")
assert health["healthy_endpoints"], "no healthy deployments; fix model_list first"

Try / catch

try:
    await proxy_upload_file(...)
except Exception as e:
    if "LLM Router not initialized" in str(e):
        # configuration failure: do not retry; surface to operator
        raise RuntimeError("proxy has no models loaded; check config") from e
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/fb918c11773a807b. Report an issue: GitHub.