usage: a window's whole also at base rates, without long-context premiums (#5861, Norethcy on X)
A window's whole (WindowHolds) is priced at API list prices, which charge
GPT-6.1 Sol's input above 272K at a premium a subscription's own use
doesn't pay. A cycle with more long calls then reads as a larger
allowance: NorethSea's previous week came to $76.56, $53.52 without the
premium, against $56.99 for the current one.
Each priced call is now also costed at its model's base rates, the
long-context tiers left out and a peak hour's price kept (baseRates), and
the window's whole sent as BaseCost beside Cost, only when the two differ.
Past cycles get it too (HistoricalWindowHolds goes through windowHolds).
On the card the figure then says which it is ("≈ $76.56 API") and is a
button: a click switches every card, past cycles too, to the base figure
("≈ $53.52 base") and back, moves nothing, and is kept in the browser.
Its tooltip names both and says neither is an official dollar allowance
or a fixed quota. A window that paid no premium is drawn as before. The
ledger's and the API's real cost are unchanged. #4181 (auto-review calls
counted in the whole) is not part of this.
app.js and the core stay in their budgets with holdsLine's and holdsWhy's comments cut, no raise.
Run (mote's sshd reset every connection, so on the Linux box through
wsl-run; the package run at base 720200092, and the -run tests,
quota-holds and i18n-keys again at this head on 208b89422; rebased since onto 44732325e,
a gateway test only):
- go test -count=1 -tags nogui ./internal/gui ./internal/provider
./internal/sessions ./internal/usage ./internal/usageapi: ok (incl.
TestCoreScriptBudget)
- go vet -tags nogui (linux), GOOS=darwin CGO_ENABLED=0 go vet, go vet on
Windows (win-run): clean. gofmt -l: clean.
- GUI: quota-holds (new test: every language, 360 and 1000px), i18n-keys,
i18n-en-no-cjk, quota-fit-batched, provider-fetch-holds in chromium and
webkit: ok.
Broken by hand:
- baseRates keeping the tiers: TestWindowHoldsBaseCostLeavesOutLong-
ContextPremiums red (base figure 0).
- the click updating only its own button: quota-holds' new test red in
both engines ("the other card didn't switch").
Not tried: a macOS run (mote unreachable), the darwin gui package's vet,
and the reporter's own log; the test's prices are gpt-6.1-sol's shape.
This commit is contained in:
@@ -332,7 +332,15 @@ scope, and only calls and readings before that reading. A card that is gated
|
||||
live (a balance, a remote, an error) is gated for past cycles too, and a
|
||||
window no longer on the cached card is left out. Past prices aren't kept, so
|
||||
the cost is at today's API list prices. A call whose own id has no API price
|
||||
is costed as the model the reply named (Served), as the ledger is (#1498). See
|
||||
is costed as the model the reply named (Served), as the ledger is (#1498).
|
||||
Where a call was over a long-context tier's size, the whole is also told at
|
||||
the models' base rates, the tiers left out and a peak hour's price kept
|
||||
(`BaseCost`, `baseRates`, #5861, NorethSea): a plan's own use pays no such
|
||||
premium, so cycles whose calls' sizes differ compare on that figure. It is
|
||||
sent only when it differs from `Cost`; the card's figure is then a button that
|
||||
switches every card, past cycles too, between the two, kept in the browser
|
||||
(`holdsBase`, `quota-holds.test.cjs`,
|
||||
`TestWindowHoldsBaseCostLeavesOutLongContextPremiums`). See
|
||||
`TestWindowHoldsDryAgainAfterReset`, `TestWindowHoldsUsesObservedRefillStart`
|
||||
and `TestHistoricalWindowHoldsUsesEachWindowsOwnReading`.
|
||||
|
||||
|
||||
@@ -1049,6 +1049,7 @@ body.panel .row.pref.flash { border-radius: 10px; }
|
||||
/* a window's whole (WindowHolds): a line of its own under the reset */
|
||||
.quota-reset .quota-holds { flex-basis: 100%; display: flex; flex-wrap: wrap; column-gap: 4px; min-width: 0; }
|
||||
.quota-reset .quota-holds > span { white-space: normal; min-width: 0; }
|
||||
.quota-reset .quota-holds-cost { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline dotted; text-underline-offset: 2px; }
|
||||
.quota-reset .quota-holds-why { flex-basis: 100%; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }
|
||||
.quota-track { height: 4px; border-radius: 2px; background: var(--pill); overflow: hidden; }
|
||||
.quota-track i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
|
||||
|
||||
@@ -18594,19 +18594,39 @@ function familyQuota(sub) {
|
||||
return [box, b];
|
||||
}
|
||||
|
||||
// holdsLine: a window's whole, reckoned from the calls magpie routed
|
||||
// through the account since it began over the share used (WindowHolds),
|
||||
// and in its tooltip how, and why it reads low if the account is used
|
||||
// elsewhere too.
|
||||
// holdsLine: a window's whole (WindowHolds), how in its tooltip. With a
|
||||
// baseCost (#5861, no long-context premium) its figure switches every card.
|
||||
let holdsBase = kept("holdsBase", false);
|
||||
function holdsCostText(h) {
|
||||
const c = fmtCost({ cost: holdsBase ? h.baseCost : h.cost });
|
||||
return holdsBase ? t("≈ {cost} base", { cost: c }) : t("≈ {cost} API", { cost: c });
|
||||
}
|
||||
function holdsLine(h) {
|
||||
const cost = (c) => fmtCost({ cost: c });
|
||||
const line = el("span", "quota-holds");
|
||||
line.append(el("span", "", t("Whole ≈ {n} tokens", { n: fmtN(h.tokens) }) + (h.priced ? " ·" : "")));
|
||||
if (h.priced) line.append(" ", el("span", "", "≈ " + cost(h.cost)));
|
||||
const two = h.priced && h.baseCost > 0;
|
||||
if (two) {
|
||||
const b = el("button", "quota-holds-cost", holdsCostText(h));
|
||||
b.type = "button";
|
||||
b._holds = h;
|
||||
b.onclick = (e) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
holdsBase = !holdsBase;
|
||||
keep("holdsBase", holdsBase);
|
||||
for (const o of document.querySelectorAll(".quota-holds-cost")) if (o._holds) o.textContent = holdsCostText(o._holds);
|
||||
};
|
||||
line.append(" ", b);
|
||||
} else if (h.priced) line.append(" ", el("span", "", "≈ " + cost(h.cost)));
|
||||
const r = h.routed || {};
|
||||
line.title = [
|
||||
h.priced ? t("The whole window ≈ {tokens} tokens of input and output, ≈ {cost} at API list prices", { tokens: fmtN(h.tokens), cost: cost(h.cost) })
|
||||
: t("The whole window ≈ {tokens} tokens of input and output; some of its models have no API price", { tokens: fmtN(h.tokens) }),
|
||||
...(two ? [
|
||||
t("≈ {cost} at base rates, without long-context premiums: for comparing cycles", { cost: cost(h.baseCost) }),
|
||||
t("Neither is an official dollar allowance or a fixed quota; click the figure to switch"),
|
||||
] : []),
|
||||
t("Reckoned from what magpie routed through this account in this window: {tokens} tokens in {calls} calls, {cache} cache reads, over the {used} the vendor says is used", { tokens: fmtN(r.tokens || 0), calls: r.calls || 0, cache: fmtN(r.cacheRead || 0), used: Math.round(h.used) + "%" }),
|
||||
t("Only magpie's calls are counted: if this account is also used elsewhere, this reads low"),
|
||||
t("A heavier model fills a window sooner: this holds for the models used so far"),
|
||||
@@ -18614,8 +18634,7 @@ function holdsLine(h) {
|
||||
return line;
|
||||
}
|
||||
|
||||
// holdsWhy: why a window's whole isn't told (provider.Holds*), for
|
||||
// holdsUnknownLine's tooltip; a reason not listed here says nothing.
|
||||
// holdsWhy: why a whole isn't told (provider.Holds*); one not listed says nothing.
|
||||
const holdsWhy = {
|
||||
low: () => t("Under {n}% of it is used: a rounded share that small is too coarse to scale up", { n: 5 }),
|
||||
clock: () => t("Its reset time isn't known, so neither is when it began"),
|
||||
|
||||
@@ -3339,6 +3339,10 @@ const I18N = {
|
||||
"A call in it may have been paid from credits or extra usage, not from the window": "其中有调用可能是用积分或额外用量付的,不是这个窗口的额度",
|
||||
"Estimated from the window that began {start}, read {at}": "按开始于 {start} 的窗口估算,采样于 {at}",
|
||||
"The whole window ≈ {tokens} tokens of input and output, ≈ {cost} at API list prices": "整个窗口 ≈ {tokens} tokens(输入加输出),按 API 标价 ≈ {cost}",
|
||||
"≈ {cost} base": "≈ {cost}(基础价)",
|
||||
"≈ {cost} API": "≈ {cost}(API 价)",
|
||||
"≈ {cost} at base rates, without long-context premiums: for comparing cycles": "按基础价(不含长上下文加价)≈ {cost}:用于对比不同周期",
|
||||
"Neither is an official dollar allowance or a fixed quota; click the figure to switch": "两者都不是官方美元额度或固定配额;点金额可切换",
|
||||
"The whole window ≈ {tokens} tokens of input and output; some of its models have no API price": "整个窗口 ≈ {tokens} tokens(输入加输出);其中有模型没有 API 标价",
|
||||
"Reckoned from what magpie routed through this account in this window: {tokens} tokens in {calls} calls, {cache} cache reads, over the {used} the vendor says is used": "按 magpie 在这个窗口里经手这个账号的用量推算:{calls} 次调用 {tokens} tokens,缓存读取 {cache},除以服务商给出的已用 {used}",
|
||||
"Only magpie's calls are counted: if this account is also used elsewhere, this reads low": "只算 magpie 经手的调用:这个账号在别处也用过时,这个数会偏低",
|
||||
@@ -8232,6 +8236,10 @@ const I18N = {
|
||||
"A call in it may have been paid from credits or extra usage, not from the window": "其中有呼叫可能是用積分或額外用量付的,不是這個視窗的額度",
|
||||
"Estimated from the window that began {start}, read {at}": "依開始於 {start} 的視窗估算,取樣於 {at}",
|
||||
"The whole window ≈ {tokens} tokens of input and output, ≈ {cost} at API list prices": "整個視窗 ≈ {tokens} tokens(輸入加輸出),按 API 標價 ≈ {cost}",
|
||||
"≈ {cost} base": "≈ {cost}(基礎價)",
|
||||
"≈ {cost} API": "≈ {cost}(API 價)",
|
||||
"≈ {cost} at base rates, without long-context premiums: for comparing cycles": "按基礎價(不含長上下文加價)≈ {cost}:用於比較不同週期",
|
||||
"Neither is an official dollar allowance or a fixed quota; click the figure to switch": "兩者都不是官方美元額度或固定配額;點金額可切換",
|
||||
"The whole window ≈ {tokens} tokens of input and output; some of its models have no API price": "整個視窗 ≈ {tokens} tokens(輸入加輸出);其中有模型沒有 API 標價",
|
||||
"Reckoned from what magpie routed through this account in this window: {tokens} tokens in {calls} calls, {cache} cache reads, over the {used} the vendor says is used": "按 magpie 在這個視窗裡經手這個帳號的用量推算:{calls} 次呼叫 {tokens} tokens,快取讀取 {cache},除以服務商給出的已用 {used}",
|
||||
"Only magpie's calls are counted: if this account is also used elsewhere, this reads low": "只算 magpie 經手的呼叫:這個帳號在別處也用過時,這個數會偏低",
|
||||
@@ -13124,6 +13132,10 @@ const I18N = {
|
||||
"A call in it may have been paid from credits or extra usage, not from the window": "この枠の呼び出しの一部は、枠ではなくクレジットや追加使用量で支払われた可能性があります",
|
||||
"Estimated from the window that began {start}, read {at}": "開始 {start}、記録 {at} の枠から推定",
|
||||
"The whole window ≈ {tokens} tokens of input and output, ≈ {cost} at API list prices": "枠全体 ≈ {tokens} トークン(入力と出力)、API 定価で ≈ {cost}",
|
||||
"≈ {cost} base": "≈ {cost}(基本料金)",
|
||||
"≈ {cost} API": "≈ {cost}(API 料金)",
|
||||
"≈ {cost} at base rates, without long-context premiums: for comparing cycles": "基本料金(長コンテキストの割増なし)で ≈ {cost}:サイクルの比較用",
|
||||
"Neither is an official dollar allowance or a fixed quota; click the figure to switch": "どちらも公式のドル枠や固定のクォータではありません。金額をクリックで切り替え",
|
||||
"The whole window ≈ {tokens} tokens of input and output; some of its models have no API price": "枠全体 ≈ {tokens} トークン(入力と出力)。API 価格のないモデルが含まれます",
|
||||
"Reckoned from what magpie routed through this account in this window: {tokens} tokens in {calls} calls, {cache} cache reads, over the {used} the vendor says is used": "この枠で magpie がこのアカウント経由で送った分から推算:{calls} 回の呼び出しで {tokens} トークン、キャッシュ読み取り {cache}、それをベンダーの示す使用率 {used} で割った値",
|
||||
"Only magpie's calls are counted: if this account is also used elsewhere, this reads low": "magpie 経由の呼び出しだけを数えます。このアカウントを他でも使っていると、この値は低めに出ます",
|
||||
@@ -18027,6 +18039,10 @@ const I18N = {
|
||||
"A call in it may have been paid from credits or extra usage, not from the window": "Ein Aufruf darin wurde vielleicht aus Guthaben oder zusätzlicher Nutzung bezahlt, nicht aus dem Fenster",
|
||||
"Estimated from the window that began {start}, read {at}": "Geschätzt aus dem am {start} begonnenen Fenster, gemessen am {at}",
|
||||
"The whole window ≈ {tokens} tokens of input and output, ≈ {cost} at API list prices": "Das ganze Fenster ≈ {tokens} Tokens Ein- und Ausgabe, ≈ {cost} zu API-Listenpreisen",
|
||||
"≈ {cost} base": "≈ {cost} (Basispreis)",
|
||||
"≈ {cost} API": "≈ {cost} (API-Preis)",
|
||||
"≈ {cost} at base rates, without long-context premiums: for comparing cycles": "≈ {cost} zu Basispreisen, ohne Langkontext-Aufschläge: zum Vergleich von Zyklen",
|
||||
"Neither is an official dollar allowance or a fixed quota; click the figure to switch": "Keiner der Werte ist ein offizielles Dollar-Kontingent oder eine feste Quote; Betrag anklicken zum Wechseln",
|
||||
"The whole window ≈ {tokens} tokens of input and output; some of its models have no API price": "Das ganze Fenster ≈ {tokens} Tokens Ein- und Ausgabe; einige seiner Modelle haben keinen API-Preis",
|
||||
"Reckoned from what magpie routed through this account in this window: {tokens} tokens in {calls} calls, {cache} cache reads, over the {used} the vendor says is used": "Hochgerechnet aus dem, was magpie in diesem Fenster über dieses Konto geleitet hat: {tokens} Tokens in {calls} Aufrufen, {cache} Cache-Lesezugriffe, geteilt durch die {used}, die der Anbieter als verbraucht meldet",
|
||||
"Only magpie's calls are counted: if this account is also used elsewhere, this reads low": "Nur Aufrufe über magpie werden gezählt: wird dieses Konto auch anderswo genutzt, fällt der Wert zu niedrig aus",
|
||||
|
||||
@@ -29,7 +29,7 @@ const quotas = [
|
||||
{ name: "Credits", used: 30, holdsWhy: "clock" },
|
||||
] },
|
||||
];
|
||||
function serve(lang) {
|
||||
function serve(lang, cards = quotas) {
|
||||
const settings = { lang, theme: "light", currency: "usd", chineseUnits: lang.startsWith("zh") };
|
||||
const state = { agents: [], profiles: [], settings };
|
||||
return async (r) => {
|
||||
@@ -43,7 +43,7 @@ function serve(lang) {
|
||||
if (url.pathname === "/api/gateway/history") return json({ cut: false, days: [], routes: [] });
|
||||
if (url.pathname === "/api/groups") return json({ models: [], groups: [], pools: [] });
|
||||
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
||||
if (url.pathname === "/api/usage/quotas") return json(quotas);
|
||||
if (url.pathname === "/api/usage/quotas") return json(cards);
|
||||
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
||||
if (url.pathname.startsWith("/api/")) return json({});
|
||||
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
||||
@@ -137,3 +137,77 @@ for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
}
|
||||
|
||||
// NorethSea (#5861): where a call paid the API's long-context premium, the
|
||||
// server also sends the whole at base rates (baseCost). The figure is then a
|
||||
// button, which says it is the API's: a click switches every card's figure
|
||||
// to the base one and back,
|
||||
// moves nothing, and is kept for the next load; the tooltip names both. A
|
||||
// window with no baseCost keeps one plain figure.
|
||||
const premium = (tokens, cost, base, used) => ({ ...holds(tokens, cost, used), baseCost: base });
|
||||
const baseCards = [
|
||||
{ provider: "codex", name: "Codex", icon: "openai", plan: "pro", user: "sam@example.com", windows: [
|
||||
{ name: "5 hours", used: 20, resetsAt: soon(2), holds: holds(12345678, 85.4321, 20) },
|
||||
{ name: "7 days", used: 40, resetsAt: soon(70), holds: premium(234567890, 1234.5, 777.25, 40) },
|
||||
] },
|
||||
{ provider: "claude", name: "Claude Code", icon: "claude-color", plan: "max", user: "kit@example.com", windows: [
|
||||
{ name: "7 days", used: 50, resetsAt: soon(30), holds: premium(34567890, 312.5, 210.75, 50) },
|
||||
] },
|
||||
];
|
||||
const base = { en: " base", zh: "(基础价)", "zh-TW": "(基礎價)", ja: "(基本料金)", de: " (Basispreis)" };
|
||||
// and the API figure says it is one, beside the other
|
||||
const api = { en: " API", zh: "(API 价)", "zh-TW": "(API 價)", ja: "(API 料金)", de: " (API-Preis)" };
|
||||
|
||||
for (const [name, engine] of [["webkit", webkit], ["chromium", chromium]]) {
|
||||
test(`${name}: a whole that paid long-context premiums switches to its base-rate figure on every card, in every language`, async () => {
|
||||
const browser = await engine.launch();
|
||||
try {
|
||||
for (const lang of Object.keys(base)) {
|
||||
for (const width of [360, 1000]) {
|
||||
const context = await browser.newContext({ viewport: { width, height: 900 }, reducedMotion: "reduce" });
|
||||
const page = await context.newPage();
|
||||
page.setDefaultTimeout(5000);
|
||||
page.setDefaultNavigationTimeout(60000);
|
||||
await page.route("**/*", serve(lang, baseCards));
|
||||
await page.goto("http://magpie.test/?view=usage");
|
||||
await page.locator(".quota-holds-cost").nth(1).waitFor();
|
||||
const read = () => page.evaluate(() => [...document.querySelectorAll(".quota-holds")].map((l) => {
|
||||
const card = l.closest(".subscription-card").getBoundingClientRect(), b = l.getBoundingClientRect();
|
||||
return { text: l.textContent, title: l.title, button: l.querySelector("button")?.textContent ?? null,
|
||||
inCard: b.left >= card.left - 1 && b.right <= card.right + 1 };
|
||||
}));
|
||||
const at = `${lang} ${width}px`;
|
||||
let got = await read();
|
||||
assert.equal(got.length, 3, at);
|
||||
const [plain, week, kit] = got;
|
||||
// no premium paid: one plain figure, the tooltip as it was
|
||||
assert.equal(plain.button, null, at);
|
||||
assert.equal(plain.title.split("\n").length, 4, at);
|
||||
assert.equal(week.button, "≈ $1235" + api[lang], at);
|
||||
assert.equal(kit.button, "≈ $313" + api[lang], at);
|
||||
for (const l of [week, kit]) {
|
||||
assert.equal(l.title.split("\n").length, 6, `${at}: ${l.title}`);
|
||||
assert.ok(l.inCard, `${at}: ${l.text}`);
|
||||
}
|
||||
assert.ok(week.title.includes("$1235") && week.title.includes("$777"), `${at}: ${week.title}`);
|
||||
const before = await page.evaluate(() => [scrollY, document.querySelector("#view-usage")?.scrollTop]);
|
||||
await page.locator(".quota-holds-cost").first().click();
|
||||
got = await read();
|
||||
assert.ok(got[1].button.startsWith("≈ $777") && got[1].button.endsWith(base[lang]), `${at}: ${got[1].button}`);
|
||||
assert.ok(got[2].button.startsWith("≈ $211") && got[2].button.endsWith(base[lang]), `${at}: the other card didn't switch: ${got[2].button}`);
|
||||
assert.equal(got[0].text, plain.text, at);
|
||||
for (const l of got) assert.ok(l.inCard, `${at}: ${l.text}`);
|
||||
assert.deepEqual(await page.evaluate(() => [scrollY, document.querySelector("#view-usage")?.scrollTop]), before, at);
|
||||
// kept for the next load, and switched back
|
||||
await page.reload();
|
||||
await page.locator(".quota-holds-cost").nth(1).waitFor();
|
||||
assert.ok((await read())[2].button.endsWith(base[lang]), `${at}: not kept`);
|
||||
await page.locator(".quota-holds-cost").nth(1).click();
|
||||
got = await read();
|
||||
assert.deepEqual([got[1].button, got[2].button], [week.button, kit.button], at);
|
||||
await context.close();
|
||||
}
|
||||
}
|
||||
} finally { await browser.close(); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,17 +20,25 @@ import (
|
||||
// up to when the share was read, and Used that share. A call made with the
|
||||
// account outside magpie is in Used but not in Routed, so the estimate is
|
||||
// then lower than the window really holds.
|
||||
//
|
||||
// BaseCost is Cost with every call at its model's base rates, no API
|
||||
// long-context premium (catalog.Price.Tiers) (#5861, NorethSea): a plan's
|
||||
// own use has none (OpenAI bills no long-context surcharge in Codex), so
|
||||
// two cycles whose calls' sizes differ compare by it. It is there only
|
||||
// when some call was over a tier's size, else it is Cost.
|
||||
type WindowHolds struct {
|
||||
Tokens int64 `json:"tokens"`
|
||||
Cost float64 `json:"cost,omitempty"`
|
||||
Priced bool `json:"priced"`
|
||||
Used float64 `json:"used"`
|
||||
Routed struct {
|
||||
Tokens int64 `json:"tokens"`
|
||||
Cost float64 `json:"cost,omitempty"`
|
||||
BaseCost float64 `json:"baseCost,omitempty"`
|
||||
Priced bool `json:"priced"`
|
||||
Used float64 `json:"used"`
|
||||
Routed struct {
|
||||
Calls int `json:"calls"`
|
||||
Tokens int64 `json:"tokens"`
|
||||
CacheRead int64 `json:"cacheRead,omitempty"`
|
||||
CacheWrite int64 `json:"cacheWrite,omitempty"`
|
||||
Cost float64 `json:"cost,omitempty"`
|
||||
BaseCost float64 `json:"baseCost,omitempty"`
|
||||
} `json:"routed"`
|
||||
Since time.Time `json:"since"`
|
||||
}
|
||||
|
||||
@@ -267,6 +267,7 @@ func windowHolds(qs []provider.SubscriptionQuota, now, first time.Time, priceOf
|
||||
h.Routed.CacheWrite += int64(r.CacheWrite)
|
||||
if pr := priceOf(r); pr != nil {
|
||||
h.Routed.Cost += r.CostAt(*pr)
|
||||
h.Routed.BaseCost += r.CostAt(baseRates(*pr))
|
||||
} else {
|
||||
unpriced[s] = true
|
||||
}
|
||||
@@ -305,12 +306,29 @@ func windowHolds(qs []provider.SubscriptionQuota, now, first time.Time, priceOf
|
||||
if !unpriced[s] && h.Routed.Cost > 0 {
|
||||
h.Priced = true
|
||||
h.Cost = h.Routed.Cost * scale
|
||||
// told only where a premium was paid: the same figure twice
|
||||
// would ask the reader to tell them apart for nothing
|
||||
if math.Abs(h.Routed.Cost-h.Routed.BaseCost) > 1e-9 {
|
||||
h.BaseCost = h.Routed.BaseCost * scale
|
||||
} else {
|
||||
h.Routed.BaseCost = 0
|
||||
}
|
||||
} else {
|
||||
h.Routed.BaseCost = 0
|
||||
}
|
||||
w.Holds = h
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// baseRates is pr without its long-context tiers: every call at the base
|
||||
// rates however large its input (WindowHolds.BaseCost, #5861). A peak
|
||||
// hour's price is kept, as that is what the vendor's base rate is then.
|
||||
func baseRates(pr catalog.Price) catalog.Price {
|
||||
pr.Tiers = nil
|
||||
return pr
|
||||
}
|
||||
|
||||
// apiPricer is each call's model at its API list price: its maker's, else
|
||||
// the provider's own list, else the maker's of the model the user said it
|
||||
// is the same as (provider.SamePriceIn), never a price the user set for the
|
||||
|
||||
@@ -570,3 +570,53 @@ func TestWindowHoldsLeavesAWalletOut(t *testing.T) {
|
||||
t.Fatalf("a wallet reckoned a whole: %+v, why %q", w.Holds, w.HoldsWhy)
|
||||
}
|
||||
}
|
||||
|
||||
// NorethSea (#5861): a window's whole is also told at the models' base
|
||||
// rates, without the API's long-context premium, which a plan's own use
|
||||
// doesn't pay, so two cycles whose calls' sizes differ compare. It is told
|
||||
// only where a call was over a tier's size; the API figure is as before.
|
||||
func TestWindowHoldsBaseCostLeavesOutLongContextPremiums(t *testing.T) {
|
||||
now := time.Date(2026, 11, 10, 12, 0, 0, 0, time.UTC)
|
||||
reset := now.Add(3 * 24 * time.Hour)
|
||||
week := func() []provider.SubscriptionQuota {
|
||||
return []provider.SubscriptionQuota{{Provider: "codex", User: "sam@example.com", Windows: []provider.QuotaWindow{
|
||||
{Name: "7 days", Used: 10, ResetsAt: &reset, Span: 7 * 24 * time.Hour}}}}
|
||||
}
|
||||
// gpt-6.1-sol's shape: 2× input and cache, 1.5× output above 272K
|
||||
price := catalog.Price{Input: 5, Output: 30, CacheRead: 0.5, Tiers: []catalog.Tier{{Above: 272000, Input: 10, Output: 45, CacheRead: 1}}}
|
||||
priceOf := func(Record) *catalog.Price { return &price }
|
||||
call := func(in, out, read int) Record {
|
||||
return Record{Time: now.Add(-time.Hour), Provider: "codex", ProviderAccount: "sam@example.com", Model: "gpt-6.1-sol", Input: in, Output: out, CacheRead: read, Status: 200}
|
||||
}
|
||||
reads := func(recs ...Record) func(func(Record)) {
|
||||
return func(fn func(Record)) {
|
||||
for _, r := range recs {
|
||||
fn(r)
|
||||
}
|
||||
}
|
||||
}
|
||||
small, large := call(10000, 2000, 100000), call(50000, 4000, 250000) // the second is 300K in
|
||||
smallBase := (10000*5 + 2000*30 + 100000*0.5) / 1e6
|
||||
largeAPI, largeBase := (50000*10+4000*45+250000*1.0)/1e6, (50000*5+4000*30+250000*0.5)/1e6
|
||||
|
||||
h := windowHolds(week(), now, now.Add(-30*24*time.Hour), priceOf, provider.Renames{}, nil, nil, reads(small, large))[0].Windows[0].Holds
|
||||
if h == nil || !h.Priced {
|
||||
t.Fatalf("not reckoned: %+v", h)
|
||||
}
|
||||
if !near(h.Cost, (smallBase+largeAPI)*10) {
|
||||
t.Errorf("API figure %v, want %v: the premium stays in it", h.Cost, (smallBase+largeAPI)*10)
|
||||
}
|
||||
if !near(h.BaseCost, (smallBase+largeBase)*10) || !near(h.Routed.BaseCost, smallBase+largeBase) {
|
||||
t.Errorf("base figure %v (routed %v), want %v", h.BaseCost, h.Routed.BaseCost, (smallBase+largeBase)*10)
|
||||
}
|
||||
// no call over 272K: one figure, told once
|
||||
h = windowHolds(week(), now, now.Add(-30*24*time.Hour), priceOf, provider.Renames{}, nil, nil, reads(small))[0].Windows[0].Holds
|
||||
if h == nil || !near(h.Cost, smallBase*10) || h.BaseCost != 0 || h.Routed.BaseCost != 0 {
|
||||
t.Errorf("no premium paid, and a base figure told apart: %+v", h)
|
||||
}
|
||||
// a model with no API price: neither figure
|
||||
h = windowHolds(week(), now, now.Add(-30*24*time.Hour), func(Record) *catalog.Price { return nil }, provider.Renames{}, nil, nil, reads(large))[0].Windows[0].Holds
|
||||
if h == nil || h.Priced || h.Cost != 0 || h.BaseCost != 0 {
|
||||
t.Errorf("unpriced, and a figure told: %+v", h)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user