fix(proxy): capture model cost map count before deployment re-registration

This commit is contained in:
Devin AI 2026-07-10 07:40:00 +00:00
parent 832a53abc4
commit e33207a50e

View file

@ -6056,15 +6056,13 @@ class ProxyConfig:
model_cost_map_url = litellm.model_cost_map_url
new_model_cost_map = get_model_cost_map(url=model_cost_map_url)
models_count = len(new_model_cost_map) if new_model_cost_map else 0
litellm.model_cost = new_model_cost_map
# Invalidate case-insensitive lookup map since model_cost was replaced
_invalidate_model_cost_lowercase_map()
# Repopulate provider model sets (e.g. litellm.anthropic_models) so that
# wildcard patterns like "anthropic/*" include any newly added models.
litellm.add_known_models(model_cost_map=new_model_cost_map)
# Replacing model_cost wholesale drops per-deployment overrides
# (custom pricing, mode, ...); replay them so e.g. a configured
# mode=responses isn't reverted to the built-in mode=chat.
if llm_router is not None:
llm_router.re_register_deployments_in_model_cost()
@ -6096,9 +6094,7 @@ class ProxyConfig:
)
await invalidate_config_param("model_cost_map_reload_config")
verbose_proxy_logger.info(
f"Model cost map reloaded successfully. Models count: {len(new_model_cost_map) if new_model_cost_map else 0}"
)
verbose_proxy_logger.info(f"Model cost map reloaded successfully. Models count: {models_count}")
except Exception as e:
verbose_proxy_logger.exception(f"Error in _check_and_reload_model_cost_map: {str(e)}")
@ -15130,15 +15126,13 @@ async def reload_model_cost_map(
model_cost_map_url = litellm.model_cost_map_url
new_model_cost_map = get_model_cost_map(url=model_cost_map_url)
models_count = len(new_model_cost_map) if new_model_cost_map else 0
litellm.model_cost = new_model_cost_map
# Invalidate case-insensitive lookup map since model_cost was replaced
_invalidate_model_cost_lowercase_map()
# Repopulate provider model sets (e.g. litellm.anthropic_models) so that
# wildcard patterns like "anthropic/*" include any newly added models.
litellm.add_known_models(model_cost_map=new_model_cost_map)
# Replacing model_cost wholesale drops per-deployment overrides
# (custom pricing, mode, ...); replay them so e.g. a configured
# mode=responses isn't reverted to the built-in mode=chat.
if llm_router is not None:
llm_router.re_register_deployments_in_model_cost()
@ -15167,7 +15161,6 @@ async def reload_model_cost_map(
)
await invalidate_config_param("model_cost_map_reload_config")
models_count = len(new_model_cost_map) if new_model_cost_map else 0
verbose_proxy_logger.info(f"Model cost map reloaded successfully in current pod. Models count: {models_count}")
return {