litellm/tests/enterprise/litellm_enterprise/proxy
ryan-crabbe-berri e195532c14
fix(proxy): count only active users toward license seat limit (#31227)
* fix(proxy): count only active users toward license seat limit

SCIM-deactivated users (metadata.scim_active == false) are kept in LiteLLM_UserTable for audit and reactivation, but they were still counted toward the per-user license limit, so deactivating a user never freed a seat. Okta never sends a SCIM DELETE and Entra only hard-deletes well after deactivation, so deactivation has to be what frees the seat

Add UserRepository.count_billable_users(), which counts every row except those where metadata.scim_active is false (absent, null, and true all count), and route the user-create license gate, the free-SSO 5-user cap, and the enterprise /user/available_users display through it. A separate litellm_active_users Prometheus gauge reports the billable count while litellm_total_users keeps its original meaning so existing dashboards are unaffected

* fix(proxy): floor billable user count at zero

count_billable_users() runs two separate count queries (total, then deactivated). Under a burst of deactivations between them, the deactivated count can momentarily exceed the earlier total and produce a negative result, which would flow into is_over_limit as a negative and show a negative seat count in the display and gauge. Clamp the result to zero so a transient race can never yield a nonsensical negative; the value self-corrects on the next call

Addresses Greptile P1 on the PR

* refactor(proxy): count teams via TeamRepository in available_users

* style: ruff format changed files at line-length 120
2026-06-29 18:01:02 -07:00
..
auth feat(auth): resolve caller identity once into a Principal at the auth seam (#30887) 2026-06-20 18:49:41 -07:00
guardrails fix(bedrock_guardrails): select latest user message by original role in apply_guardrail (#30482) 2026-06-26 20:58:23 +05:30
hooks fix(bedrock): support tool search results + chat annotations (#29120) 2026-05-29 20:48:36 -07:00
management_endpoints fix(proxy): count only active users toward license seat limit (#31227) 2026-06-29 18:01:02 -07:00
test_audit_logging_endpoints.py fixes test 2025-10-28 17:43:04 -07:00