Skip to content

feat(proxy): per-model team member budgets with router fallback - #43887

Merged
yassin-berriai merged 1 commit into
mainfrom
litellm_team_member_model_budgets
Oct 10, 2026
Merged

yassin-berriai merged 1 commit into
mainfrom
litellm_team_member_model_budgets

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Teams can't give each member a separate budget per model
  • A member who burns their expensive-model allowance can't be routed to a cheaper model
  • One member can't get per-model caps that differ from the team default

How it solves it:

  • New team_member_model_max_budget on /team/new and /team/update, stored on the team's default member budget
  • Each member is metered per model per team; over-budget requests follow router_settings.fallbacks, rechecking every budget and access rule on the fallback model
  • Admin UI gets a "Default Per-Model Budget" editor under Team Member Settings
  • /team/member_update accepts model_max_budget; Members, Edit Member gets a "Per-Model Budgets" editor that overrides the team default for that member only

User Flow

Before: an admin sets per-model member caps on a team, but members keep hitting the expensive model with no limit

  1. Admin sends POST /team/new with team_member_model_max_budget: {"claude-sonnet-4-6": {"max_budget": 20, "budget_duration": "30d"}}, gets 200
  2. POST /budget/info on the team's member budget shows "model_max_budget": null, the field was dropped
  3. A member sends POST /v1/chat/completions with claude-sonnet-4-6 past the cap and still gets 200 from claude-sonnet-4-6
  4. http://localhost:4000/ui/teams/?team= Settings tab shows no per-model member budget
  5. Members tab, Edit Member on one member: no per-model field at all, only the overall Team Member Budget

Before: Team Member Settings has no per-model budget

Before: Edit Member has no per-model budget field

After: the member is capped per model and automatically moved to the cheaper fallback, other members are untouched

  1. Admin sends the same POST /team/new (or sets it in the UI under Settings, Edit Settings, Team Member Settings, Default Per-Model Budget)
  2. A member under the Sonnet cap gets 200 with x-litellm-model-group: claude-sonnet-4-6
  3. Once over the Sonnet cap, the same request returns 200 from claude-haiku-4-5 via the router fallback
  4. Once over the Haiku cap too, it returns 422 LiteLLM Team Member: user=<id>, team=<id>, exceeded budget for model=claude-sonnet-4-6
  5. Another member of the same team, and the same user in another team, still get claude-sonnet-4-6
  6. Members tab, Edit Member on one member: Per-Model Budgets is prefilled with the team default (gpt-4o $10 Monthly); admin sets it to $2.5 Weekly, adds claude-sonnet-4-6 $4 Monthly, Save Changes
  7. Reopening that member shows the override; Edit Member on another member and the team Settings tab still show the $10 default

After: Edit Member prefilled with the team default

After: the member's own per-model caps persisted after reopening

After: another member still inherits the team default

Linear ticket

Resolves LIT-2769

Root cause

The team default member budget row already has a model_max_budget JSON column, but NewTeamRequest/UpdateTeamRequest never accepted the field, auth never loaded it onto the token, and the model budget limiter had no team-member entity, so nothing was persisted, enforced or metered

How it runs

flowchart LR
  A[request model=M] --> B[existing key/user/team model budget checks]
  B --> C{member spend on M for user:team over cap?}
  C -- no --> D[serve M]
  C -- yes --> E[walk router fallbacks for M]
  E --> F{candidate passes key, user, end-user, team, member budgets and key, team, project, member model access?}
  F -- yes --> G[rewrite body model, serve candidate]
  F -- none --> H[raise original 422 budget error]
Loading

Spend is charged on success to the same team_member_model_spend:<user_id>:<team_id>:<model> key used for the check. skip_budget_checks still loads the member budget so post-call metering sees it. A membership row with its own model_max_budget takes precedence; otherwise caps come from the team default row through the same cached team_member_default_budget:{budget_id} lookup the existing member budget check uses, which team update evicts. Fallbacks the router picks later (provider errors) also check the member's per-model cap through RouterFallbackBudgetCheck, so an exhausted target is skipped there too

Files changed

File Change
litellm/proxy/_types.py team_member_model_max_budget on NewTeamRequest, UpdateTeamRequest and (excluded from dumps) UserAPIKeyAuth
litellm/proxy/management_endpoints/team_endpoints.py Validate, premium-gate, create/upsert/clear the field on the default member budget, evict its cache; /team/member_update validates and returns model_max_budget
litellm/proxy/management_endpoints/common_utils.py model_max_budget in the member budget merge-patch, JSON-serialised for Prisma, clone-on-write off a shared budget row
litellm/proxy/auth/user_api_key_auth.py Load default member budget, enforce per model, walk router fallbacks with full budget and access rechecks, rewrite request model; a member row with {} falls back to the team default, and a zero-cost backup skips the spend caps
litellm/proxy/auth/fallback_budget.py Router-time fallback budget check also skips targets over the member's per-model cap
litellm/proxy/auth/auth_checks.py raise_on_lookup_error on the default member budget reader so auth can fail closed
litellm/proxy/proxy_server.py Build the router's fallback budget check with the model budget limiter
litellm/router_utils/common_utils.py resolve_served_model returns the model request preparation serves after global, key and router aliases, shared by both backup budget checks
litellm/proxy/common_request_processing.py Proxy rate-limit backups skip a model whose member per-model cap is spent, after resolving global, key and router aliases, and free backups stay allowed
litellm/proxy/management_endpoints/ui_sso.py SSO default team params build NewTeamRequest with model_validate, same validation, typed for the new field
litellm/proxy/hooks/model_max_budget_limiter.py TEAM_MEMBER entity with user:team identity for checks and success-time spend
litellm/proxy/litellm_pre_call_utils.py Pass user_api_key_team_member_model_max_budget into request metadata
litellm/proxy/pass_through_endpoints/pass_through_endpoints.py Same metadata for pass-through requests
litellm/llms/anthropic/pass_through/context_management/editors/compact.py Carry the field and check the member budget for the compact summary call
ui/litellm-dashboard/src/components/Teams.tsx Default Per-Model Budget editor on team create
ui/litellm-dashboard/src/components/team/TeamInfo.tsx Editor in team settings, read-only display, changed-only update payload, Per-Model Budgets field on Edit Member
ui/litellm-dashboard/src/components/team/EditMembership.tsx, memberFormValues.ts New model-max-budget member field type rendering ModelMaxBudgetEditor
ui/litellm-dashboard/src/components/team/TeamMemberTab.tsx Edit Member seeds from the member's own caps, else the team default
ui/litellm-dashboard/src/components/networking.tsx teamMemberUpdateCall sends model_max_budget only when it changed
ui/litellm-dashboard/src/components/key_team_helpers/ModelMaxBudgetEditor.tsx Optional label prop
ui/litellm-dashboard/src/lib/http/schema.d.ts Regenerated API types

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 before requesting a maintainer review

Screenshots / Proof of Fix

Rebased head (c36a399, main as of 2026-10-10, head and no-fallback columns re-run on the final head 3df96dd with identical results)

Three proxies on local Postgres with real Anthropic calls and byte-identical request files: head with router_settings.fallbacks: [{"claude-sonnet-4-6": ["claude-haiku-4-5"]}] on :4000, head without fallbacks on :4001, base origin/main with fallbacks on :4002. Team default caps Sonnet 0.000001 per 1d and Haiku 5 per 1d

Cell base, fallbacks head, fallbacks head, no fallbacks
alice Sonnet chat 1 200 sonnet 200 sonnet 200 sonnet
alice Sonnet chat 2, key 1 200 sonnet 200 haiku 422 member budget
alice Sonnet chat 3, key 2 200 sonnet 200 haiku 422 member budget
alice Sonnet stream 200 sonnet, 2 chunks 200 haiku, 2 chunks 422, 0 chunks
alice /v1/messages 200 sonnet 200 haiku 422 member budget
alice /v1/models (budget exempt route) 200 200 200
bob Sonnet and Haiku both exhausted, chat 200 sonnet 422 member budget 422 member budget
bob same, stream 200 sonnet 422, 0 chunks 422, 0 chunks
bob /v1/models after exhaustion 200 200 200
alice override Sonnet $5 via /team/member_update, then Sonnet chat 200 sonnet 200 sonnet 200 sonnet

Admin UI stills below were captured on c36a399, and git diff c36a399320 3df96dd997 -- ui/ is empty, so the dashboard served at the final head is the same

  1. http://localhost:4000/ui/?page=teams, open the team, Settings. Team Member Settings shows the default per-model budgets

    Team default per-model budgets on the rebased head

  2. Members tab, three members

    Members tab

  3. Edit alice, Per-Model Budgets shows her Sonnet override

    alice override

  4. Edit bob, click Add, leave the row unfinished, Cancel, then reopen. The unfinished row is gone and the saved rows remain

    Unfinished row

    Reopened, unfinished row dropped

Earlier rounds

All cells below are on 7e5058b (base 6d4fa56ac4); the core fallback cells (alice Sonnet to Haiku fallback on both keys, bob 422 when exhausted, clearing restores Sonnet) and the /v1/responses cells were re-run live on head 1588f11763 after the review fixes, and the clearing and tpm-only inheritance cells re-run on head 2ee9fc44ad, real Anthropic calls, local Postgres, byte-identical request bodies and config across arms. Base arm: worktree of the base commit, proxy log LITELLM_FROM /home/ubuntu/work-2769/base/litellm/__init__.py. Head arm: LITELLM_FROM /home/ubuntu/repos/litellm/litellm/__init__.py. Fallback config router_settings.fallbacks: [{"claude-sonnet-4-6": ["claude-haiku-4-5"]}] on one proxy, the same config without router_settings on another. Team A has default member caps Sonnet 0.000001 per 1d and Haiku 5 per 1d, members alice (two keys) and bob

Before (base 6d4fa56)

Cell Observable
POST /team/new with team_member_model_max_budget 200, field absent from response and from /team/info
alice Sonnet chat x3, key 1 and key 2 200, all served by claude-sonnet-4-6, no cap
alice Sonnet stream, /v1/messages 200, claude-sonnet-4-6
POST /team/member_update model_max_budget 200, nothing persisted
No-fallback proxy, same calls 200, claude-sonnet-4-6, no budget error

After (7e5058b, core and /v1/responses cells re-run on 1588f11)

Cell Proxy Observable
/team/info member default fallbacks {"claude-haiku-4-5": {"max_budget": 5, "budget_duration": "1d"}, "claude-sonnet-4-6": {"max_budget": 0.000001, "budget_duration": "1d"}}
alice Sonnet chat 1 fallbacks 200, claude-sonnet-4-6
alice Sonnet chat 2+ fallbacks 200, claude-haiku-4-5 (budget fallback)
alice Sonnet chat via her second key fallbacks 200, claude-haiku-4-5, cap is per member not per key
alice Sonnet stream fallbacks 200, claude-haiku-4-5, chunks streamed
alice /v1/messages fallbacks 200, claude-haiku-4-5
/v1/responses 1 then 2, fresh member, identical body (sha256 0ef8a9e8) fallbacks 200 claude-sonnet-4-6, then 200 claude-haiku-4-5
/v1/responses 1 then 2, same setup no fallbacks 200 claude-sonnet-4-6, then 422 budget error
bob /v1/responses, Sonnet and Haiku exhausted fallbacks 422 budget error
member override set, team has no default member budget fallbacks override in /team/info, 200 then 422 on the no-fallback model
tpm-only /team/member_update, then team default changed fallbacks member keeps inheriting the new default
bob, unused budget fallbacks 200, claude-sonnet-4-6
alice override Sonnet $5 via /team/member_update, then Sonnet chat fallbacks override persisted, 200 claude-sonnet-4-6
bob after Sonnet exhaustion fallbacks 200, claude-haiku-4-5
bob after Sonnet and Haiku exhausted, chat and stream fallbacks 422 budget error, 0 chunks
Thinking-model Anthropic Messages stream fallbacks 200, first byte about 1.26s, 153 thinking_delta events
Sonnet exhausted no fallbacks 422 budget error, no reroute
POST /team/update team_member_model_max_budget: {} then Sonnet chat fallbacks stored {}, 200 claude-sonnet-4-6

Admin UI (dashboard dev server from the head checkout, proxied to the head proxy)

  1. Teams, Team A, Settings: Team Member Settings shows Default Per-Model Budget (claude-haiku-4-5): $5.0000 per 30d and (claude-sonnet-4-6): $20.0000 per 30d

    Team default per-model member budgets

  2. Members, Edit Member on alice: Per-Model Budgets is prefilled from the team default (Haiku $5, Sonnet $20, Monthly)

    Edit Member prefilled from the team default

  3. Sonnet changed to $40, Save Changes: toast Team member updated successfully, alice's budget column switches to Custom with a Use team default action

    Override filled in

    Saved, alice shows Custom

  4. Reopen alice: Sonnet $40 persisted. /team/info: alice {"claude-haiku-4-5": {"max_budget": 5.0, "budget_duration": "30d"}, "claude-sonnet-4-6": {"max_budget": 40.0, "budget_duration": "30d"}}, bob still on the team default row with Sonnet 20.0

    alice reopened, override persisted

  5. Edit Member on bob: still the team default Sonnet $20

    bob still on the team default

  6. On head 1588f11, Edit Member on alice (stored per-model caps) and change only Team Member RPM Limit to 100, Save Changes: Team member updated successfully and the Rate Limits column shows 100 RPM, so a stored cap no longer blocks an unrelated save

    RPM-only save on a member with stored caps

  7. On head d67ad28, Edit Member on bob, Add Model Budget leaves an empty row, Cancel, then reopen bob: only the stored Haiku $5 and Sonnet $20 rows are shown, the unfinished row is gone

    Unfinished row added

    Reopened, unfinished row cleared

Taxonomy audit

Re-run on the rebased diff at c36a399 and the fixes at c1955bc, 6e5ee41, babe4d4, b4d51d8, b7d8a2e and 3df96dd, earlier on 7e5058b, audit findings fixed in 9490d48, bot review findings fixed in 1588f11, 65606fe, 5afbe0d, 699f817, eaa5039, b99c7e3, f6eab8b, 2459b04 and 2ee9fc4

  • A1, /budget/update: it can edit the team default budget row, so it now evicts team_member_default_budget:{budget_id} after the write (test pre-populates the key, calls the endpoint, asserts eviction; fails with the eviction removed)

  • E8, member spend counter identity: team_member_budget_entity_id is now {len(user_id)}:{user_id}:{team_id} so ("a:b", "c") and ("a", "b:c") no longer share a counter (test fails with the old format)

  • A2/A3, multi-worker and fetch-vs-evict race: the default budget cache entry is evicted on the writing worker and in Redis; other workers and an in-flight fetch can serve the previous caps until the entry's TTL expires, the same bound the existing team and key object caches have

  • D2/Z7, fallback candidate checks (review round on 7e5058b): each candidate now also passes the end-user model allowlist (can_customer_access_model), the block_requests_for_models_without_pricing policy (_unpriced_models_in_request), and the model access group budget check, and matched_model_access_groups is recomputed for the accepted candidate so reservations and spend charge its groups

  • Fallback targets in dict form ({"model": "backup"}) are read by model; a dict carrying other request overrides is skipped for the budget reroute instead of raising

  • W1, fallback body rewrite: uses the existing rewrite_request_model helper, so only the client-sent body plus model is rewritten and auth-enriched fields are not written back into the request body cache

  • BB, inheritance: a member edit that only changes tpm, rpm or the overall budget no longer copies the team default model_max_budget into the member's private row, so later team default changes still reach that member; a member override is honoured even when the team has no default member budget

  • /budget/update and team update evict the cache entry and log, rather than fail, when the cache delete raises after the database write succeeded

  • Dashboard: Edit Member normalizes stored max_budget/budget_duration caps into the editor shape, so saving an unrelated change (role, rpm) no longer fails form validation

  • Agent keys (review round on 1588f11): the agent refusal applies only to the new team member fallback; the existing key budget_fallbacks path behaves as on main

  • Clone-on-write skips copying model_max_budget only when the source row is the team default member budget; a nondefault row shared by several memberships keeps its caps on the copy

  • Fallback team access (review round on 5afbe0d): the member fallback candidate check now uses can_team_access_model plus key_access_group_grants_model, the same check a direct request goes through, so a backup granted by a team or key access group is not skipped

  • An empty model_max_budget patch on a member who points at the team default is a no-op instead of forking a private row, so that member keeps following later team default changes (live cell D: same budget_id as the default, and a raised default Sonnet cap reaches the member)

  • Fallback aliases (review round on 699f817): each fallback candidate is resolved through the key or team router_settings.model_group_alias map before any budget, access or pricing check and before the request is rewritten, so an alias cannot route to a model whose member cap is spent; a settings lookup failure means no fallback

  • Candidate errors: an unexpected error while checking one candidate (cache or DB failure, HTTPException) skips that candidate with a warning log instead of failing the request; when no candidate passes, the original member budget error is returned, so the walk stays fail closed

  • Review round on eaa5039: auth-time member fallback is skipped on multipart upload requests (the original budget error is returned rather than rewriting an upload body), key or team router_settings.fallbacks take precedence over the global list when choosing candidates (matching how the request is routed), and the router-time fallback budget check resolves model_group_alias targets with routable_model_group before checking member caps. Live: team router_settings fallback served Haiku after the Sonnet cap was spent on a proxy with no global fallbacks

  • Review round on b99c7e3: member caps on a fallback are checked under every name the call can be charged under, the candidate as written, its key or team alias target and the router's routable_model_group of that target, at auth time; the router-time check covers both the raw target and its routable group, so a cap stored on either the alias or the real model binds

  • Review round on f6eab8b: model_max_budget: null on a member who follows the team default is a no-op like {} (live cell D prime), and auth-time member fallback is skipped for requests that reference a provider-scoped resource (input_file_id, file_id, batch_id, training_file, fine_tuning_job_id, the same keys the router uses), so a file-backed request stays on the model group that owns the file. Two findings were answered in thread rather than changed: the router-time zero-cost bypass matches the auth-time skip_budget_checks path, and alias spend accounting on model_group is the existing primary-path behavior

  • Review round on 2459b04 (Greptile 4/5, Bugbot no new issues): the multipart and provider-scoped guard tests now use a real Router and cache instead of patching our own helpers, with the same assertions

  • Review round on 2ee9fc4 (Greptile 4/5, Bugbot 1, Devin Review 2): the member per-model budget check is skipped on routes where route_skips_budget_checks is true, like the other budget checks (test fails with the condition removed); team-default member caps are loaded for plain LiteLLM_TeamTable objects as well as cached ones (direct loader test fails with the old narrowing); the Edit Member model budget editor remounts per open and per member, so an unfinished row does not survive Cancel (integration test fails without the key, live step 7 below); the full Teams form interaction moved from the unit file to Teams.integration.test.tsx and the compact-summary and loader tests use seeded state instead of patching our own helpers, with the same assertions

  • Review round on d67ad28 (Greptile 4/5, Bugbot no new issues): a membership or default-budget lookup error no longer fails a budget-exempt route (/v1/models, management routes); the loader gets skip_budget_checks or route_skips_budget_checks(route=route), so a paid model route still fails closed on the same error. Covered by test_centralized_common_checks_skips_default_member_budget_lookup_errors_on_exempt_routes (exempt leg fails with the route term removed, paid leg pins the raise). The success path is unchanged, so the live cells above still apply; the lookup-failure path is proved by the test only, not live

  • Review round on 67980af (Greptile 4/5, Bugbot no new issues): the team default and Edit Member per-model budget pickers now offer models granted through the team's access groups, and every proxy model when the team's model list is empty or unrestricted, matching what the server enforces (two TeamInfo integration cases, each fails with its condition removed); the existing rate-limit pickers are unchanged. The member budget loader, vector store and fallback tests now seed the real membership and default budget caches and use a real Router, with Prisma read doubles only for misses and DB errors, instead of patching get_team_membership, get_team_member_default_budget and the access helpers; all assertions kept

  • Review round on 49d6c57 (Greptile 4/5 on the remaining test-double finding, Bugbot no new issues): the PR-added fallback, fallback-budget and compact summary tests now run the real PROXY_VirtualKeyModelMaxBudgetLimiter with spend seeded under model_budget_spend_cache_key, observing budget reads at the Redis edge, and the compact member-budget denial test uses a Router mock_response instead of patching _call_summary_model; tests that exist on main are unchanged

  • Review round on 59ce548 (Greptile 4/5 on the same test-double finding): the PR-added default budget lookup, shared default clone and team budget persistence tests now inject failures at the Prisma find_unique edge, seed the real membership and default budget cache entries, and run the real new_budget / update_budget helpers, asserting on the persisted Prisma budget row (serialised model_max_budget, budget_duration, budget_id) instead of patched helper arguments

  • Review round on e3b55b7 (Greptile 4/5, then confirmed in thread r4234700671 that no own-helper test double remains): the team member budget upsert test enables premium_user so the real update_budget path runs; Greptile scored 5/5 on 62c4e18, squashed with no tree change into the single commit ff8be00. Bugbot was triggered on e3b55b7 and replied that it is paused on the on-demand spend limit, so the last Bugbot verdict is no new issues on 49d6c57

  • Review round on c36a399 (Greptile P1, rate-limit backups ignore member caps): _pre_call_with_fallbacks checks each proxy rate-limit backup against the member's per-model cap before trying it, so a spent backup is skipped and the original 429 is returned when none is eligible

  • Review round on c1955bc (Greptile P1 throttled keys lose backups, P2 tests skip real backup preparation): the backup gate no longer calls the router's fallback_budget_check, which also rejects key and user budgets without honoring budget_throttle_pct. It now runs only _team_member_within_fallback_model_budget, the member cap on the backup and its routable group, and fails closed if the spend lookup errors. Key and user budgets stay decided once at auth. Three tests in TestPreCallWithFallbacksOnLocalRateLimit drive the real common_processing_pre_call_logic through the real v3 limiter with a real PROXY_VirtualKeyModelMaxBudgetLimiter seeded in DualCache, covering a spent backup (429, backup never reaches the limiter), a backup under its cap (served), and an over-budget key with an enforced RouterFallbackBudgetCheck on the router (backup still served). Disabling the member gate fails the first, and restoring the router predicate fails the first and third. This path is proved by tests only, since a key model_rpm_limit did not produce a proxy 429 on the live rig, so the live cells above do not cover it

  • Review round on 6e5ee41 (Greptile P1, free backups get blocked): _team_member_within_fallback_model_budget returns early when is_model_cost_zero holds for the backup, matching the zero-cost bypass at auth and in RouterFallbackBudgetCheck. test_rate_limit_fallback_uses_free_backup_with_spent_member_model_budget seeds a spent member cap on a zero-cost backup and asserts it is served, and it fails with the bypass removed

  • Review round on babe4d4 (CodeQL Log Injection): the backup gate's lookup-failure warning passes the model name and exception through sanitize_for_log, the existing CR/LF stripper in litellm_pre_call_utils.py

  • Review round on b4d51d8 (Greptile P1s, aliased backups skip member caps and free budget backups get rejected): the proxy rate-limit backup gate now resolves the backup through litellm.model_alias_map, the key's aliases and the key/team router_settings.model_group_alias before the member-cap check and applies the zero-cost bypass to the resolved model, and the auth-time fallback walk skips spend caps for zero-cost backups. Regression tests test_rate_limit_fallback_skips_backup_aliased_to_model_over_member_budget and test_zero_cost_fallback_skips_spent_member_model_budget fail when the alias resolution or the zero-cost bypass is removed

  • Review round on 8382348 (Greptile P1, aliased backups bypass member caps in the auth-time walk): new resolve_served_model in litellm/router_utils/common_utils.py applies litellm.model_alias_map, then key aliases, then model_group_alias, the same order as request preparation. Both backup walks use it for the price and member-cap checks, while access checks and the body rewrite keep the router-resolved name the primary request is authorized on. test_fallback_aliased_to_spent_member_model_budget_is_skipped (key alias, global alias, free backup aliased to a paid model) and the helper order test fail when the served model is dropped, the key step is skipped or the order is swapped

  • User-defined pass-through: not changed. The member cap is stamped by litellm_pre_call_utils.py only on the built-in pass-through path; the user-defined path builds metadata in init_kwargs_for_pass_through_endpoint, which filters client user_api_key_* metadata and adds the member field only on its non-user-defined branch

  • A1/A2: team update evicts team_member_default_budget:{budget_id} locally after write and clear

  • D2/Z7, post-rewrite checks: fallback candidate goes through key, team, project and membership model access plus every model budget before the rewrite

  • D2/Z7, agent keys: a key bound to an agent never reroutes to a fallback, it gets the original budget error, so agent model grants and access-group ceilings cannot be bypassed by the reroute

  • A1/A2, critical-path reads: caps are read through the evicted default-budget cache, not the membership's joined row, so a team update is not masked by the membership cache; overall-only overrides still inherit default caps

  • D4/Z2: a failed default budget or membership read fails closed unless budget checks are skipped for the request; a missing budget row still means no cap

  • F3 (router fallbacks): fallbacks chosen by the router after auth check the member per-model cap too

  • E5/X1: 0 cap is enforced (first request rejected in tests), explicit null clears to {}, missing field leaves the budget untouched

  • F3/O4: chat, streaming, /v1/messages, built-in pass-through and Anthropic compact summary all carry and check the field. User-defined pass-through routes keep main's existing behavior of not carrying managed model-budget fields, since their model is an upstream name. /v1/responses live-tested (see After table)

  • W1: the fallback rewrite updates the proxy's own parsed request body (that is the body sent downstream), no router, team or budget config dict is mutated

  • AA (metering): charged on success to the same user:team key that is checked

  • H1-H6, H8-H10: pass (no docs, no new comments, no em dashes in UI copy, existing model_max_budget Json? column, no CI changes). New suppressions each carry the gate rule and a reason (# noqa: BLE001 on the two fail-closed broad catches, # rebind-ok on the fallback body rewrite, # pyright: ignore[reportPrivateUsage] on the Starlette body cache, # mutable-ok on the model-access list contract). Optional[dict] appears only in the team endpoint docstring, matching the neighbouring fields

  • H7: prebuilt _experimental/out not touched, it is regenerated by the scheduled "update Next.js build artifacts" commit on main like other dashboard PRs

  • T: mutation checks (run on 03f3981; the tests they cover are unchanged since): dropping the pass-through metadata assignment fails test_passthrough_carries_the_per_model_budgets; making the member budget check always pass fails test_team_member_budget_is_charged_and_enforced_after_success and test_zero_team_member_model_budget_rejects_first_request. git diff origin/main...HEAD -- tests/ | grep '^-.*assert' lists six lines: the four whole-row stored_budget_row(mock_tx) == {...} asserts in the budget row tests are kept with the same values plus "model_max_budget": "{}", because the shared budget row writer now always serialises that column, and assert result == 42.5 and assert result is None only moved with their global spend tests and are present unchanged. Tests that exist on main keep every assertion 710321a: dropping the nonempty check on the member override fails test_member_model_budget_load_falls_back_when_override_has_no_model_caps[empty]; dropping the JSON serialisation fails the {} clear test in test_team_endpoints.py

Type

🆕 New Feature

Caveats (if any)

Medium

  • Loading the caps reads the cached team default budget row; for members whose override has only an overall max_budget, that is one extra cached read per team per cache lifetime
  • Member default budget cache is per worker; another worker can serve a stale cap until TTL (same as existing member budget)

Low

  • Keys bound to an agent are not rerouted to a fallback when a member per-model cap is spent; they get the budget error
  • Removing every row in a member's Per-Model Budgets saves {}, which drops the override so the member follows the team default again
  • The per-model budget pickers list the team's models plus its access group models; a cap on a model the team cannot reach is set through the API
  • Fallback order and targets come from router_settings.fallbacks; with no fallbacks the request is rejected with the budget error
  • Read-only view rounds caps to 4 decimals, so a 0.00005 cap reads $0.0001
  • Prebuilt UI bundle ships with the next scheduled bundle rebuild
  • The proxy rate-limit fallback member budget skip (babe4d4, alias resolution in b7d8a2e and 3df96dd) is covered by unit tests, not a live cell
  • Non-required osv-scan and rust-test were red on the previous head for reasons outside this diff (a braces advisory in the dashboard lockfile and a litellm-traces Rust test); this PR touches neither the lockfile nor any Rust

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

Link to Devin session: https://app.devin.ai/sessions/5605a2cafad64798b30b7a426d76d4e6
Open in Devin Desktop: https://app.devin.ai/desktop/session/5605a2cafad64798b30b7a426d76d4e6?variant=devin
Requested by: @yassin-berriai

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High impact] The reviewed code appears safe to merge, with no new blocking issue established.

Summary

Adds per-model budgets for individual team members, with team defaults and member overrides.

  • Teams can set shared per-model caps and members can save their own overrides.
  • Over-cap member requests can use allowed router fallback models.

Reviews (39) · Last reviewed commit: "feat(proxy): per-model team member budge..." · Reviewed by Greptile

greptile-apps[bot]

This comment was marked as resolved.

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.68750% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/auth/user_api_key_auth.py 94.31% 10 Missing ⚠️
...pass_through/context_management/editors/compact.py 75.00% 4 Missing ⚠️
litellm/proxy/common_request_processing.py 88.88% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_team_member_model_budgets (8af95f9) with main (691ca03)

Open in CodSpeed

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review at 9591116, which addresses all four P1 findings from the previous round

github-advanced-security[bot]

This comment was marked as resolved.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review at 9e0c9d0, which squashes a Prettier fix and a constant log message for the CodeQL log injection alerts

@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_team_member_model_budgets branch from 9e0c9d0 to 0ade84d Compare October 1, 2026 08:53
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review the rebased head 0ade84d, which also keeps agent keys off the fallback reroute so agent model grants cannot be bypassed

greptile-apps[bot]

This comment was marked as resolved.

@devin-ai-integration
devin-ai-integration Bot force-pushed the litellm_team_member_model_budgets branch from 0ade84d to 1b3580f Compare October 1, 2026 09:37
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review 1b3580f, which only adds typed Protocol views in user_api_key_auth.py to clear the basedpyright reportUnknownArgumentType ceiling; behavior is unchanged

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review 7dd6a26, which removes the extra auth-time default budget read by using the membership's joined budget row

greptile-apps[bot]

This comment was marked as resolved.

@cursor

cursor Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review head e3b55b7 and refresh the confidence score. In thread r4234700671 you confirmed the own-helper test double finding is stale on this revision, which was the only reason given for 4/5

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-anchor on ff8be00. It squashes e3b55b7 and 62c4e18 (the 5/5 you judged) into one commit with a byte-identical tree to 62c4e18, so the reviewed content is unchanged

@mateo-berri

Copy link
Copy Markdown
Contributor

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 ff8be00. Configure here.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review c36a399, the same single commit rebased onto current main with both review threads addressed

Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head c1955bc, which adds the member budget check to rate-limit fallbacks in _pre_call_with_fallbacks

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head 6e5ee41, which limits the rate-limit backup gate to member caps and reworks the tests

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head babe4d4, which adds the zero-cost bypass to the rate-limit backup member cap check

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head b4d51d8, which only sanitizes the logged model name and error in the rate-limit backup gate

Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head 8382348, which resolves backup aliases before member cap checks and lets free backups skip spend caps

Comment thread litellm/proxy/auth/user_api_key_auth.py Resolved
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head b7d8a2e, which resolves backup aliases before member cap checks and lets free backups skip spend caps

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please review head 3df96dd, where the auth-time fallback walk checks member caps and price on the model served after every alias

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-anchor on 018fca2, the same single commit rebased onto current main with no content change

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-anchor on 95c4356, same commit rebased onto main with a one hunk Teams.tsx conflict merged

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-anchor on ea54c20, which types the new budget call sites so the basedpyright gate holds against main

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

This branch had an error being deployed

1 failed deployment
e2e-changed — 8af95f90 Deployed Oct 10, 2026 by devin-ai-integration[bot] via oauth #4446
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants