fix(router): fallback for ModelNotMappedError in get_router_model_info (#47922)

Complexity-router compaction calls get_router_model_info for every
candidate deployment. On 1.106.0 with LITELLM_ENABLE_MCP_STDIO=true,
deployed MCP stdio models are not in model_cost, so
litellm.get_model_info raises ModelNotMappedError and crashes
/chat/completions via context_compaction._budget.

Wrap get_model_info in try/except: on ModelNotMappedError return a
minimal fallback ModelMapInfo with null windows and zero costs so
compaction treats the model as uncompactable instead of crashing
the request.
This commit is contained in:
ryder777777 2026-10-22 15:33:20 +00:00
parent f2118fc767
commit f35382de56

View file

@ -12198,7 +12198,27 @@ class Router:
else:
model_info_name = model
model_info: Final = litellm.get_model_info(model=model_info_name)
try:
model_info: Final = litellm.get_model_info(model=model_info_name)
except Exception as e:
if e.__class__.__name__ == "ModelNotMappedError" or "not mapped" in str(e).lower():
verbose_router_logger.warning(
"Model '%s' not mapped in model_cost; returning fallback info for compaction/budget checks: %s",
model_info_name,
e,
)
fallback: ModelMapInfo = {
"key": model_info_name,
"max_tokens": None,
"max_input_tokens": None,
"max_output_tokens": None,
"input_cost_per_token": 0,
"output_cost_per_token": 0,
"litellm_provider": custom_llm_provider or "",
"mode": "chat",
}
return fallback
raise
if model_info is None:
return model_info