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(customer): resolve budget_id field routing and missing required fields in /customer/update

Jason Jensen956ed080034c
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},
)
)