Skip to content

feat(router): limit heuristic_v2 auto-routers to one without the auto_router license feature - #39468

Merged
tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_heuristic_v2_license
Sep 3, 2026
Merged

tin-berri merged 1 commit into
litellm_internal_stagingfrom
litellm_heuristic_v2_license

Conversation

@tin-berri

@tin-berri tin-berri commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • classifier_type: heuristic_v2 ships with no entitlement check at all
  • Any proxy can run unlimited heuristic_v2 auto-routers from config.yaml or the API
  • A plain enterprise license has no way to express an auto-router add-on

How it solves it:

  • Signed license allowed_features containing auto_router lifts the limit
  • Without it a proxy holds one heuristic_v2 auto-router (config.yaml and DB combined)
  • config.yaml over the limit refuses to start with the reason
  • /model/new, /model/update, PATCH /model/{id}/update refuse with a 403 before the DB write
  • The Router refuses an extra heuristic_v2 router at registration, so DB rows are covered too
  • The rollback after a failed upsert re-admits state that was already serving, so it is exempt from the ceiling: an edit of a live heuristic_v2 router that fails, including one refused by a ceiling that has since tightened, leaves the router serving its previous configuration instead of vanishing
  • A write that leaves a row on heuristic_v2 under a limited license runs in one transaction that takes a Postgres advisory lock (pg_advisory_xact_lock) before counting the DB rows plus this proxy's config.yaml routers, so concurrent writes on any pod cannot both claim the sole slot and no surplus row is ever persisted; no migration, no new column. Only the row write runs under the lock; the team model bookkeeping, which needs a second pool connection, runs after the transaction has committed. PATCH /model/{id}/update now orders itself like create (row first, team list second), so a refused write leaves the team's model list untouched. The slot transaction bypasses the repository's publish-on-write, so it publishes the config change to other pods once after commit, the way delete_team_models does
  • Expiry follows the existing max_users / max_teams pattern: the signed payload is judged when the license is verified, and the limit reads that payload at each write and registration; a verify that rejects the license (expired or unreadable) leaves no payload behind

User Flow

Before: an operator on a plain enterprise license (or no license) runs as many heuristic_v2 auto-routers as they like

  1. They start the proxy with two auto_router/complexity_router entries set to classifier_type: heuristic_v2 in config.yaml; both show up in GET /model/info
  2. They send POST /model/new with a third heuristic_v2 router and get 200 with a new model id
  3. All three serve traffic

After: the same operator gets exactly one heuristic_v2 auto-router until the license carries the auto_router feature

  1. They start the proxy with two heuristic_v2 routers in config.yaml; startup fails with config.yaml model_list: At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.
  2. They drop one and start again; the one router serves traffic
  3. They send POST /model/new with a second heuristic_v2 router and get 403 with the same message; POST /model/new with a classifier_type: heuristic router still gets 200
  4. A heuristic_v2 row created in the DB while the license still had the feature is not loaded after a restart without it; the server log names it with the same message
  5. Their license is re-issued with "allowed_features": ["auto_router"] and they restart: both config.yaml routers load and POST /model/new for a third heuristic_v2 router returns 200

Relevant issues

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally
  • My PR passes all required CI/CD checks
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5

Screenshots / Proof of Fix

Rig: proxy from this worktree on 127.0.0.1:4590 with its own Postgres database, tiers served by real Claude models through the sandbox gateway (each chat completion below is billed, x-litellm-response-cost shown). The signed licenses for the After legs were produced with a throwaway RSA keypair whose public key temporarily replaced litellm/proxy/auth/public_key.pem in the rig only (the file is untouched in this PR); the payload was verified through the real signature path and the server log shows the parsed allowed_features for each leg

Shared setup

model_list:
  - model_name: haiku
    litellm_params: {model: openai/claude-haiku-4-5-20251001, api_base: https://gateway.litellm-sandbox.ai/v1, api_key: os.environ/GW_KEY}
  - model_name: sonnet
    litellm_params: {model: openai/claude-sonnet-5, api_base: https://gateway.litellm-sandbox.ai/v1, api_key: os.environ/GW_KEY}
  - model_name: v2-router-a
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config: {classifier_type: heuristic_v2, tiers: {SIMPLE: haiku, MEDIUM: haiku, COMPLEX: sonnet, REASONING: sonnet}}
  - model_name: v2-router-b        # present only in the "two routers" configs below
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config: {classifier_type: heuristic_v2, tiers: {SIMPLE: haiku, MEDIUM: haiku, COMPLEX: sonnet, REASONING: sonnet}}
general_settings: {master_key: sk-1234, store_model_in_db: true}
H=(-H "Authorization: Bearer sk-1234" -H "Content-Type: application/json")
V2='{"model_name":"v2-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic_v2","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
V1='{"model_name":"v1-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'

Before (a5639b8)

No license, config.yaml with two heuristic_v2 routers

  1. curl "${H[@]}" http://127.0.0.1:4590/model/info filtered to auto-routers
    v2-router-a heuristic_v2
    v2-router-b heuristic_v2
    
  2. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
    HTTP 200
    {"model_id": "a1bbc3d2-dd29-47c0-9322-4b431665a87c"}
    
  3. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"
    HTTP 200
    {"model_id": "1662809f-e14e-4250-92ba-7b808822fee6"}
    
  4. curl "${H[@]}" http://127.0.0.1:4590/v1/chat/completions -d '{"model":"v2-router-a","messages":[{"role":"user","content":"Say hi in three words"}]}'
    Hi there friend!
    x-litellm-model-name: openai/claude-haiku-4-5-20251001
    x-litellm-response-cost: 4.7000000000000004e-05
    

After (41f47eb)

No license, config.yaml with two heuristic_v2 routers

  1. Start the proxy with the two-router config
    ValueError: config.yaml model_list: At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.
    ERROR:    Application startup failed. Exiting.
    

No license, config.yaml with one heuristic_v2 router

  1. curl "${H[@]}" http://127.0.0.1:4590/model/info filtered to auto-routers
    v2-router-a heuristic_v2
    
  2. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
    HTTP 403
    {"message": "At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.", "type": "auth_error", "param": "None", "code": "403"}
    
  3. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"
    HTTP 200
    {"model_id": "7cb12ade-4ae9-4e62-a3ef-c7c3b4d3bb1a"}
    
  4. Same chat completion through v2-router-a (response headers)
    x-litellm-model-name: openai/claude-haiku-4-5-20251001
    x-litellm-response-cost: 5.2000000000000004e-05
    

License lapses: a DB heuristic_v2 row created under the feature, then a restart without it

  1. With the auto_router license and the one-router config: curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
    HTTP 200
    {"model_id": "85c1be3a-16f6-4499-a5d1-351c4fc90d10"}
    
  2. Restart the proxy with no license and the same config and DB; server log
    Error upserting deployment v2-router-db (id=85c1be3a-16f6-4499-a5d1-351c4fc90d10): At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router.. Dropping it and continuing with other deployments.
    
  3. curl "${H[@]}" http://127.0.0.1:4590/model/info filtered to auto-routers
    v2-router-a heuristic_v2
    

Plain enterprise license (signed, "allowed_features": []), config.yaml with one heuristic_v2 router

  1. Server log confirms the signed payload was accepted: 'allowed_features': []
  2. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
    HTTP 403
    {"message": "This proxy is limited to 1 auto-router(s) with classifier_type 'heuristic_v2' but would hold 2. ...", "type": "auth_error", "param": "None", "code": "403"}
    
  3. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"
    HTTP 200
    {"model_id": "fc52d898-05c7-4fdb-b83d-41017ad62182"}
    

License with the feature (signed, "allowed_features": ["auto_router"]), config.yaml with two heuristic_v2 routers

  1. Server log confirms the signed payload was accepted: 'allowed_features': ['auto_router']
  2. curl "${H[@]}" http://127.0.0.1:4590/model/info filtered to auto-routers
    v2-router-a heuristic_v2
    v2-router-b heuristic_v2
    
  3. curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
    HTTP 200
    {"model_id": "dc3b34c2-5287-462d-aaba-fa1152978200"}
    
  4. Same chat completion through v2-router-a (response headers)
    x-litellm-model-name: openai/claude-haiku-4-5-20251001
    x-litellm-response-cost: 5.2000000000000004e-05
    

Concurrent creates: six POST /model/new heuristic_v2 requests fired together, no license, config.yaml with no heuristic_v2 router

Before (ff81cc8, the pre-transaction head): the endpoint judged the live router, which only updates on reload, so every request saw the slot free

status codes: [200, 403, 500, 500, 500, 500]
rows in LiteLLM_ProxyModelTable: v2-race-0 v2-race-1 v2-race-2 v2-race-4 v2-race-5   (5 surplus rows)
live auto-routers via GET /model/info: ['v2-race-0']
server log: 19 x "Dropping it and continuing with other deployments"

After (41f47eb): the advisory lock serialises the six transactions and the count runs inside each

status codes: [200, 403, 403, 403, 403, 403]
rows in LiteLLM_ProxyModelTable: v2-race-0
second wave of 4 concurrent creates: [403, 403, 403, 403]
POST /model/new with classifier_type heuristic: HTTP 200

Concurrent team-scoped creates: six POST /model/new heuristic_v2 requests with model_info.team_id fired together, signed license with "allowed_features": []

The team path runs team_model_add on a second pool connection, so this is the burst that would stall if it ran under the lock

GET /health/license: enterprise []
status codes: [200, 403, 403, 403, 403, 403]   wall time 0.19s
rows in LiteLLM_ProxyModelTable: model_name_<team>_<uuid> | team_public_model_name=team-v2-0
GET /team/info models: ['all-proxy-models', 'team-v2-0']
second team wave of 4: [403, 403, 403, 403]   wall time 0.13s
non-team wave of 4 against the held slot: [403, 403, 403, 403]

Team-scoped PATCH: rename and switch to heuristic_v2 in one request while the slot is held, signed license with "allowed_features": []

create team-scoped heuristic router A (team-a):      200
create non-team heuristic_v2 router B (takes slot):  200
team models: ['all-proxy-models', 'team-a']

PATCH A {model_name: team-a-renamed, classifier_type: heuristic_v2}
  status 403  "At most 1 auto-router(s) with classifier_type 'heuristic_v2' ..."
  team models: ['all-proxy-models', 'team-a']          (unchanged)
  row A:       heuristic | team_public_model_name=team-a (unchanged)

PATCH A {model_name: team-a-renamed}
  status 200
  team models: ['all-proxy-models', 'team-a-renamed']
  row A:       heuristic | team_public_model_name=team-a-renamed

Type

🆕 New Feature

Caveats (if any)

Low

  • The slot transaction counts config.yaml routers from this pod's live router; pods running different config.yaml files would each add their own config routers to the count, which is the same assumption the startup validator already makes

  • CI: the documentation and code-quality jobs stay red until docs(proxy): document router_settings.heuristic_v2_router_limit litellm-docs#1152 (the max_heuristic_v2_routers row in the router_settings reference) merges; CI checks the docs repo out unpinned from main

  • A license verified through the license API (no signed payload) carries no feature list, so it keeps the one-router limit by design

  • A license that expires while the proxy is running keeps lifting the limit until the next license verification (startup or config load), exactly as max_users, max_teams and every premium_user gate behave today; the license module is not special-cased for this feature. An already-expired signed license no longer populates airgapped_license_data, so max_users / max_teams also stop binding for it (it is not premium either way)

  • The dashboard still offers Heuristic v2 in the classifier picker; over the limit the 403 message above surfaces as the save error. Disabling the option in the UI from /health/license is a follow-up

  • router_settings.heuristic_v2_router_limit in config.yaml is ignored (managed outside config), so the ceiling can only come from the license

  • The Router-side message is SDK-neutral; the "license lifts the limit" sentence is appended by the proxy on the 403 and the startup refusal, so the registration log line for a refused DB row carries the neutral message only

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

Medium Risk
Changes model registration, proxy model-management transactions, and license feature parsing; mis-counting or lock ordering could block legitimate writes or allow brief over-limit state across pods with mismatched config.

Overview
Caps heuristic_v2 complexity auto-routers at one unless a signed airgapped license includes allowed_features: auto_router; API-only license verification does not lift the cap.

Enforcement is layered so extra routers are not silently dropped under ignore_invalid_deployments: config.yaml fails startup when over limit; Router registration rejects newcomers (edits keep their slot); model create/update/PATCH return 403 before persisting. The proxy passes a live heuristic_v2_router_limit resolver into Router and treats router_settings.heuristic_v2_router_limit as managed outside config.

DB writes that would leave a row on heuristic_v2 under a limited license run in a transaction with pg_advisory_xact_lock, count other DB rows plus config.yaml routers, then publish config after commit. Team model list updates run after the row write so a refused slot does not mutate team ACLs.

License verification now clears airgapped_license_data on expiry or failed verify so stale features cannot keep lifting the limit.

Reviewed by Cursor Bugbot for commit 41f47eb. Bugbot is set up for automated code reviews on this repo. Configure here.

@devin-ai-integration devin-ai-integration Bot added the risk:high Sensitive, broad, or high-risk change label Sep 3, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

PR #39468 labeled risk:high (license/entitlement gating in litellm_license.py, core router.py, proxy_server.py, model management endpoints; 11 files, +633/-3). No enterprise label, so Linear routing was skipped.

@codspeed

codspeed Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_heuristic_v2_license (41f47eb) with litellm_internal_staging (f173a6b)

Open in CodSpeed

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR limits heuristic-v2 auto-routers to one unless a verified signed license grants the auto_router feature.

  • Enforces the limit during config loading, Router registration, and serialized model-management writes.
  • Clears cached signed-license feature data when verification rejects an expired or unreadable license.
  • Coordinates deployment-row writes, team bookkeeping, and cross-worker configuration publication.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
litellm/proxy/auth/litellm_license.py Adds the auto-router entitlement resolver and clears cached signed payloads on every rejected verification path.
litellm/proxy/management_endpoints/model_management_endpoints.py Serializes limited heuristic-v2 row writes with a PostgreSQL advisory lock and orders team bookkeeping after successful persistence.
litellm/proxy/proxy_server.py Validates config-file router counts and injects the dynamic license-backed limit into proxy Router instances.
litellm/router.py Enforces the injected registration ceiling while preserving previously serving deployment state after failed upserts.
litellm/router_utils/auto_router_model_naming.py Centralizes heuristic-v2 detection, counting, and an SDK-neutral limit message.
tests/test_litellm/proxy/auth/test_litellm_license.py Covers entitlement resolution and valid-to-rejected signed-license transitions.

Reviews (8): Last reviewed commit: "feat(router): limit heuristic_v2 auto-ro..." | Re-trigger Greptile

Comment thread litellm/proxy/auth/litellm_license.py Resolved
Comment thread litellm/proxy/auth/litellm_license.py Resolved
@veria-ai

veria-ai Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 3 · PR risk: 0/10

@codecov

codecov Bot commented Sep 3, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.16981% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/auth/litellm_license.py 91.66% 1 Missing ⚠️
...management_endpoints/model_management_endpoints.py 98.21% 1 Missing ⚠️
litellm/router.py 95.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tin-berri

Copy link
Copy Markdown
Contributor Author

CI note: documentation and code-quality are red only on the router_settings doc row, which is BerriAI/litellm-docs#1152; proxy-endpoints is red on an inherited crowdstrike_aidr cadence test that fails identically at the merge-base. Everything else is green on fb1f831437. @greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5.

The implementation is well-scoped and the behavior is convincingly covered: entitlement-aware limits are enforced at startup, write endpoints, and router registration; config and DB deployments are handled; expired signed licenses clear feature access; and the tested license/no-license flows match the intended behavior. The runtime evidence demonstrates both rejection and successful routing paths.

I’m not giving 5/5 because the PR still has known red CI checks, even though the documented failures appear unrelated or externally blocked, and the multi-pod race noted in the caveats remains an accepted limitation. Those do not indicate a correctness issue in the changed logic, but they prevent full confidence until the CI/docs conditions are resolved.

Comment thread litellm/proxy/auth/litellm_license.py Resolved
@tin-berri
tin-berri force-pushed the litellm_heuristic_v2_license branch from fb1f831 to 01a5532 Compare September 3, 2026 02:40
@tin-berri

Copy link
Copy Markdown
Contributor Author

Round pushed as 01a5532: the Router takes a heuristic_v2_router_limit resolver and re-checks license expiry on every write and registration, verify clears the cached payload on failure, the Router message is SDK-neutral with the license remedy appended proxy-side, and the new tests are typed. Rebased onto staging, so proxy-endpoints is green; documentation and code-quality are red only on the router_settings doc row (BerriAI/litellm-docs#1152). @greptileai can you reply here with a score and why that score?

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5.

The previously identified correctness issues are addressed: the Router now uses a live license-limit resolver, expiry is re-evaluated on each write and registration, failed license verification clears cached entitlement data, and SDK-facing errors remain license-neutral with the proxy adding the licensing remedy. The new typed tests cover license transitions, config/DB registration, endpoint writes, slot-preserving edits, and unlimited licensed behavior, and the reported proxy-endpoints failure is now green.

I’m not giving 5/5 because documentation and code-quality remain red while the external router_settings documentation row is pending in BerriAI/litellm-docs#1152. The documented multi-pod write race is also still an accepted limitation, although it does not indicate a defect in this implementation’s single-pod enforcement.

Comment thread litellm/router.py Resolved
@tin-berri
tin-berri force-pushed the litellm_heuristic_v2_license branch 3 times, most recently from a980f1a to ff81cc8 Compare September 3, 2026 05:27
@tin-berri

Copy link
Copy Markdown
Contributor Author

Round pushed as ff81cc8. Two changes. (1) Per-call license expiry is reverted: license_expired, the verifier reorder and the three expiry tests are gone, and heuristic_v2_router_limit() now reads the payload cached at verification exactly like max_users / max_teams and every premium_user gate, so this feature no longer diverges from the proxy-wide licensing pattern. A license lapsing mid-process is documented as the same accepted gap the rest of the proxy carries; the Router still resolves the limit through the bound method on each call so a re-verification binds without a restart. (2) Bugbot's upsert finding is fixed: upsert_deployment refuses a heuristic_v2 edit that would exceed a since-tightened ceiling before the live row is popped, with a test that fails without the guard. All four earlier threads have replies. @greptileai please re-score.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit ff81cc8. Configure here.

@tin-berri
tin-berri force-pushed the litellm_heuristic_v2_license branch from ff81cc8 to 24e2d24 Compare September 3, 2026 05:43
@tin-berri

Copy link
Copy Markdown
Contributor Author

Round pushed as 24e2d24: the heuristic_v2 slot is now claimed atomically. A heuristic_v2 write under a limited license runs in one transaction with pg_advisory_xact_lock taken before the DB-row count, so concurrent /model/new / /model/update / PATCH /model/{id}/update requests on any pod cannot both take the sole slot and no surplus row is persisted. Live-proven on a Postgres rig: six concurrent creates went from [200, 403, 500, 500, 500, 500] with five rows persisted to [200, 403, 403, 403, 403, 403] with one row; proof block added to the PR body and the cross-pod caveat is removed. Veria's thread has the details. @greptileai please re-score.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 24e2d24. Configure here.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit a6ede47. Configure here.

@tin-berri

Copy link
Copy Markdown
Contributor Author

@greptileai can you reply here with score and why

@greptile-apps

greptile-apps Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Confidence score: 4/5.

This is a strong, well-scoped implementation: the entitlement is derived only from a verified, non-expired signed license; enforcement covers config startup, router registration, and create/update APIs; and the Postgres advisory-lock transaction closes the concurrent-write gap while preserving team-model ordering and rollback behavior. The added unit, endpoint, startup, and concurrency-focused tests plus the end-to-end evidence cover the important customer flows.

I’m not giving 5/5 because this is a high-impact change across licensing, startup, router state, and transactional model management, with behavior that still depends on the documented multi-pod/config assumptions. The PR also notes documentation/code-quality CI remains red pending the external docs change, so final confidence should increase once those checks are green.

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Independent E2E run of a6ede47: proxy on 127.0.0.1:4590 with its own Postgres database (h2gate), tiers served by real Anthropic models (anthropic/claude-haiku-4-5, anthropic/claude-sonnet-4-6), signed test licenses made with a throwaway RSA keypair whose public key replaced litellm/proxy/auth/public_key.pem in the rig only. Every leg matched the PR description

# one.yaml (two.yaml adds an identical v2-router-b)
model_list:
  - model_name: haiku
    litellm_params: {model: anthropic/claude-haiku-4-5, api_key: os.environ/ANTHROPIC_API_KEY}
  - model_name: sonnet
    litellm_params: {model: anthropic/claude-sonnet-4-6, api_key: os.environ/ANTHROPIC_API_KEY}
  - model_name: v2-router-a
    litellm_params:
      model: auto_router/complexity_router
      complexity_router_config: {classifier_type: heuristic_v2, tiers: {SIMPLE: haiku, MEDIUM: haiku, COMPLEX: sonnet, REASONING: sonnet}}
general_settings: {master_key: sk-1234, store_model_in_db: true}
H=(-H "Authorization: Bearer sk-1234" -H "Content-Type: application/json")
V2='{"model_name":"v2-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic_v2","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
V1='{"model_name":"v1-router-db","litellm_params":{"model":"auto_router/complexity_router","complexity_router_config":{"classifier_type":"heuristic","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
P1: curl "${H[@]}" http://127.0.0.1:4590/model/info | jq '.data[] | select(.litellm_params.model=="auto_router/complexity_router") | [.model_name, .litellm_params.complexity_router_config.classifier_type]'
P2: curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V2"
P3: curl "${H[@]}" -X POST http://127.0.0.1:4590/model/new -d "$V1"
P4: curl -si "${H[@]}" http://127.0.0.1:4590/v1/chat/completions -d '{"model":"v2-router-a","messages":[{"role":"user","content":"Say hi in three words"}]}'
P5: curl "${H[@]}" http://127.0.0.1:4590/health/license
P6: curl "${H[@]}" -X PATCH http://127.0.0.1:4590/model/<P3 id>/update -d '{"litellm_params":{"complexity_router_config":{"classifier_type":"heuristic_v2","tiers":{"SIMPLE":"haiku","MEDIUM":"haiku","COMPLEX":"sonnet","REASONING":"sonnet"}}}}'
Leg License (allowed_features per P5) Config Startup P1 auto-routers P2 v2 create P3 v1 create P4 chat via v2-router-a P6 PATCH v1 -> v2
L1 none two.yaml refused
L2 none one.yaml ok v2-router-a 403 200 200, anthropic/claude-haiku-4-5 403
L3 real org license, ["*"] one.yaml ok v2-router-a 403 200 200, anthropic/claude-haiku-4-5 403
L3 real org license, ["*"] two.yaml refused
L4a signed, ["auto_router"] two.yaml ok v2-router-a, v2-router-b 200 200 200, anthropic/claude-haiku-4-5 200
L4b signed, [] one.yaml ok v2-router-a 403 200 200, anthropic/claude-haiku-4-5 403
L4c signed, ["*"] one.yaml ok v2-router-a 403 200 200 403
L4d signed, ["auto_router"], expired 2020-01-01 (P5 shows no license) one.yaml ok v2-router-a 403 200 200 403

Startup refusal (L1, and L3 with two.yaml)

ValueError: config.yaml model_list: At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.
ERROR:    Application startup failed. Exiting.

P2 403 body (same text on the P6 403)

{"error":{"message":"At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router. A LiteLLM license with the 'auto_router' feature lifts the limit.","type":"auth_error","param":"None","code":"403"}}

L5 license lapse: with the ["auto_router"] license and one.yaml, P2 returned 200 (v2-router-db id 6493d5d5). Restarted with no license and the same DB

LiteLLM Router:WARNING: router.py:9573 - Error upserting deployment v2-router-db (id=6493d5d5-a726-4ed6-966e-f3e60ff8e001): At most 1 auto-router(s) with classifier_type 'heuristic_v2' can be registered but this would make 2. Use classifier_type 'heuristic' for this router or remove an existing heuristic_v2 router.. Dropping it and continuing with other deployments.
P1: [["v2-router-a","heuristic_v2"]]

Restarted again with the ["auto_router"] license: P1: [["v2-router-a","heuristic_v2"],["v2-router-db","heuristic_v2"]]

L6 concurrency: no license, config with no heuristic_v2 router, six POST /model/new heuristic_v2 requests (v2-race-0..5) fired together

200 v2-race-0
403 v2-race-1
403 v2-race-2
403 v2-race-3
403 v2-race-4
403 v2-race-5
SELECT model_name FROM "LiteLLM_ProxyModelTable";  ->  v2-race-0

Note on L3/L4c: allowed_features: ["*"] does not lift the limit since the check is a literal "auto_router" membership test, confirmed as intended with the author

…_router license feature

Without the auto_router feature in the signed enterprise license a proxy may hold
one complexity router with classifier_type heuristic_v2 across config.yaml and the
DB; with it the limit is lifted. The ceiling is derived once from LicenseCheck and
handed to the Router, which refuses the extra router at registration. config.yaml
over the limit refuses to start, and /model/new, /model/update and
PATCH /model/{id}/update refuse the write with a 403 before touching the DB.
Expiry follows the existing max_users/max_teams pattern: judged when the
license is verified, not on every call, and a verify that rejects the license
(expired or unreadable) leaves no signed payload behind. The rollback after a
failed upsert re-admits state that was already serving, so it is exempt from the
ceiling: an edit that fails, including one refused by a ceiling that has since
tightened, leaves the router serving its previous configuration.
A write that leaves a row on heuristic_v2 under a limited license runs in one
transaction that takes a Postgres advisory lock before counting the DB rows plus
this proxy's config.yaml routers, so concurrent writes on any pod cannot both
claim the sole slot and no surplus row is ever persisted.
Only the row insert runs under that lock: the team model bookkeeping, which
needs a second pool connection, runs after the transaction has committed.
PATCH /model/{id}/update follows the same order as create: the row is written
through the slot first and the team's model list is updated only afterwards, so
a refused write leaves the team as it was.
The slot transaction bypasses the repository's publish-on-write, so it
publishes the config change once after commit, as delete_team_models does.
@tin-berri
tin-berri force-pushed the litellm_heuristic_v2_license branch from a6ede47 to 41f47eb Compare September 3, 2026 19:56
@tin-berri

Copy link
Copy Markdown
Contributor Author

Rebased onto current litellm_internal_staging as 41f47eb (was conflicting after #39436 landed the access-group rename sync in the same two write blocks). Resolution only, no behavior change: in patch_model the rename sync now reads the written name captured by the row writer, and in update_model it runs after the slot block, outside the lock. All four delta gates pass against the new base and the rig runs (concurrent creates, team burst, team patch path) are unchanged. @greptileai please re-score.

@tin-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 41f47eb. Configure here.

@tin-berri
tin-berri merged commit df73c62 into litellm_internal_staging Sep 3, 2026
86 of 88 checks passed
@tin-berri
tin-berri deleted the litellm_heuristic_v2_license branch September 3, 2026 20:40
tin-berri added a commit that referenced this pull request Sep 4, 2026
… the auto_router license feature

Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose
records own their in-process predicate, SQL spelling and refusal wording. The
existing heuristic_v2 capability keeps its own one-router ceiling. A single
customization capability combines operator-defined tier_definitions and an
operator-written classifier system_prompt, so an unlicensed proxy can have at
most one router that customizes either form. The prompt half only applies to
classifier types that call an LLM. The shipped default prompt, classification
rubric presets, tier_labels renames and tier model choices remain ungated. The
signed auto_router license feature makes both ceilings unlimited.
koladefaj pushed a commit to koladefaj/litellm that referenced this pull request Sep 4, 2026
test_no_linear_scans_in_router: BerriAI#39468 added config_deployments() and
heuristic_v2_router_limit_violation(), which both scan the whole model_list
from admin-only paths (model add/upsert), so add them to the allowlist. The
allowlist becomes a mapping so each exemption carries its reason as data.

test_missing_model_parameter_curl: a request with no model is rejected by the
proxy when nothing can serve it and by the router when a wildcard or default
deployment exists, and by the upstream provider when a wildcard forwards it,
so the message text is not a stable contract. Assert the contract that holds
in every case: HTTP 400 with a non-empty error message.

test_model_group_info_e2e: /model_group/info resolves wildcards, so it can
never return "anthropic/*" verbatim. cc3f9cd rewrote the assertion to
expect the raw pattern after claude-3-5-haiku-20241022 left the price map,
which made it unsatisfiable. Assert the expansion instead.

test_should_derive_ocr_mapping_status_from_live_tests: the audit needs a
native bridge built with the trace-parity feature, which CI never builds, so
skip with the harness's own diagnostic instead of erroring. Extract that
check out of ensure_trace_bridge as trace_bridge_error so a pytest run
reports the state without kicking off a maturin rebuild.
tin-berri added a commit that referenced this pull request Sep 5, 2026
… the auto_router license feature

Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose
records own their in-process predicate, SQL spelling and refusal wording. The
existing heuristic_v2 capability keeps its own one-router ceiling. A single
customization capability combines operator-defined tier definitions with every
operator-written part of the classifier prompt. The prompt half only applies to
classifier types that call an LLM. The shipped default prompt, classification
rubric presets, tier-label renames and tier model choices remain ungated.

Scope every enforcement point to actual complexity routers. A model-less PATCH
or legacy update now decrypts the stored model before accepting strategy-router
settings, so a regular model cannot acquire a router config or spend a license
slot. Under the existing advisory lock, the cross-pod candidate query returns
only model scalars and the count decrypts and classifies them in process; old
non-router rows carrying a capability-shaped config no longer block a real
complexity router. The signed auto_router license feature makes both ceilings
unlimited.
tin-berri added a commit that referenced this pull request Sep 5, 2026
… the auto_router license feature

Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose
records own their in-process predicate, SQL spelling and refusal wording. The
existing heuristic_v2 capability keeps its own one-router ceiling. A single
customization capability combines operator-defined tier definitions with every
operator-written part of the classifier prompt. The prompt half only applies to
classifier types that call an LLM. The shipped default prompt, classification
rubric presets, tier-label renames and tier model choices remain ungated.

Scope every enforcement point to actual complexity routers. A model-less PATCH
or legacy update now decrypts the stored model before accepting strategy-router
settings, so a regular model cannot acquire a router config or spend a license
slot. Under the existing advisory lock, the cross-pod candidate query returns
only model scalars and the count decrypts and classifies them in process; old
non-router rows carrying a capability-shaped config no longer block a real
complexity router. The signed auto_router license feature makes both ceilings
unlimited.
tin-berri added a commit that referenced this pull request Sep 5, 2026
… the auto_router license feature (#39674)

Generalizes the heuristic_v2 ceiling from #39468 into a capability table whose
records own their in-process predicate, SQL spelling and refusal wording. The
existing heuristic_v2 capability keeps its own one-router ceiling. A single
customization capability combines operator-defined tier definitions with every
operator-written part of the classifier prompt. The prompt half only applies to
classifier types that call an LLM. The shipped default prompt, classification
rubric presets, tier-label renames and tier model choices remain ungated.

Scope every enforcement point to actual complexity routers. A model-less PATCH
or legacy update now decrypts the stored model before accepting strategy-router
settings, so a regular model cannot acquire a router config or spend a license
slot. Under the existing advisory lock, the cross-pod candidate query returns
only model scalars and the count decrypts and classifies them in process; old
non-router rows carrying a capability-shaped config no longer block a real
complexity router. The signed auto_router license feature makes both ceilings
unlimited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants