Skip to content

fix(router): resolve model_group_alias in pre-routing hook - #27540

Closed
Jwrede wants to merge 3 commits into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/complexity-router-alias-resolution
Closed

fix(router): resolve model_group_alias in pre-routing hook#27540
Jwrede wants to merge 3 commits into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/complexity-router-alias-resolution

Conversation

@Jwrede

@Jwrede Jwrede commented May 9, 2026

Copy link
Copy Markdown

Relevant issues

Fixes #27473

Pre-Submission checklist

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

Type

Bug Fix

Changes

Router.async_pre_routing_hook looks up model in self.complexity_routers, self.auto_routers, self.quality_routers, and self.adaptive_routers -- but when the caller passes a model_group_alias name (e.g. claude-sonnet-4-6) instead of the actual group name (e.g. internal-ai), none of the maps match. The hook returns None, the raw auto_router/complexity_router deployment is selected as-is, and litellm.acompletion(model="auto_router/complexity_router") fails with BadRequestError: Unmapped LLM provider.

The fix adds alias resolution via self._get_model_from_alias(model) at the top of async_pre_routing_hook, before any router map lookups. This is the same utility already used in _common_checks_available_deployment for the sync path.

Test plan

Added 6 unit tests in tests/test_litellm/router_utils/test_pre_routing_hook_alias_resolution.py:

  • Alias resolves to complexity_router
  • Alias resolves to auto_router
  • Alias resolves to quality_router
  • Non-alias model still matches directly (no regression)
  • Unknown model with no alias returns None
  • Dict-format alias (with hidden key) resolves correctly

yuneng-berri and others added 2 commits May 7, 2026 18:05
When a model_group_alias points to a complexity_router (or auto_router,
quality_router, adaptive_router) group, calling completion() with the
alias name skips the pre-routing hook because the alias is not found in
the router maps. The hook returns None, the raw auto_router deployment
is selected, and litellm.acompletion fails with "Unmapped LLM provider".

Resolve aliases at the top of async_pre_routing_hook using the existing
_get_model_from_alias() utility so the resolved group name is used for
all router map lookups.

Fixes BerriAI#27473
@Jwrede

Jwrede commented May 9, 2026

Copy link
Copy Markdown
Author

@greptileai

@greptile-apps

greptile-apps Bot commented May 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes Router.async_pre_routing_hook silently returning None when callers pass a model_group_alias name instead of the real group name, causing litellm.acompletion to fail with BadRequestError: Unmapped LLM provider. The fix inserts a single alias-resolution call (_get_model_from_alias) at the top of the hook, consistent with how the sync path already handles aliases.

  • litellm/router.py: Four lines added before the router-map lookups to resolve the alias via the existing _get_model_from_alias helper; no other logic is changed.
  • tests/test_litellm/router_utils/test_pre_routing_hook_alias_resolution.py: Six new mock-only unit tests covering alias resolution for complexity_routers, auto_routers, quality_routers, direct-name (no-regression), unknown-model, and dict-format alias cases.

Confidence Score: 4/5

Safe to merge; the change is a minimal, well-scoped guard in a pre-routing hook with no impact on non-alias flows.

The production fix is four lines touching only async_pre_routing_hook, using an already-proven helper that the sync path relies on. Tests are mock-only and cover the three most common router types; the adaptive_routers branch is the one gap, which is a minor test-coverage miss rather than a functional defect.

No files require special attention; tests/test_litellm/router_utils/test_pre_routing_hook_alias_resolution.py could add an adaptive_routers case for completeness.

Important Files Changed

Filename Overview
litellm/router.py Adds a 4-line alias resolution guard at the top of async_pre_routing_hook using the existing _get_model_from_alias helper; minimal, targeted, and consistent with the sync path.
tests/test_litellm/router_utils/test_pre_routing_hook_alias_resolution.py New mock-only unit tests covering alias resolution for complexity, auto, and quality routers, plus direct-name and unknown-model cases; adaptive_routers branch is not tested.

Reviews (1): Last reviewed commit: "fix(router): resolve model_group_alias b..." | Re-trigger Greptile

Comment on lines +55 to +60
router.auto_routers[target_group] = mock_sub_router
elif router_type == "quality":
router.quality_routers[target_group] = mock_sub_router

return router

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 No test for adaptive_routers alias resolution

async_pre_routing_hook has four router-map branches: auto_routers, complexity_routers, adaptive_routers, and quality_routers. The suite covers three of them but skips adaptive_routers. If a regression were introduced that accidentally excluded adaptive_routers from the alias-resolution path, these tests would not catch it.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four router types are covered -- see test_alias_resolves_to_adaptive_router in the test file. The _make_router_with_alias helper accepts router_type="adaptive" and the test class has a dedicated test case for it.

Cover the adaptive_routers branch in async_pre_routing_hook, completing
test coverage for all four router map types.
@abdulrahman-mpt

Copy link
Copy Markdown

Any update on the PR review for this issue? Would it be possible to get another reviewer to help move this forward?

@Jwrede

Jwrede commented May 15, 2026

Copy link
Copy Markdown
Author

Friendly ping @ishaan-jaff @krrish-berri-2 -- this fixes model_group_alias resolution in the pre-routing hook (causes 400 errors with complexity_router/auto_router). Happy to address any feedback.

@nicolaas-taljaard

Copy link
Copy Markdown

Hi any update on the MR? The issue it's linked to is a blocker.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions Bot added the stale label Aug 14, 2026
@github-actions github-actions Bot closed this Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: v1.83.14 auto_router/complexity_router in litellm_params throws "Unmapped LLM provider" 400 error

5 participants