mirror of
https://github.com/openai/codex.git
synced 2026-02-01 22:47:52 +00:00
test cache discount
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { describe, expect, test } from "vitest";
|
||||
|
||||
import { estimateCostUSD } from "../src/utils/estimate-cost.js";
|
||||
import {
|
||||
estimateCostUSD,
|
||||
estimateCostFromUsage,
|
||||
} from "../src/utils/estimate-cost.js";
|
||||
import { SessionCostTracker } from "../src/utils/session-cost.js";
|
||||
import type { ResponseItem } from "openai/resources/responses/responses.mjs";
|
||||
|
||||
@@ -36,6 +39,22 @@ describe("estimateCostUSD", () => {
|
||||
);
|
||||
expect(cost2!).toBeGreaterThan(cost!);
|
||||
});
|
||||
|
||||
test("cost calculation honours cached input token discount", () => {
|
||||
const usage = {
|
||||
input_tokens: 1000,
|
||||
input_tokens_details: { cached_tokens: 600 },
|
||||
output_tokens: 500,
|
||||
total_tokens: 1500,
|
||||
} as any; // simple literal structure for test
|
||||
|
||||
const cost = estimateCostFromUsage(usage, "gpt-4.1");
|
||||
|
||||
// Expected: (1000-600)*0.000002 + 600*0.0000005 + 500*0.000008
|
||||
const expected = 400 * 0.000002 + 600 * 0.0000005 + 500 * 0.000008;
|
||||
expect(cost).not.toBeNull();
|
||||
expect(cost!).toBeCloseTo(expected, 8);
|
||||
});
|
||||
});
|
||||
|
||||
describe("SessionCostTracker", () => {
|
||||
|
||||
Reference in New Issue
Block a user