BerriAI/litellm · error · 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 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.
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
Example fix
# before (config.yaml)
model_list: []
general_settings:
master_key: sk-1234
# after
model_list:
- model_name: gpt-4o
litellm_params:
model: openai/gpt-4o
api_key: os.environ/OPENAI_API_KEY
general_settings:
master_key: sk-1234 Defensive patterns
Strategy: validation
Validate before calling
from litellm.proxy import proxy_server
def managed_files_upload_ready() -> bool:
router = getattr(proxy_server, "llm_router", None)
return router is not None and len(router.get_model_names()) > 0
# only upload when ready
if managed_files_upload_ready():
await client.files.create(...) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- DB not connected. This endpoint needs a database; set…
- LLM router not found. Please set it up by passing in a…
- 503
- api_base is required
- api_base is required for hosted_vllm embeddings
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fb918c11773a807b.
Report an issue: GitHub.
Appendix: source
Thrown at enterprise/litellm_enterprise/proxy/hooks/managed_files.py:1017
# 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 77b7c6c40c)