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(proxy): serialize team budget_limits to JSON in jsonify_team_object (#31045)

yuneng-jiang6f6aec29302b
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index ea8ab2f9b8e..755602cbcc0 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -3792,6 +3792,10 @@ class PrismaClient:
db_data["members_with_roles"], list
):
db_data["members_with_roles"] = json.dumps(db_data["members_with_roles"])
+ if db_data.get("budget_limits", None) is not None and isinstance(
+ db_data["budget_limits"], list
+ ):
+ db_data["budget_limits"] = json.dumps(db_data["budget_limits"])
return db_data
# Define a retrying strategy with exponential backoff
diff --git a/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py b/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
index d517c1c346f..87063bdf00b 100644
--- a/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
+++ b/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
@@ -105,6 +105,33 @@ def test_jsonify_team_object_converts_members_to_json_string(
}
+def test_jsonify_team_object_converts_budget_limits_to_json_string(
+ prisma_client: PrismaClient,
+) -> None:
+ data = {
+ "team_id": "t1",
+ "budget_limits": [
+ {
+ "budget_duration": "1d",
+ "max_budget": 10.0,
+ "reset_at": "2026-01-01T00:00:00Z",
+ },
+ {
+ "budget_duration": "7d",
+ "max_budget": 50.0,
+ "reset_at": "2026-01-07T00:00:00Z",
+ },
+ ],
+ "models": ["gpt-4"],
+ }
+ result = prisma_client.jsonify_team_object(data)
+ assert result == {
+ "team_id": "t1",
+ "budget_limits": json.dumps(data["budget_limits"]),
+ "models": ["gpt-4"],
+ }
+
+
def test_jsonify_team_object_error_on_non_dict(prisma_client: PrismaClient) -> None:
with pytest.raises(AttributeError):
prisma_client.jsonify_team_object(None) # type: ignore[arg-type]