Documentation
Team & Enterprise
Budget Controls
Set monthly USD spend caps per team or project. Get email alerts at 80% and 100% of budget. Optionally hard-stop all LLM calls when the cap is hit.
How budgets work
- Create a budget with a monthly USD cap and alert threshold.
- Pass
budget_idinlaghav_optionson API calls to charge against that budget. - Laghav tracks spend in Redis (key:
laghav:budget:{tenant_id}:{budget_id}:{YYYY-MM}). - At 80%: Admin receives N06 warning email.
- At 100%: Admin receives N07 alert email. If
hard_stop: true, calls return 402.
Create a budget
bash
curl -X POST https://api.laghav.ai/api/budgets \-H "Authorization: Bearer lgh_live_xxx" \-H "Content-Type: application/json" \-d '{"team_name": "Engineering","monthly_budget_usd": 500,"alert_threshold_pct": 80,"hard_stop": false}'# Response: { "id": "budget_abc", "team_name": "Engineering", ... }
Charging calls against a budget
budget.py
response = client.complete(messages=messages,model="auto",laghav_options={"budget_id": "engineering" # or use the budget ID from the API})# This call's cost_actual_usd is added to the engineering budget counter
Budget exceeded response
budget-exceeded.json
{error: "Team monthly budget cap reached",code: "BUDGET_EXCEEDED",budget_id: "budget_abc",spent_usd: 500.12,limit_usd: 500.00,request_id: "lgh_req_xyz"}
⚠hard_stop vs alert-only
With
hard_stop: false (default), calls continue beyond budget but you receive the N07 alert email. With hard_stop: true, calls are blocked with 402 BUDGET_EXCEEDED once the cap is hit.List budgets
bash
curl https://api.laghav.ai/api/budgets \-H "Authorization: Bearer lgh_live_xxx"# {# "budgets": [{# "id": "budget_abc",# "team_name": "Engineering",# "monthly_budget_usd": 500,# "alert_threshold_pct": 80,# "spent_this_month_usd": 305.50,# "spent_pct": 61# }]# }