Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions lib/server/cost-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ const kGlobalModelPricing = {
"gemini-3.1-pro-preview": { input: 2.0, output: 12.0 },
"gemini-3-flash-preview": { input: 0.5, output: 3.0 },
"gemini-2.0-flash": { input: 0.1, output: 0.4 },
"gpt-5.5": { input: 5.0, output: 30.0, cacheRead: 0.5, cacheWrite: 5.0 },
"kimi-k2.6:cloud": { input: 0.8, output: 3.0, cacheRead: 0.1, cacheWrite: 0.8 },
"deepseek-v4-flash:cloud": { input: 0.14, output: 0.28, cacheRead: 0.0028, cacheWrite: 0.14 },
"glm-5.1:cloud": { input: 1.4, output: 4.4, cacheRead: 0.26, cacheWrite: 1.4 },
"grok-4.3": { input: 1.25, output: 2.5, cacheRead: 0.2, cacheWrite: 1.25 },
"qwen3-coder-next": { input: 0.11, output: 0.8, cacheRead: 0.0, cacheWrite: 0.11 },
"gpt-5.4-mini": { input: 0.75, output: 4.5, cacheRead: 0.075, cacheWrite: 0.75 },
"minimax-m3:cloud": { input: 0.6, output: 2.4, cacheRead: 0.06, cacheWrite: 0.6 },
};

const toInt = (value, fallbackValue = 0) => {
Expand Down Expand Up @@ -256,9 +264,13 @@ const resolvePricingFromFallbackMap = (model = "") => {
if (!normalized) return null;
const exact = kGlobalModelPricing[normalized];
if (exact) return exact;
const matchKey = Object.keys(kGlobalModelPricing).find((key) =>
normalized.includes(key),
);
const modelId = normalized.split("/").filter(Boolean).pop();
if (modelId && kGlobalModelPricing[modelId]) {
return kGlobalModelPricing[modelId];
}
const matchKey = Object.keys(kGlobalModelPricing)
.sort((a, b) => b.length - a.length)
.find((key) => normalized.includes(key));
return matchKey ? kGlobalModelPricing[matchKey] : null;
};

Expand Down
27 changes: 27 additions & 0 deletions tests/server/cost-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,31 @@ describe("server/cost-utils", () => {
expect(breakdown.pricingFound).toBe(true);
expect(breakdown.totalCost).toBeCloseTo(5, 8);
});

it("prices provider-qualified GPT-5.5 correctly without gpt-5 shadowing", () => {
const breakdown = deriveCostBreakdown({
provider: "openai",
model: "openai/gpt-5.5",
inputTokens: 1_000_000,
outputTokens: 1_000_000,
});

expect(breakdown.pricingFound).toBe(true);
// GPT-5.5 is input: 5.0, output: 30.0 (total $35.0 per million)
// GPT-5 would be input: 1.25, output: 10.0 (total $11.25 per million)
expect(breakdown.totalCost).toBeCloseTo(35.0, 8);
});

it("prices provider-qualified GPT-5.4-mini correctly without gpt-5 shadowing", () => {
const breakdown = deriveCostBreakdown({
provider: "openai",
model: "openai/gpt-5.4-mini",
inputTokens: 1_000_000,
outputTokens: 1_000_000,
});

expect(breakdown.pricingFound).toBe(true);
// GPT-5.4-mini is input: 0.75, output: 4.5 (total $5.25 per million)
expect(breakdown.totalCost).toBeCloseTo(5.25, 8);
});
});
Loading