From f58e109420a8748c7cb7345a99d5c94d8943c815 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Tue, 13 Jan 2026 16:38:24 -0800 Subject: [PATCH] Document allowed helper functions and exception process in _get_model_cost_key - Add documentation listing allowed helper functions with O(n) operations - Explain why these are acceptable (conditionally called) - Add instructions for adding new exceptions to check_get_model_cost_key_performance.py --- litellm/utils.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/litellm/utils.py b/litellm/utils.py index 848f0266db2..05118f5b892 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -5065,6 +5065,14 @@ def _get_model_cost_key(potential_key: str) -> Optional[str]: WARNING: Only O(1) lookup operations are acceptable. O(n) lookups will cause severe CPU overhead. This function is called frequently during router operations. + + ALLOWED HELPER FUNCTIONS (conditionally called, O(n) operations are acceptable): + - _rebuild_model_cost_lowercase_map: Rebuilds the lookup map (only when map is None) + - _handle_stale_map_entry_rebuild: Rebuilds map when stale entry detected (rare case) + + If you need to add a new helper function with O(n) operations that is conditionally + called and confirmed not to cause performance issues, add it to the allowed_helpers + list in: tests/code_coverage_tests/check_get_model_cost_key_performance.py """ global _model_cost_lowercase_map