-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
feat: team override model #24330
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Harshit28j
wants to merge
9
commits into
BerriAI:main
Choose a base branch
from
Harshit28j:litellm_feat_team-model-override
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,597
−403
Open
feat: team override model #24330
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
82fecaa
feat: team override model
Harshit28j 237d835
fix: req changes from greptile
Harshit28j 0199f21
fix: req changes by greptile
Harshit28j 55c3d5c
fix: greptile req changes
Harshit28j b62fdbd
fix: req changes
Harshit28j 9a11474
fix: req changes by greptile
Harshit28j d8a47eb
fix: greptile feedback
Harshit28j b479aa0
fix: req changes by greptile
Harshit28j a2ecbd9
fix: req changes by greptile
Harshit28j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -113,6 +113,157 @@ curl --location 'http://0.0.0.0:4000/chat/completions' \ | |
|
|
||
| ### [API Reference](https://litellm-api.up.railway.app/#/team%20management/new_team_team_new_post) | ||
|
|
||
| ## **Per-Member Model Overrides (Team-Scoped Defaults)** | ||
|
|
||
| :::info | ||
|
|
||
| Requires `TEAM_MODEL_OVERRIDES=true` environment variable or `litellm.team_model_overrides_enabled = True`. | ||
|
|
||
| ::: | ||
|
|
||
| By default, every team member can access all models in `team.models`. With per-member model overrides, you can: | ||
|
|
||
| - Set **`default_models`** on a team — the models every member gets by default | ||
| - Set **`models`** on individual team members — additional models only they can access | ||
|
|
||
| A member's **effective models** = `default_models` ∪ `member.models`. If neither is set, falls back to `team.models` (full backward compatibility). | ||
|
|
||
| ### Enable the Feature | ||
|
|
||
| Add to your `config.yaml`: | ||
|
|
||
| ```yaml | ||
| environment_variables: | ||
| TEAM_MODEL_OVERRIDES: "true" | ||
| ``` | ||
|
|
||
| ### 1. Create a Team with Default Models | ||
|
|
||
| ```shell | ||
| curl -L 'http://localhost:4000/team/new' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "team_alias": "engineering", | ||
| "models": ["gpt-4", "gpt-4o-mini", "gpt-4o"], | ||
| "default_models": ["gpt-4o-mini"] | ||
| }' | ||
| ``` | ||
|
|
||
|
Comment on lines
+144
to
+152
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The docs state:
Two behaviours are not documented:
|
||
| - `models` — the full pool of models the team is allowed to use | ||
| - `default_models` — the subset every member gets by default (must be a subset of `models`) | ||
|
|
||
| ### 2. Add Members with Per-User Overrides | ||
|
|
||
| ```shell | ||
| # Alice gets the default (gpt-4o-mini only) | ||
| curl -L 'http://localhost:4000/team/member_add' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "team_id": "<team-id>", | ||
| "member": {"role": "user", "user_id": "alice"} | ||
| }' | ||
|
|
||
| # Bob gets gpt-4o in addition to the default | ||
| curl -L 'http://localhost:4000/team/member_add' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "team_id": "<team-id>", | ||
| "member": {"role": "user", "user_id": "bob", "models": ["gpt-4o"]} | ||
| }' | ||
| ``` | ||
|
|
||
| | Member | Override | Effective Models | | ||
| |--------|----------|-----------------| | ||
| | Alice | none | `["gpt-4o-mini"]` | | ||
| | Bob | `["gpt-4o"]` | `["gpt-4o-mini", "gpt-4o"]` | | ||
|
|
||
| ### 3. Generate Keys and Test | ||
|
|
||
| ```shell | ||
| # Generate key for Bob | ||
| curl -L 'http://localhost:4000/key/generate' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"team_id": "<team-id>", "user_id": "bob"}' | ||
| ``` | ||
|
|
||
| <Tabs> | ||
| <TabItem label="Allowed (Bob → gpt-4o)" value="allowed"> | ||
|
|
||
| ```shell | ||
| curl -L 'http://localhost:4000/chat/completions' \ | ||
| -H 'Authorization: Bearer <bob-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "Hello"}]}' | ||
| ``` | ||
|
|
||
| Returns `200 OK` — `gpt-4o` is in Bob's effective set. | ||
|
|
||
| </TabItem> | ||
| <TabItem label="Denied (Bob → gpt-4)" value="denied"> | ||
|
|
||
| ```shell | ||
| curl -L 'http://localhost:4000/chat/completions' \ | ||
| -H 'Authorization: Bearer <bob-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{"model": "gpt-4", "messages": [{"role": "user", "content": "Hello"}]}' | ||
| ``` | ||
|
|
||
| Returns `401 Unauthorized` — `gpt-4` is in the team pool but not in Bob's effective set. | ||
|
|
||
| </TabItem> | ||
| </Tabs> | ||
|
|
||
| ### 4. Update Member Overrides | ||
|
|
||
| ```shell | ||
| # Add gpt-4 to Bob's overrides | ||
| curl -L 'http://localhost:4000/team/member_update' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "team_id": "<team-id>", | ||
| "user_id": "bob", | ||
| "models": ["gpt-4o", "gpt-4"] | ||
| }' | ||
|
|
||
| # Remove all overrides (Bob falls back to default_models only) | ||
| curl -L 'http://localhost:4000/team/member_update' \ | ||
| -H 'Authorization: Bearer <your-master-key>' \ | ||
| -H 'Content-Type: application/json' \ | ||
| -d '{ | ||
| "team_id": "<team-id>", | ||
| "user_id": "bob", | ||
| "models": [] | ||
| }' | ||
| ``` | ||
|
|
||
| ### Validation Rules | ||
|
|
||
| | Rule | Error | | ||
| |------|-------| | ||
| | `default_models` must be a subset of `team.models` | `400` on `/team/new` and `/team/update` | | ||
| | Member `models` must be a subset of `team.models` | `400` on `/team/member_add` and `/team/member_update` | | ||
| | Key `models` must be a subset of effective models | `403` on `/key/generate` | | ||
| | Narrowing `team.models` auto-prunes stale `default_models` | Automatic on `/team/update` | | ||
|
|
||
| ### Important Notes | ||
|
|
||
| - **Effective models are capped by `team.models`**: If `team.models` is later narrowed, any member overrides outside the new pool are silently excluded at runtime — no access is granted beyond the team's allowed list. | ||
| - **Service/bot keys** (keys without a `user_id`) are **not affected** by this feature. They always use the full `team.models` pool, preserving backward compatibility. | ||
| - **Access groups** (`access_group_ids`) are a team-level concept and are **not** restricted by per-member overrides. Models granted via access groups remain available to all team members. | ||
|
|
||
| ### Backward Compatibility | ||
|
|
||
| When the feature flag is off **or** when neither `default_models` nor member `models` is configured: | ||
|
|
||
| - `get_effective_team_models()` returns `team.models` unchanged | ||
| - All existing teams and keys work exactly as before | ||
| - Zero extra database queries on the auth hot path | ||
|
|
||
|
|
||
| ## **View Available Fallback Models** | ||
|
|
||
|
|
||
5 changes: 5 additions & 0 deletions
5
...ras/litellm_proxy_extras/migrations/20260321000001_add_team_model_overrides/migration.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| -- AlterTable: Add default_models to LiteLLM_TeamTable | ||
| ALTER TABLE "LiteLLM_TeamTable" ADD COLUMN IF NOT EXISTS "default_models" TEXT[] DEFAULT ARRAY[]::TEXT[]; | ||
|
|
||
| -- AlterTable: Add models to LiteLLM_TeamMembership | ||
| ALTER TABLE "LiteLLM_TeamMembership" ADD COLUMN IF NOT EXISTS "models" TEXT[] DEFAULT ARRAY[]::TEXT[]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
access_group_idssilently bypasses per-member model restrictionsThe docs describe the feature as providing fine-grained per-member model access control. However,
can_team_access_modelinauth_checks.pyfalls back to the team'saccess_group_idsafter the per-member effective-models check fails — without any restriction from the user'seffective_modelsset. The code comment acknowledges this:This means:
["gpt-4o-mini"]via per-member overridesaccess_group_ids = ["premium-models"]which includes["gpt-4", "claude-3"]gpt-4andclaude-3through the access-group bypass even though they're not in their effective model setThe docs should explicitly call this out so admins understand that
access_group_idsis an additive team-wide grant that overrides per-member restrictions. Without this note, an admin who configures per-member restrictions for compliance or cost-control may unknowingly leave a bypass path open.