fix(quotas): list unpriced models by recorded cost; integer token limits in status

The unpriced-model notice asked the live registry whether a model has a
price, so a priced model whose provider was later disabled showed up as
unpriced. It now lists models whose calls this period were all recorded at
$0. Token limits are serialized as integers.
This commit is contained in:
Alex committed 2026-09-21 12:14:14 +01:00
1 parent 1eacfdd3d0
commit 6db9014dfb
4 files changed
+21 -15

No files matched your search

+5 -3
View File
@@ -151,13 +151,15 @@ def _delete_policy(scope: str, subject_id: Optional[str]):
def _unpriced_models(conn) -> list[dict]:
"""Catalog models used this period that no cost limit can see."""
"""Models used this period whose calls were all recorded at $0 for want of a price."""
start, _ = window_bounds(settings.QUOTA_PERIOD)
return [
row
for row in TokenUsageRepository(conn).tokens_by_model(start=start)
# BYOM ids are UUIDs; those calls are $0 by design, not by omission.
if not looks_like_uuid(row["model_id"]) and not is_priced(row["model_id"])
# Judged by what was recorded, so a priced model whose provider has since
# been disabled is not listed. BYOM ids are UUIDs and $0 by design; a
# model explicitly priced at $0 is free, not unpriced.
if row["cost"] == 0 and not looks_like_uuid(row["model_id"]) and not is_priced(row["model_id"])
]
+7 -6
View File
@@ -43,18 +43,19 @@ class BucketStatus:
def to_dict(self) -> dict:
"""Return the JSON shape shared by the admin and user quota endpoints."""
def budget(limit: ResolvedLimit, used: float) -> dict:
def budget(limit: Optional[float], resolved: ResolvedLimit, used: float) -> dict:
return {
"limit": limit.limit,
"limit": limit,
"used": used,
"source": limit.source,
"source_id": limit.source_id,
"source": resolved.source,
"source_id": resolved.source_id,
}
tokens, cost = self.limits.tokens, self.limits.cost
return {
"bucket": self.bucket,
"tokens": budget(self.limits.tokens, self.tokens_used),
"cost": budget(self.limits.cost, round(self.cost_used, 6)),
"tokens": budget(None if tokens.unlimited else int(tokens.limit), tokens, self.tokens_used),
"cost": budget(cost.limit, cost, round(self.cost_used, 6)),
"resets_at": self.resets_at.isoformat(),
}