litellm/litellm
Alexsander Hamir ddb90c9ad7
[Fix] - Router: add model_name index for O(1) deployment lookups (#15113)
* perf(router): add model_name index for O(1) deployment lookups

Add model_name_to_deployment_indices mapping to optimize _get_all_deployments()
from O(n) to O(1) + O(k) lookups.

- Add model_name_to_deployment_indices: Dict[str, List[int]]
- Add _build_model_name_index() to build/maintain the index
- Update _add_model_to_list_and_index_map() to maintain both indices
- Refactor to use idx = len(self.model_list) before append (cleaner)
- Optimize _get_all_deployments() to use index instead of linear scan

* test(router): add test coverage for _build_model_name_index

Add single comprehensive test for _build_model_name_index() function to fix
code coverage CI failure.

The test verifies:
- Index correctly maps model_name to deployment indices
- Handles multiple deployments per model_name
- Clears and rebuilds index correctly

Fixes: CI code coverage error for _build_model_name_index
2025-10-06 08:14:11 -07:00
..
anthropic_interface
assistants
batch_completion
batches (feat)Litellm x twelvelabs bedrock[Async Invoke Support] (#14871) 2025-10-02 18:52:33 -07:00
caching [Fix] Cache - Avoiding expensive operations when cache isn't available (#15182) 2025-10-04 09:10:37 -07:00
completion_extras fix: fix import errors 2025-09-14 09:32:21 -07:00
endpoints/speech/speech_to_completion_bridge fix: fix import errors 2025-09-14 09:32:21 -07:00
experimental_mcp_client fix: resolve regression with duplicate Mcp-Protocol-Version header 2025-09-30 07:12:56 +09:00
files Litellm gemini batch (#14733) 2025-09-19 15:22:52 -07:00
fine_tuning
google_genai fix test /generateContent route 2025-10-04 10:49:46 -07:00
images Revert "#14404 BugFix - Add support for Azure AD token-based authorization in image generation request headers definition for Azure" 2025-09-24 16:23:20 +05:30
integrations OTEL fix spans 2025-10-04 09:22:57 -07:00
litellm_core_utils Merge branch 'main' into litellm_dev_09_30_2025_p1 2025-10-04 14:15:55 -07:00
llms feat(snowflake): add function calling support for Snowflake Cortex REST API 2025-10-05 13:08:33 +02:00
passthrough
proxy fix(key_management_endpoints.py): retain error check when non proxy admin is trying to update key belonging to a different user 2025-10-04 16:22:35 -07:00
realtime_api
rerank_api [Feat] Add Nvidia NIM Rerank Support (#15152) 2025-10-02 18:58:52 -07:00
responses [Feat] Return Cost for Responses API Streaming requests (#15053) 2025-09-29 19:47:04 -07:00
router_strategy fix: remove router inefficiencies (from O(M*N) to O(1)) - 62.5% faster P99 latency (#15046) 2025-09-29 15:49:46 -07:00
router_utils fix: fix import errors 2025-09-14 09:32:21 -07:00
secret_managers fix: use fastuuid helper (#14903) 2025-09-25 15:47:01 -07:00
types Revert "Add streamGenerateContent cost tracking in passthrough (#15199)" (#15202) 2025-10-04 14:37:02 -07:00
vector_stores
__init__.py ci/cd new release 2025-10-04 12:49:52 -07:00
_logging.py
_redis.py [Security] Fix: Ensure .info() logs are not used for request/responses + Add code QA check for possible violations (#14386) 2025-09-09 13:55:56 -07:00
_service_logger.py
_uuid.py Fix: revert fastuuid optional dependency, always use fastuuid in .__uid helper (#14941) 2025-09-26 09:14:20 -07:00
_version.py
budget_manager.py
constants.py fix OPENAI_EMBEDDING_PARAMS 2025-10-04 10:11:21 -07:00
cost_calculator.py Removing get_model_info from Lemonade provider. Implemented get_models which gets hooked into get_valid_models litellm utility. Also, added a simple cost calculator implementation for Lemonade so calling cost_calculator.completion_cost() doesn't return an error when a model is not found in the model_cost json. 2025-09-30 12:12:24 -06:00
cost.json
exceptions.py Revert "[Feature]: Replace HTTPException with ParallelRequestLimitError in pa…" (#15095) 2025-09-30 21:17:04 -07:00
main.py Merge branch 'BerriAI:main' into gemini-adapter-fixes 2025-10-01 09:53:51 +08:00
model_prices_and_context_window_backup.json Fix "azure_ai/grok-4-fast-reasoning" entry in "model_prices_and_context_window.json" (#15204) 2025-10-04 14:50:44 -07:00
mypy.ini fix mypy 2025-09-27 12:21:32 -07:00
py.typed
router.py [Fix] - Router: add model_name index for O(1) deployment lookups (#15113) 2025-10-06 08:14:11 -07:00
scheduler.py
timeout.py
utils.py [Fix] Cache - Avoiding expensive operations when cache isn't available (#15182) 2025-10-04 09:10:37 -07:00