Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(models): skip non-dict litellm model_cost entries (#5537)
Guard fuzzy_match_models against list-valued metadata so sanity checks
do not raise AttributeError on attrs.get.
  • Loading branch information
lhl-lhi committed Sep 12, 2026
commit e2c9063a89e1053101a700b6daa7a4ea4fe0ae28
3 changes: 3 additions & 0 deletions aider/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,9 @@ def fuzzy_match_models(name):
model_metadata += list(model_info_manager.local_model_metadata.items())

for orig_model, attrs in model_metadata:
# litellm.model_cost occasionally yields non-dict values; skip them.
if not isinstance(attrs, dict):
continue
model = orig_model.lower()
if attrs.get("mode") != "chat":
continue
Expand Down
22 changes: 22 additions & 0 deletions tests/basic/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,28 @@ def test_gpt_5_5_model_settings(self):
self.assertEqual(model.editor_model.name, editor_name)
self.assertIn("reasoning_effort", model.accepts_settings)

def test_fuzzy_match_models_skips_non_dict_attrs(self):
"""litellm.model_cost can yield list values; do not AttributeError on .get."""
from aider.models import fuzzy_match_models, litellm, model_info_manager

fake_cost = {
"ok/chat-model": {"mode": "chat", "litellm_provider": "ok"},
"broken/list-entry": ["not", "a", "dict"],
}
mock_module = MagicMock()
mock_module.model_cost = fake_cost
original_lazy = litellm._lazy_module
original_local = model_info_manager.local_model_metadata
try:
litellm._lazy_module = mock_module
model_info_manager.local_model_metadata = {}
matches = fuzzy_match_models("chat-model")
finally:
litellm._lazy_module = original_lazy
model_info_manager.local_model_metadata = original_local

self.assertIn("ok/chat-model", matches)


if __name__ == "__main__":
unittest.main()