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
fix(budget): serialize model_max_budget before the /budget/update write
Yuneng Jiang4d6786d420eb
diff --git a/litellm/proxy/management_endpoints/budget_management_endpoints.py b/litellm/proxy/management_endpoints/budget_management_endpoints.pyindex 17a845d4300..62a24109dbb 100644--- a/litellm/proxy/management_endpoints/budget_management_endpoints.py+++ b/litellm/proxy/management_endpoints/budget_management_endpoints.py@@ -13,6 +13,7 @@ All /budget management endpoints#### BUDGET TABLE MANAGEMENT ####import math+from collections.abc import Mappingfrom typing import Finalfrom fastapi import APIRouter, Depends, HTTPException@@ -178,13 +179,17 @@ async def update_budget(else {})- response: Final = await BudgetRepository(prisma_client).table.update(- where={"budget_id": budget_obj.budget_id},- data={+ budget_obj_jsonified: Final[Mapping[str, object]] = jsonify_object(+ {**budget_obj.model_dump(exclude_unset=True),**recomputed_reset_at,"updated_by": user_api_key_dict.user_id or litellm_proxy_admin_name,- },+ }+ )++ response: Final = await BudgetRepository(prisma_client).table.update(+ where={"budget_id": budget_obj.budget_id},+ data=budget_obj_jsonified,)return responsediff --git a/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.pyindex 0bad0d24be5..0337381b84b 100644--- a/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_budget_endpoints.py@@ -1,5 +1,6 @@# tests/test_budget_endpoints.py+import jsonimport typesfrom datetime import datetime, timedelta, timezoneimport pytest@@ -388,3 +389,34 @@ async def test_update_budget_duration_none_does_not_recompute(client_and_mocks):assert "budget_duration" in captured and captured["budget_duration"] is Noneassert "budget_reset_at" not in captured+++async def test_update_budget_serializes_model_max_budget_for_prisma(+ client_and_mocks, monkeypatch+):+ monkeypatch.setattr(ps, "premium_user", True)++ client, _, mock_table = client_and_mocks+ captured = _capture_update_data(mock_table)++ resp = client.post(+ "/budget/update",+ json={+ "budget_id": "budget_per_model",+ "model_max_budget": {+ "gpt4o": {"budget_limit": 5.0, "time_period": "1d"},+ "glm-5.2": {"budget_limit": 7.5, "time_period": "30d"},+ },+ },+ )+ assert resp.status_code == 200, resp.text++ stored = captured["model_max_budget"]+ assert isinstance(stored, str), (+ f"model_max_budget must reach prisma as a JSON string, got {type(stored).__name__}"+ )+ assert json.loads(stored) == {+ "gpt4o": {"max_budget": 5.0, "budget_duration": "1d"},+ "glm-5.2": {"max_budget": 7.5, "budget_duration": "30d"},+ }