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

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.

Source

Thrown at litellm/llms/base_llm/managed_resources/base_managed_resource.py:384

        llm_router: Router,
        request_data: dict[str, Any],
        target_model_names_list: list[str],
        litellm_parent_otel_span: Span,
    ) -> list[ResourceObjectType]:
        """
        Create a resource for each model in the target list.

        Args:
            llm_router: LiteLLM router instance
            request_data: Request data for resource creation
            target_model_names_list: List of target model names
            litellm_parent_otel_span: OpenTelemetry span for tracing

        Returns:
            List of resource objects created for each model
        """
        if llm_router is None:
            raise Exception("LLM Router not initialized. Ensure models added to proxy.")

        responses: Final = []
        for model in target_model_names_list:
            individual_response = await self.create_resource_for_model(
                llm_router=llm_router,
                model=model,
                request_data=request_data,
                litellm_parent_otel_span=litellm_parent_otel_span,
            )
            responses.append(individual_response)
        return responses

    def generate_unified_resource_id(
        self,
        resource_objects: list[ResourceObjectType],
        target_model_names_list: list[str],
    ) -> str:
        """

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Ensure the proxy config has at least one valid model under model_list and the router initialized before serving managed-resource requests.
  2. If models come from the DB, verify DB connectivity and that the model table is populated.
  3. Pass a live llm_router instance when invoking the handler programmatically.
  4. Check proxy startup logs for earlier router-init failures instead of only seeing this downstream error.

Example fix

# before
await handler.create_resources_for_models(llm_router=None, request_data=req, target_model_names_list=['gpt-4'])

# after
router = litellm.Router(model_list=[{'model_name': 'gpt-4', 'litellm_params': {'model': 'gpt-4o'}}])
await handler.create_resources_for_models(llm_router=router, request_data=req, target_model_names_list=['gpt-4'])
Defensive patterns

Strategy: validation

Validate before calling

def router_ready(router) -> bool:
    return router is not None and len(getattr(router, 'model_names', []) or router.get_model_names()) > 0

Try / catch

try:
    await handler.create_resources_for_models(llm_router=router, ...)
except Exception as e:
    if 'LLM Router not initialized' in str(e):
        raise RuntimeError('proxy has no models; check model_list/DB') from e
    raise

Prevention

When it happens

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

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

Related errors


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