collab: Limit free tier usage across all models (#25573)

This PR adjusts the usage checks for the LLM free tier.

Previously we would limit the usage on a per-model basis, meaning the
user would get $10/mo free for each model they had access to.

We now have usage for all models count towards the free tier limit.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2025-02-25 11:42:55 -05:00 committed by GitHub
parent 524e813d20
commit 3a3621f2d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -451,19 +451,19 @@ async fn check_usage_limit(
return Ok(());
}
let user_id = UserId::from_proto(claims.user_id);
let model = state.db.model(provider, model_name)?;
let usage = state
.db
.get_usage(
UserId::from_proto(claims.user_id),
provider,
model_name,
Utc::now(),
)
.get_usage(user_id, provider, model_name, Utc::now())
.await?;
let free_tier = claims.free_tier_monthly_spending_limit();
if usage.spending_this_month >= free_tier {
let spending_this_month = state
.db
.get_user_spending_for_month(user_id, Utc::now())
.await?;
if spending_this_month >= free_tier {
if !claims.has_llm_subscription {
return Err(Error::http(
StatusCode::PAYMENT_REQUIRED,