Skip to content

feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas - #14799

Open
fouadSalkini wants to merge 7 commits into
diegosouzapw:release/v3.8.52from
fouadSalkini:fix/usage-limit-ignore-unpriced
Open

fouadSalkini wants to merge 7 commits into
diegosouzapw:release/v3.8.52from
fouadSalkini:fix/usage-limit-ignore-unpriced

Conversation

@fouadSalkini

@fouadSalkini fouadSalkini commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

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 as exceeded and 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: true in both windows, because it had used antigravity/gemini-3.8-flash-tiered (1,925 requests), antigravity/claude-sonnet-4-6, antigravity/gemini-pro-agent, a kilocode/*:free model 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, default false, no restart; DB override > env > default).
  • When on, unpriced usage counts as $0 and no longer forces dailyExceeded / weeklyExceeded. Priced spend is still enforced against the limit.
  • dailyHasUnpricedUsage / weeklyHasUnpricedUsage keep 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: new policies flag (warningLevel: "caution").
  • featureFlagUsageLimitIgnoreUnpricedDescription added to en.json and 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.
  • tests/unit/feature-flags-settings.test.ts: expected flag count 78 → 79.
  • Related suites (fix(backend): API-key budget enforcement can compute $0 for routing alias auto #12341, feature flags, i18n feature-flag, API key policy, usage-limit tests): 122/122 pass.
  • npm run typecheck:core, ESLint (with suppressions), Prettier, check:cycles: clean.
  • i18n: check-ui-keys-coverage, check-translation-ratio, check-ui-value-drift, check-new-key-coverage, zh-CN glossary: pass. check-key-completeness fails only on bs missing 16 combos.* keys, which is inherited from the base.

⚠️ base-red inherited: #14866

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.
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @fouadSalkini — small, safe (default off) and well tested. One thing before merge: docs/reference/FEATURE_FLAGS.md still says 78 flags / "Policies (5)" and doesn't list USAGE_LIMIT_IGNORE_UNPRICED; please add the row and bump the counts, then run npm run check:docs-all.

@diegosouzapw diegosouzapw changed the title feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas [defer] feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas Sep 25, 2026
@diegosouzapw diegosouzapw added the deferred-v3.8.52 Grande demais / suspeito para o lote atual; precisa de sessão dedicada no ciclo v3.8.52 label Sep 25, 2026
@fouadSalkini

Copy link
Copy Markdown
Contributor Author

Added USAGE_LIMIT_IGNORE_UNPRICED to docs/reference/FEATURE_FLAGS.md under Policies, bumped the category count to 6 and total count to 79 flags, and updated the changelog fragment with the PR link.

@fouadSalkini

Copy link
Copy Markdown
Contributor Author

Merged the latest release/v3.8.51 to clear the conflicts in docs/reference/FEATURE_FLAGS.md and tests/unit/feature-flags-settings.test.ts. Counts are re-derived from featureFlagDefinitions.ts: 81 flags, Policies (6); the base's new rows and assertions are kept. feature-flags-settings passes 63/63 and api-key-budget-alias-auto-12341 4/4. The remaining check:docs-counts failure is the inherited base-red #14866.

fouadSalkini added a commit to fouadSalkini/OmniRoute that referenced this pull request Sep 26, 2026
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.
fouadSalkini added a commit to fouadSalkini/OmniRoute that referenced this pull request Sep 26, 2026
fouadSalkini added a commit to fouadSalkini/OmniRoute that referenced this pull request Sep 26, 2026
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).
@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.51 to release/v3.8.52 September 29, 2026 11:20
@diegosouzapw

Copy link
Copy Markdown
Owner

Re-homed to release/v3.8.52: v3.8.51 entered its release freeze, so the branch now belongs to the release captain and development continues on the next cycle. Nothing is wrong with this PR — it just needed a live base. No action needed from you; CI will re-run against the new base.

fouadSalkini added a commit to fouadSalkini/OmniRoute that referenced this pull request Sep 30, 2026
…p flag test

diegosouzapw#14799 and diegosouzapw#14864 each add one flag; this second hard-coded registry count
was still at the upstream 80.
@diegosouzapw diegosouzapw changed the title [defer] feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas feat(api-keys): opt-in flag to count unpriced usage as $0 in per-key USD quotas Oct 1, 2026
@diegosouzapw diegosouzapw removed the deferred-v3.8.52 Grande demais / suspeito para o lote atual; precisa de sessão dedicada no ciclo v3.8.52 label Oct 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants