From 956ed080034c9d791aaebdbe890dc4ee9360058f Mon Sep 17 00:00:00 2001 From: Jason Jensen Date: Tue, 8 Jul 2025 23:01:32 +0000 Subject: [PATCH] fix(customer): resolve budget_id field routing and missing required fields in /customer/update - Fix incorrect Prisma relation field from "litellm_endusertable" to "end_users" - Route budget_id to end user data instead of budget table data for linking existing budgets - Add required created_by and updated_by fields when creating new budgets - Import missing litellm_proxy_admin_name dependency Fixes #12437 - 500 error when updating customer with budget_id --- .../customer_endpoints.py | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/management_endpoints/customer_endpoints.py b/litellm/proxy/management_endpoints/customer_endpoints.py index dfc36bf6c4a..c653b3baf88 100644 --- a/litellm/proxy/management_endpoints/customer_endpoints.py +++ b/litellm/proxy/management_endpoints/customer_endpoints.py @@ -417,7 +417,7 @@ async def update_end_user( ``` """ - from litellm.proxy.proxy_server import prisma_client + from litellm.proxy.proxy_server import litellm_proxy_admin_name, prisma_client try: data_json: dict = data.json() @@ -459,19 +459,29 @@ async def update_end_user( budget_table_data = {} update_end_user_table_data = {} for k, v in non_default_values.items(): - if k in LiteLLM_BudgetTable.model_fields.keys(): + # budget_id is for linking to existing budget, not for creating new budget + if k == "budget_id": + update_end_user_table_data[k] = v + elif k in LiteLLM_BudgetTable.model_fields.keys(): budget_table_data[k] = v - if k in LiteLLM_EndUserTable.model_fields.keys(): + elif k in LiteLLM_EndUserTable.model_fields.keys(): update_end_user_table_data[k] = v - ## Check if budget id is set ## + ## Check if we need to create a new budget (only if budget fields are provided, not just budget_id) ## if budget_table_data: if end_user_budget_table is None: ## Create new budget ## budget_table_data_record = ( await prisma_client.db.litellm_budgettable.create( - data=budget_table_data, include={"litellm_endusertable": True} + data={ + **budget_table_data, + "created_by": user_api_key_dict.user_id + or litellm_proxy_admin_name, + "updated_by": user_api_key_dict.user_id + or litellm_proxy_admin_name, + }, + include={"end_users": True}, ) )