fix(session): ignore malformed model costs (#43248)

This commit is contained in:
Shoubhit Dash
2026-08-18 19:49:08 +05:30
committed by GitHub
parent 4e81a0b73f
commit 9b0dd36cda
2 changed files with 23 additions and 9 deletions
@@ -1782,6 +1782,22 @@ describe("SessionNs.getUsage", () => {
expect(Number.isNaN(result.cost)).toBe(false)
})
test("ignores malformed cost fields", () => {
const model = createModel({
context: 100_000,
output: 32_000,
cost: { input: 3, output: 15, cache: { read: 0.3, write: 3.75 } },
})
Object.assign(model.cost, { input: {} })
const result = SessionNs.getUsage({
model,
usage: usage({ inputTokens: 1_000_000, outputTokens: 100_000, totalTokens: 1_100_000 }),
})
expect(result.cost).toBe(1.5)
})
test("calculates cost correctly", () => {
const model = createModel({
context: 100_000,