feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas - #14799
fouadSalkini wants to merge 7 commits into
Conversation
Per-key USD usage quotas fail closed on usage whose provider/model has no pricing row (diegosouzapw#12341): the window reads as exceeded and the key is blocked, even when priced spend is far below the limit. Operators who route through subscription or free models without pricing rows had no way out short of pricing every model. USAGE_LIMIT_IGNORE_UNPRICED (Settings -> Feature flags, default off) makes unpriced usage count as $0 instead. Priced spend is still enforced, and dailyHasUnpricedUsage / weeklyHasUnpricedUsage keep reporting unpriced usage. The default keeps the fail-closed behavior.
|
Thanks @fouadSalkini — small, safe (default off) and well tested. One thing before merge: |
…limit-ignore-unpriced # Conflicts: # src/lib/usage/apiKeyUsageLimits.ts
|
Added |
|
Merged the latest |
Adds the opt-in flag that counts unpriced usage as $0 in per-key USD quotas. featureFlagDefinitions.ts also holds the diegosouzapw#14864 flag definition, which stays inert until the agent sessions commit wires it.
…iegosouzapw#14860, diegosouzapw#14863 and diegosouzapw#14864 Locale files as deployed, covering all locales.
Registers USAGE_LIMIT_IGNORE_UNPRICED in the feature-flag registry (policies, boolean, default off), as in the final diegosouzapw#14799 head, so the dashboard shows the toggle; enforcement already read the flag. FEATURE_FLAGS.md gets the row, and the registry count test now matches this base (80 flags).
|
Re-homed to |
…p flag test diegosouzapw#14799 and diegosouzapw#14864 each add one flag; this second hard-coded registry count was still at the upstream 80.
Summary
Per-key USD usage quotas (
usageLimitEnabled+ daily/weekly USD) fail closed on unpriced usage (#12341). If any successful request in the window used a provider/model that has no pricing row, the window reads asexceededand the key is rejected, whatever the priced spend. That is the right default when an unpriced routing alias (e.g.cursor/auto) can hide real cost.It becomes a hard blocker for operators who route through subscription or free models that nobody prices. On one production node, a key at 7.5 % of its daily limit and 3.8 % of its weekly limit reported
exceeded: truein both windows, because it had usedantigravity/gemini-3.8-flash-tiered(1,925 requests),antigravity/claude-sonnet-4-6,antigravity/gemini-pro-agent, akilocode/*:freemodel and a few others without pricing rows. The only workaround today is to hand-price every such model.This adds an opt-in feature flag:
USAGE_LIMIT_IGNORE_UNPRICED(Settings → Feature flags → Policies, defaultfalse, no restart; DB override > env > default).dailyExceeded/weeklyExceeded. Priced spend is still enforced against the limit.dailyHasUnpricedUsage/weeklyHasUnpricedUsagekeep reporting that unpriced usage was seen, and the server warning still names each unpriced provider/model.With the flag off, behavior is unchanged.
Changes
src/lib/usage/apiKeyUsageLimits.ts: the fail-closed override is gated on the flag; the warning text mentions the flag.src/shared/constants/featureFlagDefinitions.ts: newpoliciesflag (warningLevel: "caution").featureFlagUsageLimitIgnoreUnpricedDescriptionadded toen.jsonand translated into all 66 locales (one added line per file).changelog.d/features/usage-limit-ignore-unpriced.md.Tests
tests/unit/api-key-budget-alias-auto-12341.test.ts: two new cases.exceededbut is still reported. This case fails against the previous code and passes with the change.exceeded.tests/unit/feature-flags-settings.test.ts: expected flag count 78 → 79.npm run typecheck:core, ESLint (with suppressions), Prettier,check:cycles: clean.check-ui-keys-coverage,check-translation-ratio,check-ui-value-drift,check-new-key-coverage, zh-CN glossary: pass.check-key-completenessfails only onbsmissing 16combos.*keys, which is inherited from the base.