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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Verbose error on admin add (#10978)
Jugal D. Bhatt03cda2468158
diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.pyindex f2ea89dd318..60f05902522 100644--- a/litellm/proxy/management_endpoints/team_endpoints.py+++ b/litellm/proxy/management_endpoints/team_endpoints.py@@ -1110,7 +1110,7 @@ async def team_member_update(Update team member budgets and team member role"""- from litellm.proxy.proxy_server import prisma_client+ from litellm.proxy.proxy_server import prisma_client, premium_userif prisma_client is None:raise HTTPException(status_code=500, detail={"error": "No db connected"})@@ -1118,6 +1118,13 @@ async def team_member_update(if data.team_id is None:raise HTTPException(status_code=400, detail={"error": "No team id passed in"})++ if data.role == "admin" and not premium_user:+ # exactly the same text your proxy throws for add:+ raise HTTPException(+ status_code=400,+ detail="Assigning team admins is a premium feature. You must be a LiteLLM Enterprise user to use this feature. If you have a license please set `LITELLM_LICENSE` in your env. Get a 7 day trial key here: https://www.litellm.ai/#trial. Pricing: https://www.litellm.ai/#pricing"+ )if data.user_id is None and data.user_email is None:raise HTTPException(status_code=400,diff --git a/tests/litellm/proxy/test_team_member_update.py b/tests/litellm/proxy/test_team_member_update.pynew file mode 100644index 00000000000..7f534b0b618--- /dev/null+++ b/tests/litellm/proxy/test_team_member_update.py@@ -0,0 +1,39 @@+import pytest+from fastapi import HTTPException+from starlette.requests import Request++from litellm.proxy.management_endpoints.team_endpoints import team_member_update+from litellm.proxy._types import TeamMemberUpdateRequest+import litellm.proxy.proxy_server as proxy_server++async def test_team_member_update_admin_requires_premium(monkeypatch):+ # Arrange: patch prisma_client and premium_user+ monkeypatch.setattr(proxy_server, 'prisma_client', object())+ monkeypatch.setattr(proxy_server, 'premium_user', False)++ # Create a request body that tries to set role=admin+ data = TeamMemberUpdateRequest(+ team_id="team-1234",+ user_id="user-1",+ user_email=None,+ role="admin",+ max_budget_in_team=None,+ )+ scope = {"type": "http", "method": "POST", "path": "/team/member_update"}+ request = Request(scope)++ # We don't need a full auth object since premium check happens before auth is used+ auth = object()++ # Act & Assert: expect HTTPException 400 with the exact premium feature message+ with pytest.raises(HTTPException) as exc_info:+ await team_member_update(data, request, auth)++ assert exc_info.value.status_code == 400+ expected_msg = (+ "Assigning team admins is a premium feature. You must be a LiteLLM Enterprise user to use this feature. "+ "If you have a license please set `LITELLM_LICENSE` in your env. Get a 7 day trial key here: https://www.litellm.ai/#trial. "+ "Pricing: https://www.litellm.ai/#pricing"+ )+ assert exc_info.value.detail == expected_msgdiff --git a/ui/litellm-dashboard/src/components/networking.tsx b/ui/litellm-dashboard/src/components/networking.tsxindex 86d63cfc17b..ba9d1cb34a5 100644--- a/ui/litellm-dashboard/src/components/networking.tsx+++ b/ui/litellm-dashboard/src/components/networking.tsx@@ -3358,14 +3358,15 @@ export interface Member {export const teamMemberAddCall = async (accessToken: string,teamId: string,- formValues: Member // Assuming formValues is an object+ formValues: Member) => {try {- console.log("Form Values in teamMemberAddCall:", formValues); // Log the form values before making the API call+ console.log("Form Values in teamMemberAddCall:", formValues);const url = proxyBaseUrl? `${proxyBaseUrl}/team/member_add`: `/team/member_add`;+const response = await fetch(url, {method: "POST",headers: {@@ -3374,21 +3375,30 @@ export const teamMemberAddCall = async (},body: JSON.stringify({team_id: teamId,- member: formValues, // Include formValues in the request body+ member: formValues,}),});if (!response.ok) {- const errorData = await response.text();- handleError(errorData);- console.error("Error response from the server:", errorData);- throw new Error("Network response was not ok");+ // Read and parse JSON error body+ const errorText = await response.text();+ let parsedError: any = {};++ try {+ parsedError = JSON.parse(errorText);+ } catch (e) {+ console.warn("Failed to parse error body as JSON:", errorText);+ }++ const rawMessage = parsedError?.detail?.error || "Failed to add team member";+ const err = new Error(rawMessage);+ (err as any).raw = parsedError;+ throw err;}const data = await response.json();console.log("API Response:", data);return data;- // Handle success - you might want to update some state or UI based on the created key} catch (error) {console.error("Failed to create key:", error);throw error;@@ -3401,7 +3411,7 @@ export const teamMemberUpdateCall = async (formValues: Member // Assuming formValues is an object) => {try {- console.log("Form Values in teamMemberAddCall:", formValues); // Log the form values before making the API call+ console.log("Form Values in teamMemberUpdateCall:", formValues);const url = proxyBaseUrl? `${proxyBaseUrl}/team/member_update`@@ -3420,21 +3430,30 @@ export const teamMemberUpdateCall = async (});if (!response.ok) {- const errorData = await response.text();- handleError(errorData);- console.error("Error response from the server:", errorData);- throw new Error("Network response was not ok");+ // Read and parse JSON error body+ const errorText = await response.text();+ let parsedError: any = {};++ try {+ parsedError = JSON.parse(errorText);+ } catch (e) {+ console.warn("Failed to parse error body as JSON:", errorText);+ }++ const rawMessage = parsedError?.detail?.error || "Failed to add team member";+ const err = new Error(rawMessage);+ (err as any).raw = parsedError;+ throw err;}const data = await response.json();console.log("API Response:", data);return data;- // Handle success - you might want to update some state or UI based on the created key} catch (error) {- console.error("Failed to create key:", error);+ console.error("Failed to update team member:", error);throw error;}-}+};export const teamMemberDeleteCall = async (accessToken: string,diff --git a/ui/litellm-dashboard/src/components/team/edit_membership.tsx b/ui/litellm-dashboard/src/components/team/edit_membership.tsxindex 27e64193e35..5ffc1dd5945 100644--- a/ui/litellm-dashboard/src/components/team/edit_membership.tsx+++ b/ui/litellm-dashboard/src/components/team/edit_membership.tsx@@ -78,9 +78,9 @@ const MemberModal = <T extends BaseMember>({onSubmit(formData);form.resetFields();- message.success(`Successfully ${mode === 'add' ? 'added' : 'updated'} member`);+ // message.success(`Successfully ${mode === 'add' ? 'added' : 'updated'} member`);} catch (error) {- message.error('Failed to submit form');+ // message.error('Failed to submit form');console.error('Form submission error:', error);}};diff --git a/ui/litellm-dashboard/src/components/team/team_info.tsx b/ui/litellm-dashboard/src/components/team/team_info.tsxindex f195e0845df..d502097b8f5 100644--- a/ui/litellm-dashboard/src/components/team/team_info.tsx+++ b/ui/litellm-dashboard/src/components/team/team_info.tsx@@ -115,26 +115,36 @@ const TeamInfoView: React.FC<TeamInfoProps> = ({const handleMemberCreate = async (values: any) => {try {- if (accessToken == null) {- return;- }-+ if (accessToken == null) return;+const member: Member = {user_email: values.user_email,user_id: values.user_id,role: values.role,- }- const response = await teamMemberAddCall(accessToken, teamId, member);-+ };++ await teamMemberAddCall(accessToken, teamId, member);+message.success("Team member added successfully");setIsAddMemberModalVisible(false);form.resetFields();fetchTeamInfo();- } catch (error) {- message.error("Failed to add team member");+ } catch (error: any) {+ let errMsg = "Failed to add team member";++ if (error?.raw?.detail?.error?.includes("Assigning team admins is a premium feature")) {+ errMsg = "Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.";+ } else if (error?.message) {+ errMsg = error.message;+ }++ message.error(errMsg);console.error("Error adding team member:", error);}};+++const handleMemberUpdate = async (values: any) => {try {@@ -147,17 +157,29 @@ const TeamInfoView: React.FC<TeamInfoProps> = ({user_id: values.user_id,role: values.role,}+ message.destroy(); // Remove all existing toasts- const response = await teamMemberUpdateCall(accessToken, teamId, member);+ await teamMemberUpdateCall(accessToken, teamId, member);message.success("Team member updated successfully");setIsEditMemberModalVisible(false);fetchTeamInfo();- } catch (error) {- message.error("Failed to update team member");+ } catch (error: any) {+ let errMsg = "Failed to update team member";+ if (error?.raw?.detail?.includes("Assigning team admins is a premium feature")) {+ errMsg = "Assigning admins is an enterprise-only feature. Please upgrade your LiteLLM plan to enable this.";+ } else if (error?.message) {+ errMsg = error.message;+ }+ setIsEditMemberModalVisible(false);++ message.destroy(); // Remove all existing toasts++ message.error(errMsg);console.error("Error updating team member:", error);}};+const handleMemberDelete = async (member: Member) => {try {