fix(quota/openrouter): suppress usedFraction since SF policy is :free-only
OpenRouter's credit-balance (total_usage / total_credits) was being
used as a quota signal in phase 2's quotaHeadroomMultiplier, demoting
openrouter once credits got high (e.g., 80% used → 0.5 multiplier).
But SF's built-in policy (preferences-models.js:123-131
isModelAllowedByBuiltInProviderPolicy) hard-restricts every OpenRouter
route to `:free` + zero-cost models for ALL SF users — there's no
opt-in, no way to bypass it. Therefore SF dispatches NEVER consume
OpenRouter credits, and the credit balance is purely historical noise.
Fix: stop emitting `usedFraction` for OpenRouter's credit window. The
window is still reported (so `sf headless usage` shows credits state
for awareness) but quotaHeadroomMultiplier now treats OpenRouter as
"no quota signal" → neutral 1.0 — no spurious demotion.
Affects only the routing layer (selector). Display layer unchanged
beyond the label tweak ("info only — SF routes :free").
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
f7cd01df0a
commit
7217a24c28
1 changed files with 16 additions and 7 deletions
|
|
@ -142,7 +142,18 @@ async function fetchKimiCodingQuota(apiKey) {
|
|||
/**
|
||||
* OpenRouter — GET https://openrouter.ai/api/v1/credits with Bearer auth.
|
||||
* Returns { data: { total_credits, total_usage } } where both are USD floats.
|
||||
* Used relative to the user's purchased credits, not a rolling window.
|
||||
*
|
||||
* Important: SF's built-in policy (preferences-models.js:123-131
|
||||
* isModelAllowedByBuiltInProviderPolicy) restricts OpenRouter routes to
|
||||
* `:free` + zero-cost models for ALL SF users, no opt-in needed. Routing
|
||||
* through SF therefore never consumes credits — the credits balance is
|
||||
* historical noise, not a signal for the quota-aware router.
|
||||
*
|
||||
* The window IS reported (so `sf headless usage` can display credits state
|
||||
* for user awareness) but `usedFraction` is deliberately left undefined so
|
||||
* benchmark-selector's quotaHeadroomMultiplier treats OpenRouter as "no
|
||||
* quota signal" (neutral 1.0) rather than incorrectly demoting at the
|
||||
* credits high-water mark.
|
||||
*/
|
||||
async function fetchOpenrouterQuota(apiKey) {
|
||||
const res = await fetch("https://openrouter.ai/api/v1/credits", {
|
||||
|
|
@ -157,14 +168,12 @@ async function fetchOpenrouterQuota(apiKey) {
|
|||
return {
|
||||
windows: [
|
||||
{
|
||||
label: "credits (USD)",
|
||||
label: "credits (USD, info only — SF routes :free)",
|
||||
used: totalUsage,
|
||||
limit: totalCredits || totalUsage, // avoid divide-by-zero
|
||||
usedFraction:
|
||||
totalCredits > 0
|
||||
? clampFraction(totalUsage, totalCredits)
|
||||
: undefined,
|
||||
resetHint: remaining >= 0 ? `${remaining.toFixed(2)} USD remaining` : undefined,
|
||||
// usedFraction intentionally omitted; see comment above.
|
||||
resetHint:
|
||||
remaining >= 0 ? `${remaining.toFixed(2)} USD remaining` : undefined,
|
||||
},
|
||||
],
|
||||
raw: payload,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue