Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

fix(model_management_endpoints.py): fix allowing team admins to update team models (#9697)

Krish Dholakia6c69ad4c89c9
diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html
deleted file mode 100644
index c84fe10598f..00000000000
--- a/litellm/proxy/_experimental/out/onboarding.html
+++ /dev/null
@@ -1 +0,0 @@
-<!DOCTYPE html><html id="__next_error__"><head><meta charSet="utf-8"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="preload" as="script" fetchPriority="low" href="/ui/_next/static/chunks/webpack-75a5453f51d60261.js"/><script src="/ui/_next/static/chunks/fd9d1056-524b80e1a6b8bb06.js" async=""></script><script src="/ui/_next/static/chunks/117-883150efc583d711.js" async=""></script><script src="/ui/_next/static/chunks/main-app-4f7318ae681a6d94.js" async=""></script><title>LiteLLM Dashboard</title><meta name="description" content="LiteLLM Proxy Admin UI"/><link rel="icon" href="/ui/favicon.ico" type="image/x-icon" sizes="16x16"/><meta name="next-size-adjust"/><script src="/ui/_next/static/chunks/polyfills-42372ed130431b0a.js" noModule=""></script></head><body><script src="/ui/_next/static/chunks/webpack-75a5453f51d60261.js" async=""></script><script>(self.__next_f=self.__next_f||[]).push([0]);self.__next_f.push([2,null])</script><script>self.__next_f.push([1,"1:HL[\"/ui/_next/static/media/a34f9d1faa5f3315-s.p.woff2\",\"font\",{\"crossOrigin\":\"\",\"type\":\"font/woff2\"}]\n2:HL[\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"style\"]\n3:HL[\"/ui/_next/static/css/1f6915676624c422.css\",\"style\"]\n"])</script><script>self.__next_f.push([1,"4:I[12846,[],\"\"]\n6:I[19107,[],\"ClientPageRoot\"]\n7:I[12011,[\"665\",\"static/chunks/3014691f-0b72c78cfebbd712.js\",\"42\",\"static/chunks/42-1cbed529ecb084e0.js\",\"899\",\"static/chunks/899-9af4feaf6f21839c.js\",\"250\",\"static/chunks/250-dfc03a6fb4f0d254.js\",\"461\",\"static/chunks/app/onboarding/page-2bf7a26db5342dbf.js\"],\"default\",1]\n8:I[4707,[],\"\"]\n9:I[36423,[],\"\"]\nb:I[61060,[],\"\"]\nc:[]\n"])</script><script>self.__next_f.push([1,"0:[\"$\",\"$L4\",null,{\"buildId\":\"Yb50LG5p7c9QpG54GIoFV\",\"assetPrefix\":\"/ui\",\"urlParts\":[\"\",\"onboarding\"],\"initialTree\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{}]}]},\"$undefined\",\"$undefined\",true],\"initialSeedData\":[\"\",{\"children\":[\"onboarding\",{\"children\":[\"__PAGE__\",{},[[\"$L5\",[\"$\",\"$L6\",null,{\"props\":{\"params\":{},\"searchParams\":{}},\"Component\":\"$7\"}],null],null],null]},[null,[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\",\"onboarding\",\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":\"$undefined\",\"notFoundStyles\":\"$undefined\"}]],null]},[[[[\"$\",\"link\",\"0\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/86f6cc749f6b8493.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}],[\"$\",\"link\",\"1\",{\"rel\":\"stylesheet\",\"href\":\"/ui/_next/static/css/1f6915676624c422.css\",\"precedence\":\"next\",\"crossOrigin\":\"$undefined\"}]],[\"$\",\"html\",null,{\"lang\":\"en\",\"children\":[\"$\",\"body\",null,{\"className\":\"__className_cf7686\",\"children\":[\"$\",\"$L8\",null,{\"parallelRouterKey\":\"children\",\"segmentPath\":[\"children\"],\"error\":\"$undefined\",\"errorStyles\":\"$undefined\",\"errorScripts\":\"$undefined\",\"template\":[\"$\",\"$L9\",null,{}],\"templateStyles\":\"$undefined\",\"templateScripts\":\"$undefined\",\"notFound\":[[\"$\",\"title\",null,{\"children\":\"404: This page could not be found.\"}],[\"$\",\"div\",null,{\"style\":{\"fontFamily\":\"system-ui,\\\"Segoe UI\\\",Roboto,Helvetica,Arial,sans-serif,\\\"Apple Color Emoji\\\",\\\"Segoe UI Emoji\\\"\",\"height\":\"100vh\",\"textAlign\":\"center\",\"display\":\"flex\",\"flexDirection\":\"column\",\"alignItems\":\"center\",\"justifyContent\":\"center\"},\"children\":[\"$\",\"div\",null,{\"children\":[[\"$\",\"style\",null,{\"dangerouslySetInnerHTML\":{\"__html\":\"body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}\"}}],[\"$\",\"h1\",null,{\"className\":\"next-error-h1\",\"style\":{\"display\":\"inline-block\",\"margin\":\"0 20px 0 0\",\"padding\":\"0 23px 0 0\",\"fontSize\":24,\"fontWeight\":500,\"verticalAlign\":\"top\",\"lineHeight\":\"49px\"},\"children\":\"404\"}],[\"$\",\"div\",null,{\"style\":{\"display\":\"inline-block\"},\"children\":[\"$\",\"h2\",null,{\"style\":{\"fontSize\":14,\"fontWeight\":400,\"lineHeight\":\"49px\",\"margin\":0},\"children\":\"This page could not be found.\"}]}]]}]}]],\"notFoundStyles\":[]}]}]}]],null],null],\"couldBeIntercepted\":false,\"initialHead\":[null,\"$La\"],\"globalErrorComponent\":\"$b\",\"missingSlots\":\"$Wc\"}]\n"])</script><script>self.__next_f.push([1,"a:[[\"$\",\"meta\",\"0\",{\"name\":\"viewport\",\"content\":\"width=device-width, initial-scale=1\"}],[\"$\",\"meta\",\"1\",{\"charSet\":\"utf-8\"}],[\"$\",\"title\",\"2\",{\"children\":\"LiteLLM Dashboard\"}],[\"$\",\"meta\",\"3\",{\"name\":\"description\",\"content\":\"LiteLLM Proxy Admin UI\"}],[\"$\",\"link\",\"4\",{\"rel\":\"icon\",\"href\":\"/ui/favicon.ico\",\"type\":\"image/x-icon\",\"sizes\":\"16x16\"}],[\"$\",\"meta\",\"5\",{\"name\":\"next-size-adjust\"}]]\n5:null\n"])</script></body></html>
\ No newline at end of file
diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py
index 0e8a9e4cc87..3d93c9f4b37 100644
--- a/litellm/proxy/management_endpoints/model_management_endpoints.py
+++ b/litellm/proxy/management_endpoints/model_management_endpoints.py
@@ -394,7 +394,7 @@ class ModelManagementAuthChecks:
@staticmethod
async def can_user_make_model_call(
- model_params: Union[Deployment, updateDeployment],
+ model_params: Deployment,
user_api_key_dict: UserAPIKeyAuth,
prisma_client: PrismaClient,
premium_user: bool,
@@ -723,8 +723,38 @@ async def update_model(
},
)
+ _model_id = None
+ _model_info = getattr(model_params, "model_info", None)
+ if _model_info is None:
+ raise Exception("model_info not provided")
+
+ _model_id = _model_info.id
+ if _model_id is None:
+ raise Exception("model_info.id not provided")
+
+ _existing_litellm_params = (
+ await prisma_client.db.litellm_proxymodeltable.find_unique(
+ where={"model_id": _model_id}
+ )
+ )
+
+ if _existing_litellm_params is None:
+ if (
+ llm_router is not None
+ and llm_router.get_deployment(model_id=_model_id) is not None
+ ):
+ raise HTTPException(
+ status_code=400,
+ detail={
+ "error": "Can't edit model. Model in config. Store model in db via `/model/new`. to edit."
+ },
+ )
+ else:
+ raise Exception("model not found")
+ deployment = Deployment(**_existing_litellm_params.model_dump())
+
await ModelManagementAuthChecks.can_user_make_model_call(
- model_params=model_params,
+ model_params=deployment,
user_api_key_dict=user_api_key_dict,
prisma_client=prisma_client,
premium_user=premium_user,
@@ -732,31 +762,6 @@ async def update_model(
# update DB
if store_model_in_db is True:
- _model_id = None
- _model_info = getattr(model_params, "model_info", None)
- if _model_info is None:
- raise Exception("model_info not provided")
-
- _model_id = _model_info.id
- if _model_id is None:
- raise Exception("model_info.id not provided")
- _existing_litellm_params = (
- await prisma_client.db.litellm_proxymodeltable.find_unique(
- where={"model_id": _model_id}
- )
- )
- if _existing_litellm_params is None:
- if (
- llm_router is not None
- and llm_router.get_deployment(model_id=_model_id) is not None
- ):
- raise HTTPException(
- status_code=400,
- detail={
- "error": "Can't edit model. Model in config. Store model in db via `/model/new`. to edit."
- },
- )
- raise Exception("model not found")
_existing_litellm_params_dict = dict(
_existing_litellm_params.litellm_params
)
diff --git a/tests/test_models.py b/tests/test_models.py
index 848c4014451..31e564a8293 100644
--- a/tests/test_models.py
+++ b/tests/test_models.py
@@ -10,7 +10,6 @@ from dotenv import load_dotenv
load_dotenv()
-
async def generate_key(session, models=[]):
url = "http://0.0.0.0:4000/key/generate"
headers = {"Authorization": "Bearer sk-1234", "Content-Type": "application/json"}
@@ -58,10 +57,43 @@ async def test_get_models():
await get_models(session=session, key=key)
-async def add_models(session, model_id="123", model_name="azure-gpt-3.5"):
+async def add_models(session, model_id="123", model_name="azure-gpt-3.5", key="sk-1234", team_id=None):
url = "http://0.0.0.0:4000/model/new"
headers = {
- "Authorization": f"Bearer sk-1234",
+ "Authorization": f"Bearer {key}",
+ "Content-Type": "application/json",
+ }
+
+ data = {
+ "model_name": model_name,
+ "litellm_params": {
+ "model": "azure/chatgpt-v-2",
+ "api_key": "os.environ/AZURE_API_KEY",
+ "api_base": "https://openai-gpt-4-test-v-1.openai.azure.com/",
+ "api_version": "2023-05-15",
+ },
+ "model_info": {"id": model_id},
+ }
+
+ if team_id:
+ data["model_info"]["team_id"] = team_id
+
+ async with session.post(url, headers=headers, json=data) as response:
+ status = response.status
+ response_text = await response.text()
+ print(f"Add models {response_text}")
+ print()
+
+ if status != 200:
+ raise Exception(f"Request did not return a 200 status code: {status}")
+
+ response_json = await response.json()
+ return response_json
+
+async def update_model(session, model_id="123", model_name="azure-gpt-3.5", key="sk-1234"):
+ url = "http://0.0.0.0:4000/model/update"
+ headers = {
+ "Authorization": f"Bearer {key}",
"Content-Type": "application/json",
}
@@ -199,13 +231,13 @@ async def test_get_specific_model():
)
-async def delete_model(session, model_id="123"):
+async def delete_model(session, model_id="123", key="sk-1234"):
"""
Make sure only models user has access to are returned
"""
url = "http://0.0.0.0:4000/model/delete"
headers = {
- "Authorization": f"Bearer sk-1234",
+ "Authorization": f"Bearer {key}",
"Content-Type": "application/json",
}
data = {"id": model_id}
@@ -441,3 +473,49 @@ async def test_model_group_info_e2e():
has_anthropic_claude_3_opus = True
assert has_anthropic_claude_3_5_haiku and has_anthropic_claude_3_opus
+
+
+async def test_team_model_e2e():
+ """
+ Test team model e2e
+
+ - create team
+ - create user
+ - add user to team as admin
+ - add model to team
+ - update model
+ - delete model
+ """
+ from test_users import new_user
+ from test_team import new_team
+ import uuid
+ async with aiohttp.ClientSession() as session:
+ # Creat a user
+ user_data = await new_user(session=session, i=0)
+ user_id = user_data["user_id"]
+ user_api_key = user_data["key"]
+
+ # Create a team
+ member_list = [
+ {"role": "admin", "user_id": user_id},
+ ]
+ team_data = await new_team(session=session, member_list=member_list, i=0)
+ team_id = team_data["team_id"]
+
+ model_id = str(uuid.uuid4())
+ model_name = "my-test-model"
+ # Add model to team
+ model_data = await add_models(session=session, model_id=model_id, model_name=model_name, key=user_api_key, team_id=team_id)
+ model_id = model_data["model_id"]
+
+ # Update model
+ model_data = await update_model(session=session, model_id=model_id, model_name=model_name, key=user_api_key)
+ model_id = model_data["model_id"]
+
+ # Delete model
+ await delete_model(session=session, model_id=model_id, key=user_api_key)
+
+
+
+